Java Code Examples for java.rmi.server.RMIClientSocketFactory

The following are top voted examples for showing how to use java.rmi.server.RMIClientSocketFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: AlfrescoRmiRegistryFactoryBean.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 2
Project: lams   File: RmiServiceExporter.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 3
Project: lams   File: RmiRegistryFactoryBean.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 4
Project: spring4-understanding   File: RmiServiceExporter.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 5
Project: spring4-understanding   File: RmiRegistryFactoryBean.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Project: my-spring-cache-redis   File: RmiServiceExporter.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 7
Project: my-spring-cache-redis   File: RmiRegistryFactoryBean.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 8
Project: spring   File: RmiServiceExporter.java   View source code 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 9
Project: alfresco-repository   File: AlfrescoRmiRegistryFactoryBean.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 10
Project: lams   File: RmiServiceExporter.java   View source code 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 11
Project: lams   File: RmiRegistryFactoryBean.java   View source code 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 12
Project: OpenJSharp   File: TCPEndpoint.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Project: OpenJSharp   File: TCPEndpoint.java   View source code 5 votes vote down vote up
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;
}
 
Example 14
Project: OpenJSharp   File: LiveRef.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 15
Project: OpenJSharp   File: LiveRef.java   View source code 5 votes vote down vote up
public boolean remoteEquals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
        LiveRef ref = (LiveRef) obj;

        TCPEndpoint thisEp = ((TCPEndpoint) ep);
        TCPEndpoint refEp = ((TCPEndpoint) ref.ep);

        RMIClientSocketFactory thisClientFactory =
            thisEp.getClientSocketFactory();
        RMIClientSocketFactory refClientFactory =
            refEp.getClientSocketFactory();

        /**
         * Fix for 4254103: LiveRef.remoteEquals should not fail
         * if one of the objects in the comparison has a null
         * server socket.  Comparison should only consider the
         * following criteria:
         *
         * hosts, ports, client socket factories and object IDs.
         */
        if (thisEp.getPort() != refEp.getPort() ||
            !thisEp.getHost().equals(refEp.getHost()))
        {
            return false;
        }
        if ((thisClientFactory == null) ^ (refClientFactory == null)) {
            return false;
        }
        if ((thisClientFactory != null) &&
            !((thisClientFactory.getClass() ==
               refClientFactory.getClass()) &&
              (thisClientFactory.equals(refClientFactory))))
        {
            return false;
        }
        return (id.equals(ref.id));
    } else {
        return false;
    }
}
 
Example 16
Project: OpenJSharp   File: Activation.java   View source code 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example 17
Project: OpenJSharp   File: SingleEntryRegistry.java   View source code 5 votes vote down vote up
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf);
    this.name = name;
    this.object = object;
}
 
Example 18
Project: OpenJSharp   File: RMIConnectorServer.java   View source code 5 votes vote down vote up
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);
}
 
Example 19
Project: jdk8u-jdk   File: TCPEndpoint.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 20
Project: jdk8u-jdk   File: TCPEndpoint.java   View source code 5 votes vote down vote up
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;
}
 
Example 21
Project: jdk8u-jdk   File: LiveRef.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 22
Project: jdk8u-jdk   File: LiveRef.java   View source code 5 votes vote down vote up
public boolean remoteEquals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
        LiveRef ref = (LiveRef) obj;

        TCPEndpoint thisEp = ((TCPEndpoint) ep);
        TCPEndpoint refEp = ((TCPEndpoint) ref.ep);

        RMIClientSocketFactory thisClientFactory =
            thisEp.getClientSocketFactory();
        RMIClientSocketFactory refClientFactory =
            refEp.getClientSocketFactory();

        /**
         * Fix for 4254103: LiveRef.remoteEquals should not fail
         * if one of the objects in the comparison has a null
         * server socket.  Comparison should only consider the
         * following criteria:
         *
         * hosts, ports, client socket factories and object IDs.
         */
        if (thisEp.getPort() != refEp.getPort() ||
            !thisEp.getHost().equals(refEp.getHost()))
        {
            return false;
        }
        if ((thisClientFactory == null) ^ (refClientFactory == null)) {
            return false;
        }
        if ((thisClientFactory != null) &&
            !((thisClientFactory.getClass() ==
               refClientFactory.getClass()) &&
              (thisClientFactory.equals(refClientFactory))))
        {
            return false;
        }
        return (id.equals(ref.id));
    } else {
        return false;
    }
}
 
