@Override protected Registry getRegistry( String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if(enabled) { return super.getRegistry(registryHost, registryPort, clientSocketFactory, serverSocketFactory); } else { throw new RemoteException(ERR_MSG_NOT_ENABLED); } }
/** * Locate or create the RMI registry for this exporter. * @param registryHost the registry host to use (if this is specified, * no implicit creation of a RMI registry will happen) * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { // Host explicitly specified: only lookup possible. if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]"); } Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory); testRegistry(reg); return reg; } else { return getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } }
/** * Locate or create the RMI registry. * @param registryHost the registry host to use (if this is specified, * no implicit creation of a RMI registry will happen) * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws java.rmi.RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { // Host explicitly specified: only lookup possible. if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]"); } Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory); testRegistry(reg); return reg; } else { return getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } }
/** * Return new server socket to listen for connections on this endpoint. */ ServerSocket newServerSocket() throws IOException { if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) { TCPTransport.tcpLog.log(Log.VERBOSE, "creating server socket on " + this); } RMIServerSocketFactory serverFactory = ssf; if (serverFactory == null) { serverFactory = chooseFactory(); } ServerSocket server = serverFactory.createServerSocket(listenPort); // if we listened on an anonymous port, set the default port // (for this socket factory) if (listenPort == 0) setDefaultPort(server.getLocalPort(), csf, ssf); return server; }
/** * Creates a default activation group implementation. * * @param id the group's identifier * @param data ignored */ public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data) throws RemoteException { super(id); groupID = id; /* * Unexport activation group impl and attempt to export it on * an unshared anonymous port. See 4692286. */ unexportObject(this, true); RMIServerSocketFactory ssf = new ServerSocketFactoryImpl(); UnicastRemoteObject.exportObject(this, 0, null, ssf); if (System.getSecurityManager() == null) { try { // Provide a default security manager. System.setSecurityManager(new SecurityManager()); } catch (Exception e) { throw new RemoteException("unable to set security manager", e); } } }
/** * Server UnicastConnectionManager constructor */ private UnicastConnectionManager(int port, RMIServerSocketFactory ssf) throws RemoteException { try { ssock = ssf.createServerSocket(port); serverPort = ssock.getLocalPort(); } catch (IOException ioex) { ssock = null; serverPort = 0; throw new java.rmi.server.ExportException("can not create Server Socket on port " + port,ioex); } // Note that for compatibility the serverName is "localhost", // not UnicastConnectionManager.localhost, which is the name // of the local box. A server listening on localhost:port is // listening on the loopback interface, 127.0.0.1, but // UnicastConnectionManager.localhost is an externally // accessible IP address. serverName = "localhost"; serverFactory = ssf; clientFactory = null; }
@Override protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if(enabled) { return super.getRegistry(registryPort, clientSocketFactory, serverSocketFactory); } else { throw new RemoteException(ERR_MSG_NOT_ENABLED); } }
/** * Locate or create the RMI registry for this exporter. * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { if (this.alwaysCreateRegistry) { logger.info("Creating new RMI registry"); return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); } synchronized (LocateRegistry.class) { try { // Retrieve existing registry. Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); testRegistry(reg); return reg; } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.info("Could not detect RMI registry - creating new one"); // Assume no registry found -> create new one. return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } } } else { return getRegistry(registryPort); } }
@Override public void afterPropertiesSet() throws Exception { // Check socket factories for registry. if (this.clientSocketFactory instanceof RMIServerSocketFactory) { this.serverSocketFactory = (RMIServerSocketFactory) this.clientSocketFactory; } if ((this.clientSocketFactory != null && this.serverSocketFactory == null) || (this.clientSocketFactory == null && this.serverSocketFactory != null)) { throw new IllegalArgumentException( "Both RMIClientSocketFactory and RMIServerSocketFactory or none required"); } // Fetch RMI registry to expose. this.registry = getRegistry(this.host, this.port, this.clientSocketFactory, this.serverSocketFactory); }
/** * Locate or create the RMI registry. * @param registryPort the registry port to use * @param clientSocketFactory the RMI client socket factory for the registry (if any) * @param serverSocketFactory the RMI server socket factory for the registry (if any) * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { if (this.alwaysCreate) { logger.info("Creating new RMI registry"); this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); } synchronized (LocateRegistry.class) { try { // Retrieve existing registry. Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); testRegistry(reg); return reg; } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.info("Could not detect RMI registry - creating new one"); // Assume no registry found -> create new one. this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } } } else { return getRegistry(registryPort); } }
/** * Create a custom socket factory endpoint for a specified host and port. * This should not be used by external classes to create endpoints * for servers in this VM; use getLocalEndpoint instead. */ public TCPEndpoint(String host, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { if (host == null) host = ""; this.host = host; this.port = port; this.csf = csf; this.ssf = ssf; }
public static TCPEndpoint getLocalEndpoint(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { /* * Find mapping for an endpoint key to the list of local unique * endpoints for this client/server socket factory pair (perhaps * null) for the specific port. */ TCPEndpoint ep = null; synchronized (localEndpoints) { TCPEndpoint endpointKey = new TCPEndpoint(null, port, csf, ssf); LinkedList<TCPEndpoint> epList = localEndpoints.get(endpointKey); String localHost = resampleLocalHost(); if (epList == null) { /* * Create new endpoint list. */ ep = new TCPEndpoint(localHost, port, csf, ssf); epList = new LinkedList<TCPEndpoint>(); epList.add(ep); ep.listenPort = port; ep.transport = new TCPTransport(epList); localEndpoints.put(endpointKey, epList); if (TCPTransport.tcpLog.isLoggable(Log.BRIEF)) { TCPTransport.tcpLog.log(Log.BRIEF, "created local endpoint for socket factory " + ssf + " on port " + port); } } else { synchronized (epList) { ep = epList.getLast(); String lastHost = ep.host; int lastPort = ep.port; TCPTransport lastTransport = ep.transport; // assert (localHost == null ^ lastHost != null) if (localHost != null && !localHost.equals(lastHost)) { /* * Hostname has been updated; add updated endpoint * to list. */ if (lastPort != 0) { /* * Remove outdated endpoints only if the * port has already been set on those endpoints. */ epList.clear(); } ep = new TCPEndpoint(localHost, lastPort, csf, ssf); ep.listenPort = port; ep.transport = lastTransport; epList.add(ep); } } } } return ep; }
/** * Construct a new live reference for a server object in the local * address space, to use sockets of the specified type. */ public LiveRef(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { this((new ObjID()), port, csf, ssf); }
/** * Recover activation state from the reliable log and initialize * activation services. */ private static void startActivation(int port, RMIServerSocketFactory ssf, String logName, String[] childArgs) throws Exception { ReliableLog log = new ReliableLog(logName, new ActLogHandler()); Activation state = (Activation) log.recover(); state.init(port, ssf, log, childArgs); }
SystemRegistryImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, ActivationSystem systemStub) throws RemoteException { super(port, csf, ssf); this.systemStub = systemStub; }
/** * Construct a new Activator on a specified port. */ ActivatorImpl(int port, RMIServerSocketFactory ssf) throws RemoteException { /* Server ref must be created and assigned before remote object * 'this' can be exported. */ LiveRef lref = new LiveRef(new ObjID(ObjID.ACTIVATOR_ID), port, null, ssf); UnicastServerRef uref = new UnicastServerRef(lref); ref = uref; uref.exportObject(this, null, false); }
ActivationSystemImpl(int port, RMIServerSocketFactory ssf) throws RemoteException { /* Server ref must be created and assigned before remote object * 'this' can be exported. */ LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf); UnicastServerRef uref = new UnicastServerRef(lref); ref = uref; uref.exportObject(this, null); }
SingleEntryRegistry(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, String name, Remote object) throws RemoteException { super(port, csf, ssf); this.name = name; this.object = object; }
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port) throws IOException { RMIClientSocketFactory csf = (RMIClientSocketFactory) env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE); RMIServerSocketFactory ssf = (RMIServerSocketFactory) env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE); return new RMIJRMPServerImpl(port, csf, ssf, env); }
/** * Construct a Unicast server remote reference to be exported * on the specified port. */ public UnicastServerRef2(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) { super(new LiveRef(port, csf, ssf)); }
/** * Construct a Unicast server remote reference to be exported * on the specified port. */ public UnicastServerRef2(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, ObjectInputFilter filter) { super(new LiveRef(port, csf, ssf), filter); }