Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 19 package gcc.server; 20 21 import gcc.rmi.iiop.ListenerInfo; 22 import gcc.rmi.iiop.RemoteInterface; 23 import gcc.rmi.iiop.server.MessageHandler; 24 import gcc.adapter.AdapterManager; 25 import gcc.adapter.Adapter; 26 import gcc.adapter.AdapterManager; 27 import gcc.naming.NameService; 28 29 import java.net.Socket; 30 import java.net.ServerSocket; 31 import java.net.InetSocketAddress; 32 33 public class IIOPDaemon implements Runnable 34 { 35 protected String _host = "localhost"; 36 protected int _port = 9000; 37 protected String _name = "IIOP"; 38 protected ServerSocket _ss = null; 39 protected boolean _ready = false; 40 41 public void setHost( String host ) 42 { 43 _host = host; 44 } 45 46 public String getHost() 47 { 48 return _host; 49 } 50 51 public void setPort( int port ) 52 { 53 _port = port; 54 } 55 56 public int getPort() 57 { 58 return _port; 59 } 60 61 public void setName( String name ) 62 { 63 _name = name; 64 } 65 66 public String getName() 67 { 68 return _name; 69 } 70 71 public void setReady() 72 { 73 _ready = true; 74 } 75 76 public boolean isReady() 77 { 78 return _ready; 79 } 80 81 public ServerSocket getServerSocket() 82 { 83 if (_ss == null) 84 { 85 synchronized( this ) 86 { 87 try 88 { 89 InetSocketAddress isa = new InetSocketAddress( _host, _port ); 90 _ss = new ServerSocket(); 91 _ss.bind( isa ); 92 setReady(); 93 } 94 catch( Exception ex ) 95 { 96 ex.printStackTrace(); 97 } 98 } 99 } 100 101 return _ss; 102 } 103 104 public void run() 105 { 106 ListenerInfo li = new ListenerInfo(); 107 li.protocol = 1; 108 li.host = getHost(); 109 li.port = getPort(); 110 111 ServerSocket ss = getServerSocket(); 112 Socket s = null; 113 System.out.println( "[" + getName() + "-" + getHost() + ":" + getPort() + "] Accepting Connections..." ); 114 while( isReady() ) 115 { 116 try 117 { 118 s = ss.accept(); 119 } 120 catch( Exception e ) 121 { 122 e.printStackTrace(); 123 } 124 125 MessageHandler mh; 126 mh = MessageHandler.getInstance( li, s ); 127 mh.start(); 128 } 129 } 130 131 public static void main( String args[] ) 132 { 133 IIOPDaemon id = new IIOPDaemon(); 134 id.setHost( "localhost"); 135 id.setPort( 9000 ); 136 137 Thread t = new Thread( id ); 138 t.setName( id.getName() + " Daemon" ); 139 t.start(); 140 141 NameService ns = NameService.getInstance(); 142 AdapterManager am = AdapterManager.getInstance(); 143 144 Adapter a = new Adapter(); 148 a.setBindName( "NameService" ); 149 a.setRemoteClassName( "gcc.rmi.iiop.server.ServerNamingContext" ); 150 a.setRemoteInterfaceName( "gcc.rmi.iiop.NameServiceOperations" ); 151 a.setShared( true ); 152 a.addId( "IDL:gcc/rmi/iiop/NameService:1.0" ); 153 a.addId( "IDL:omg.org/CosNaming/NamingContext:1.0" ); 154 a.addId( "IDL:omg.org/CosNaming/NamingContextExt:1.0" ); 155 a.addId( "NameService" ); a.setClassLoader( id.getClass().getClassLoader() ); 157 160 am.registerAdapter( a ); 161 ns.bindAdapter( a ); 162 163 a = new Adapter(); 167 a.setBindName( "mark.comps.Add" ); 168 a.setRemoteClassName( "mark.comps.AddImpl" ); 169 a.setRemoteInterfaceName( "mark.comps.Add" ); 170 a.addId( "RMI:mark.comps.Add:0000000000000000" ); 171 a.setClassLoader( id.getClass().getClassLoader() ); 172 173 am.registerAdapter( a ); 174 ns.bindAdapter( a ); 175 176 a = new Adapter(); 180 a.setBindName( "mark.comps.Add2" ); 181 a.setRemoteClassName( "mark.comps.Add2Impl" ); 182 a.setRemoteInterfaceName( "mark.comps.Add2" ); 183 a.addId( "RMI:mark.comps.Add2:0000000000000000" ); 184 a.setClassLoader( id.getClass().getClassLoader() ); 185 186 am.registerAdapter( a ); 187 ns.bindAdapter( a ); 188 } 189 } 190
| Popular Tags
|