Search in sources :

Example 6 with Endpoint

use of sun.rmi.transport.Endpoint in project jdk8u_jdk by JetBrains.

the class TestLibrary method getRegistryPort.

/**
     * Returns the port number the RMI {@link Registry} is running on.
     *
     * @param registry the registry to find the port of.
     * @return the port number the registry is using.
     * @throws RuntimeException if there was a problem getting the port number.
     */
public static int getRegistryPort(Registry registry) {
    int port = -1;
    try {
        RemoteRef remoteRef = ((RegistryImpl) registry).getRef();
        LiveRef liveRef = ((UnicastServerRef) remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }
    return port;
}
Also used : RegistryImpl(sun.rmi.registry.RegistryImpl) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) LiveRef(sun.rmi.transport.LiveRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) RemoteRef(java.rmi.server.RemoteRef) UnicastServerRef(sun.rmi.server.UnicastServerRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) NoSuchObjectException(java.rmi.NoSuchObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 7 with Endpoint

use of sun.rmi.transport.Endpoint in project jdk8u_jdk by JetBrains.

the class TCPEndpoint method getLocalEndpoint.

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;
}
Also used : Endpoint(sun.rmi.transport.Endpoint)

Example 8 with Endpoint

use of sun.rmi.transport.Endpoint in project jdk8u_jdk by JetBrains.

the class TCPEndpoint method setDefaultPort.

/**
     * 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);
        }
    }
}
Also used : Endpoint(sun.rmi.transport.Endpoint)

Aggregations

Endpoint (sun.rmi.transport.Endpoint)8 IOException (java.io.IOException)4 ConnectIOException (java.rmi.ConnectIOException)2 RemoteException (java.rmi.RemoteException)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 Socket (java.net.Socket)1 NoSuchObjectException (java.rmi.NoSuchObjectException)1 ExportException (java.rmi.server.ExportException)1 RMIClientSocketFactory (java.rmi.server.RMIClientSocketFactory)1 RemoteRef (java.rmi.server.RemoteRef)1 RegistryImpl (sun.rmi.registry.RegistryImpl)1 NewThreadAction (sun.rmi.runtime.NewThreadAction)1 UnicastServerRef (sun.rmi.server.UnicastServerRef)1 Connection (sun.rmi.transport.Connection)1 LiveRef (sun.rmi.transport.LiveRef)1 TCPEndpoint (sun.rmi.transport.tcp.TCPEndpoint)1