View Javadoc

1   /***
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activeio.oneport;
19  
20  import java.io.IOException;
21  import java.net.InetAddress;
22  import java.net.ServerSocket;
23  import java.net.Socket;
24  
25  import org.activeio.SynchChannelServer;
26  import org.activeio.adapter.AsynchToSynchChannelServerAdapter;
27  import org.activeio.adapter.SynchChannelServerToServerSocketAdapter;
28  import org.openorb.orb.net.SocketFactory;
29  
30  /***
31   * 
32   */
33  public class OpenORBOpenPortSocketFactory implements SocketFactory {
34  
35      private final OnePortAsynchChannelServer channelServer;
36  
37      public OpenORBOpenPortSocketFactory(OnePortAsynchChannelServer channelServer) {
38          this.channelServer = channelServer;
39      }
40      
41      /***
42       * Outbound sockets are normal.
43       */
44      public Socket createSocket(InetAddress address, int port) throws IOException {
45          return new Socket(address, port);
46      }
47  
48      /***
49       * Server sockets bind against the OnePortAsynchChannelServer.
50       */
51      public ServerSocket createServerSocket(InetAddress address, int port) throws IOException {
52          SynchChannelServer sychServer = AsynchToSynchChannelServerAdapter.adapt(channelServer.bindAsynchChannel(IIOPRecognizer.IIOP_RECOGNIZER));
53  		sychServer.start();
54  		return new SynchChannelServerToServerSocketAdapter(sychServer);
55      }
56      
57  }