servermanagerimpl.java
来自「JAVA 所有包」· Java 代码 · 共 629 行 · 第 1/2 页
JAVA
629 行
entry = (ServerTableEntry) serverTable.get(key); if (debug) if (entry == null) { System.out.println( "ServerManagerImpl: getEntry: " + "no active server found." ) ; } else { System.out.println( "ServerManagerImpl: getEntry: " + " active server found " + entry + "." ) ; } if ((entry != null) && (!entry.isValid())) { serverTable.remove(key); entry = null; } if (entry == null) { ServerDef serverDef = repository.getServer(serverId); entry = new ServerTableEntry( wrapper, serverId, serverDef, initialPort, dbDirName, false, debug); serverTable.put(key, entry); entry.activate() ; } } return entry ; } private ServerLocation locateServer (ServerTableEntry entry, String endpointType, boolean block) throws NoSuchEndPoint, ServerNotRegistered, ServerHeldDown { ServerLocation location = new ServerLocation() ; // if server location is desired, then wait for the server // to register back, then return location ORBPortInfo [] serverORBAndPortList; if (block) { try { serverORBAndPortList = entry.lookup(endpointType); } catch (Exception ex) { if (debug) System.out.println( "ServerManagerImpl: locateServer: " + "server held down" ) ; throw new ServerHeldDown( entry.getServerId() ); } String host = orb.getLegacyServerSocketManager() .legacyGetEndpoint(LegacyServerSocketEndPointInfo.DEFAULT_ENDPOINT).getHostName(); location.hostname = host ; int listLength; if (serverORBAndPortList != null) { listLength = serverORBAndPortList.length; } else { listLength = 0; } location.ports = new ORBPortInfo[listLength]; for (int i = 0; i < listLength; i++) { location.ports[i] = new ORBPortInfo(serverORBAndPortList[i].orbId, serverORBAndPortList[i].port) ; if (debug) System.out.println( "ServerManagerImpl: locateServer: " + "server located at location " + location.hostname + " ORBid " + serverORBAndPortList[i].orbId + " Port " + serverORBAndPortList[i].port) ; } } return location; } private ServerLocationPerORB locateServerForORB (ServerTableEntry entry, String orbId, boolean block) throws InvalidORBid, ServerNotRegistered, ServerHeldDown { ServerLocationPerORB location = new ServerLocationPerORB() ; // if server location is desired, then wait for the server // to register back, then return location EndPointInfo [] endpointInfoList; if (block) { try { endpointInfoList = entry.lookupForORB(orbId); } catch (InvalidORBid ex) { throw ex; } catch (Exception ex) { if (debug) System.out.println( "ServerManagerImpl: locateServerForORB: " + "server held down" ) ; throw new ServerHeldDown( entry.getServerId() ); } String host = orb.getLegacyServerSocketManager() .legacyGetEndpoint(LegacyServerSocketEndPointInfo.DEFAULT_ENDPOINT).getHostName(); location.hostname = host ; int listLength; if (endpointInfoList != null) { listLength = endpointInfoList.length; } else { listLength = 0; } location.ports = new EndPointInfo[listLength]; for (int i = 0; i < listLength; i++) { location.ports[i] = new EndPointInfo(endpointInfoList[i].endpointType, endpointInfoList[i].port) ; if (debug) System.out.println( "ServerManagerImpl: locateServer: " + "server located at location " + location.hostname + " endpointType " + endpointInfoList[i].endpointType + " Port " + endpointInfoList[i].port) ; } } return location; } public String[] getORBNames(int serverId) throws ServerNotRegistered { try { ServerTableEntry entry = getEntry( serverId ) ; return (entry.getORBList()); } catch (Exception ex) { throw new ServerNotRegistered(serverId); } } private ServerTableEntry getRunningEntry( int serverId ) throws ServerNotRegistered { ServerTableEntry entry = getEntry( serverId ) ; try { // this is to see if the server has any listeners ORBPortInfo [] serverORBAndPortList = entry.lookup(IIOP_CLEAR_TEXT.value) ; } catch (Exception exc) { return null ; } return entry; } public void install( int serverId ) throws ServerNotRegistered, ServerHeldDown, ServerAlreadyInstalled { ServerTableEntry entry = getRunningEntry( serverId ) ; if (entry != null) { repository.install( serverId ) ; entry.install() ; } } public void uninstall( int serverId ) throws ServerNotRegistered, ServerHeldDown, ServerAlreadyUninstalled { ServerTableEntry entry = (ServerTableEntry) serverTable.get( new Integer(serverId) ); if (entry != null) { entry = (ServerTableEntry) serverTable.remove(new Integer(serverId)); if (entry == null) { if (debug) System.out.println( "ServerManagerImpl: shutdown for server Id " + serverId + " throws ServerNotActive." ) ; throw new ServerHeldDown( serverId ); } entry.uninstall(); } } public ServerLocation locateServer (int serverId, String endpointType) throws NoSuchEndPoint, ServerNotRegistered, ServerHeldDown { ServerTableEntry entry = getEntry( serverId ) ; if (debug) System.out.println( "ServerManagerImpl: locateServer called with " + " serverId=" + serverId + " endpointType=" + endpointType + " block=true" ) ; // passing in entry to eliminate multiple lookups for // the same entry in some cases return locateServer(entry, endpointType, true); } /** This method is used to obtain the registered ports for an ORB. * This is useful for custom Bad server ID handlers in ORBD. */ public ServerLocationPerORB locateServerForORB (int serverId, String orbId) throws InvalidORBid, ServerNotRegistered, ServerHeldDown { ServerTableEntry entry = getEntry( serverId ) ; // passing in entry to eliminate multiple lookups for // the same entry in some cases if (debug) System.out.println( "ServerManagerImpl: locateServerForORB called with " + " serverId=" + serverId + " orbId=" + orbId + " block=true" ) ; return locateServerForORB(entry, orbId, true); } public void handle(ObjectKey okey) { IOR newIOR = null; ServerLocationPerORB location; // we need to get the serverid and the orbid from the object key ObjectKeyTemplate oktemp = okey.getTemplate(); int serverId = oktemp.getServerId() ; String orbId = oktemp.getORBId() ; try { // get the ORBName corresponding to the orbMapid, that was // first registered by the server ServerTableEntry entry = getEntry( serverId ) ; location = locateServerForORB(entry, orbId, true); if (debug) System.out.println( "ServerManagerImpl: handle called for server id" + serverId + " orbid " + orbId) ; // we received a list of ports corresponding to an ORB in a // particular server, now retrieve the one corresponding // to IIOP_CLEAR_TEXT, and for other created the tagged // components to be added to the IOR int clearPort = 0; EndPointInfo[] listenerPorts = location.ports; for (int i = 0; i < listenerPorts.length; i++) { if ((listenerPorts[i].endpointType).equals(IIOP_CLEAR_TEXT.value)) { clearPort = listenerPorts[i].port; break; } } // create a new IOR with the correct port and correct tagged // components IIOPAddress addr = IIOPFactories.makeIIOPAddress( orb, location.hostname, clearPort ) ; IIOPProfileTemplate iptemp = IIOPFactories.makeIIOPProfileTemplate( orb, GIOPVersion.V1_2, addr ) ; if (GIOPVersion.V1_2.supportsIORIIOPProfileComponents()) { iptemp.add(IIOPFactories.makeCodeSetsComponent(orb)); iptemp.add(IIOPFactories.makeMaxStreamFormatVersionComponent()); } IORTemplate iortemp = IORFactories.makeIORTemplate(oktemp) ; iortemp.add( iptemp ) ; newIOR = iortemp.makeIOR(orb, "IDL:org/omg/CORBA/Object:1.0", okey.getId() ); } catch (Exception e) { throw wrapper.errorInBadServerIdHandler( e ) ; } if (debug) System.out.println( "ServerManagerImpl: handle " + "throws ForwardException" ) ; try { // This delay is required in case of Server is activated or // re-activated the first time. Server needs some time before // handling all the requests. // (Talk to Ken to see whether there is a better way of doing this). Thread.sleep( serverStartupDelay ); } catch ( Exception e ) { System.out.println( "Exception = " + e ); e.printStackTrace(); } throw new ForwardException(orb, newIOR); } public int getEndpoint(String endpointType) throws NoSuchEndPoint { return orb.getLegacyServerSocketManager() .legacyGetTransientServerPort(endpointType); } public int getServerPortForType(ServerLocationPerORB location, String endPointType) throws NoSuchEndPoint { EndPointInfo[] listenerPorts = location.ports; for (int i = 0; i < listenerPorts.length; i++) { if ((listenerPorts[i].endpointType).equals(endPointType)) { return listenerPorts[i].port; } } throw new NoSuchEndPoint(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?