Example 23
Project: jdk8u-jdk   File: Activation.java   View source code 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example 24
Project: jdk8u-jdk   File: UnicastServerRef2.java   View source code 5 votes vote down vote up
/**
 * 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));
}
 
Example 25
Project: jdk8u-jdk   File: UnicastServerRef2.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 26
Project: jdk8u-jdk   File: SingleEntryRegistry.java   View source code 5 votes vote down vote up
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf);
    this.name = name;
    this.object = object;
}
 
Example 27
Project: jdk8u-jdk   File: RMIConnectorServer.java   View source code 5 votes vote down vote up
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);
}
 
Example 28
Project: jdk8u-jdk   File: RMIJRMPServerImpl.java   View source code 5 votes vote down vote up
/**
 * <p>Creates a new {@link RMIServer} object that will be exported
 * on the given port using the given socket factories.</p>
 *
 * @param port the port on which this object and the {@link
 * RMIConnectionImpl} objects it creates will be exported.  Can be
 * zero, to indicate any available port.
 *
 * @param csf the client socket factory for the created RMI
 * objects.  Can be null.
 *
 * @param ssf the server socket factory for the created RMI
 * objects.  Can be null.
 *
 * @param env the environment map.  Can be null.
 *
 * @exception IOException if the {@link RMIServer} object
 * cannot be created.
 *
 * @exception IllegalArgumentException if <code>port</code> is
 * negative.
 */
public RMIJRMPServerImpl(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf,
                         Map<String,?> env)
        throws IOException {

    super(env);

    if (port < 0)
        throw new IllegalArgumentException("Negative port: " + port);

    this.port = port;
    this.csf = csf;
    this.ssf = ssf;
    this.env = (env == null) ? Collections.<String, Object>emptyMap() : env;

    String[] credentialsTypes
            = (String[]) this.env.get(EnvHelp.CREDENTIAL_TYPES);
    List<String> types = null;
    if (credentialsTypes != null) {
        types = new ArrayList<>();
        for (String type : credentialsTypes) {
            if (type == null) {
                throw new IllegalArgumentException("A credential type is null.");
            }
            ReflectUtil.checkPackageAccess(type);
            types.add(type);
        }
    }
    exportedWrapper = types != null ?
            new ExportedWrapper(this, types) :
            null;
}
 
Example 29
Project: jdk8u-jdk   File: RMIExporterTest.java   View source code 5 votes vote down vote up
public Remote exportObject(Remote obj,
                           int port,
                           RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
    throws RemoteException {
    System.out.println("CustomRMIExporter::exportObject():: " +
                       "Remote = " + obj);
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIJRMPServerImpl"))
        rmiServerExported = true;
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIConnectionImpl"))
        rmiConnectionExported = true;
    return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
 
Example 30
Project: openjdk-jdk10   File: SingleEntryRegistry.java   View source code 5 votes vote down vote up
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf, SingleEntryRegistry::singleRegistryFilter);
    this.name = name;
    this.object = object;
}
 
Example 31
Project: openjdk-jdk10   File: TCPEndpoint.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 32
Project: openjdk-jdk10   File: TCPEndpoint.java   View source code 5 votes vote down vote up
/**
 * Set the port of the (shared) default endpoint object.
 * When first created, it contains port 0 because the transport
 * hasn't tried to listen to get assigned a port, or if listening
 * failed, a port hasn't been assigned from the server.
 */
