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;
}
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;
}
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);
}
}
}
Aggregations