static void setDefaultPort(int port, RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
{
    TCPEndpoint endpointKey = new TCPEndpoint(null, 0, csf, ssf);

    synchronized (localEndpoints) {
        LinkedList<TCPEndpoint> epList = localEndpoints.get(endpointKey);

        synchronized (epList) {
            int size = epList.size();
            TCPEndpoint lastEp = epList.getLast();

            for (TCPEndpoint ep : epList) {
                ep.port = port;
            }
            if (size > 1) {
                /*
                 * Remove all but the last element of the list
                 * (which contains the most recent hostname).
                 */
                epList.clear();
                epList.add(lastEp);
            }
        }

        /*
         * Allow future exports to use the actual bound port
         * explicitly (see 6269166).
         */
        TCPEndpoint newEndpointKey = new TCPEndpoint(null, port, csf, ssf);
        localEndpoints.put(newEndpointKey, epList);

        if (TCPTransport.tcpLog.isLoggable(Log.BRIEF)) {
            TCPTransport.tcpLog.log(Log.BRIEF,
                "default port for server socket factory " + ssf +
                " and client socket factory " + csf +
                " set to " + port);
        }
    }
}
 
Example 33
Project: openjdk-jdk10   File: LiveRef.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 34
Project: openjdk-jdk10   File: LiveRef.java   View source code 5 votes vote down vote up
public boolean remoteEquals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
        LiveRef ref = (LiveRef) obj;

        TCPEndpoint thisEp = ((TCPEndpoint) ep);
        TCPEndpoint refEp = ((TCPEndpoint) ref.ep);

        RMIClientSocketFactory thisClientFactory =
            thisEp.getClientSocketFactory();
        RMIClientSocketFactory refClientFactory =
            refEp.getClientSocketFactory();

        /**
         * Fix for 4254103: LiveRef.remoteEquals should not fail
         * if one of the objects in the comparison has a null
         * server socket.  Comparison should only consider the
         * following criteria:
         *
         * hosts, ports, client socket factories and object IDs.
         */
        if (thisEp.getPort() != refEp.getPort() ||
            !thisEp.getHost().equals(refEp.getHost()))
        {
            return false;
        }
        if ((thisClientFactory == null) ^ (refClientFactory == null)) {
            return false;
        }
        if ((thisClientFactory != null) &&
            !((thisClientFactory.getClass() ==
               refClientFactory.getClass()) &&
              (thisClientFactory.equals(refClientFactory))))
        {
            return false;
        }
        return (id.equals(ref.id));
    } else {
        return false;
    }
}
 
Example 35
Project: openjdk-jdk10   File: Activation.java   View source code 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    assert systemStub != null;
    synchronized (this) {
        this.systemStub = systemStub;
        notifyAll();
    }
}
 
Example 36
Project: openjdk-jdk10   File: UnicastServerRef2.java   View source code 5 votes vote down vote up
/**
 * 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));
}
 
Example 37
Project: openjdk-jdk10   File: UnicastServerRef2.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 38
Project: openjdk-jdk10   File: RegistryImpl.java   View source code 5 votes vote down vote up
/**
 * Construct a new RegistryImpl on the specified port with the
 * given custom socket factory pair.
 */
public RegistryImpl(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf)
    throws RemoteException
{
    this(port, csf, ssf, RegistryImpl::registryFilter);
}
 
Example 39
Project: openjdk-jdk10   File: RegistryImpl.java   View source code 5 votes vote down vote up
/**
 * ObjectInputFilter to filter Registry input objects.
 * The list of acceptable classes is limited to classes normally
 * stored in a registry.
 *
 * @param filterInfo access to the class, array length, etc.
 * @return  {@link ObjectInputFilter.Status#ALLOWED} if allowed,
 *          {@link ObjectInputFilter.Status#REJECTED} if rejected,
 *          otherwise {@link ObjectInputFilter.Status#UNDECIDED}
 */
private static ObjectInputFilter.Status registryFilter(ObjectInputFilter.FilterInfo filterInfo) {
    if (registryFilter != null) {
        ObjectInputFilter.Status status = registryFilter.checkInput(filterInfo);
        if (status != ObjectInputFilter.Status.UNDECIDED) {
            // The Registry filter can override the built-in white-list
            return status;
        }
    }

    if (filterInfo.depth() > REGISTRY_MAX_DEPTH) {
        return ObjectInputFilter.Status.REJECTED;
    }
    Class<?> clazz = filterInfo.serialClass();
    if (clazz != null) {
        if (clazz.isArray()) {
            // Arrays are REJECTED only if they exceed the limit
            return (filterInfo.arrayLength() >= 0 && filterInfo.arrayLength() > REGISTRY_MAX_ARRAY_SIZE)
                ? ObjectInputFilter.Status.REJECTED
                : ObjectInputFilter.Status.UNDECIDED;
        }
        if (String.class == clazz
                || java.lang.Number.class.isAssignableFrom(clazz)
                || Remote.class.isAssignableFrom(clazz)
                || java.lang.reflect.Proxy.class.isAssignableFrom(clazz)
                || UnicastRef.class.isAssignableFrom(clazz)
                || RMIClientSocketFactory.class.isAssignableFrom(clazz)
                || RMIServerSocketFactory.class.isAssignableFrom(clazz)
                || java.rmi.activation.ActivationID.class.isAssignableFrom(clazz)
                || java.rmi.server.UID.class.isAssignableFrom(clazz)) {
            return ObjectInputFilter.Status.ALLOWED;
        } else {
            return ObjectInputFilter.Status.REJECTED;
        }
    }
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 40
Project: openjdk-jdk10   File: RMIConnectorServer.java   View source code 5 votes vote down vote up
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);
}