/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* TCPEndpoint represents some communication endpoint for an address
* space (VM).
*
* @author Ann Wollrath
*/
/** IP address or host name */
/** port number */
private int port;
/** custom client socket factory (null if not custom factory) */
/** custom server socket factory (null if not custom factory) */
/** if local, the port number to listen on */
/** if local, the transport object associated with this endpoint */
/** the local host name */
/** true if real local host name is known yet */
private static boolean localHostKnown;
// this should be a *private* method since it is privileged
}
// this should be a *private* method since it is privileged
}
/**
* Returns the value of the java.rmi.server.hostname property.
*/
return AccessController.doPrivileged(
new GetPropertyAction("java.rmi.server.hostname"));
}
/**
* Find host name of local machine. Property "java.rmi.server.hostname"
* is used if set, so server administrator can compensate for the possible
* inablility to get fully qualified host name from VM.
*/
static {
localHostKnown = true;
// could try querying CGI program here?
try {
localHostKnown = false;
}
/* if the user wishes to use a fully qualified domain
* name then attempt to find one.
*/
if (getBoolean("java.rmi.server.useLocalHostName")) {
} else {
/* default to using ip addresses, names will
* work across seperate domains.
*/
}
} catch (Exception e) {
localHostKnown = false;
}
}
"localHostKnown = " + localHostKnown +
", localHost = " + localHost);
}
}
/** maps an endpoint key containing custom socket factories to
* their own unique endpoint */
// TBD: should this be a weak hash table?
private static final
new HashMap<>();
/**
* Create an 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.
*/
}
/**
* 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.
*/
{
host = "";
}
/**
* Get an endpoint for the local address space on specified port.
* If port number is 0, it returns shared default endpoint object
* whose host name and port may or may not have been determined.
*/
}
{
/*
* Find mapping for an endpoint key to the list of local unique
* null) for the specific port.
*/
synchronized (localEndpoints) {
/*
* Create new endpoint list.
*/
"created local endpoint for socket factory " + ssf +
" on port " + port);
}
} else {
synchronized (epList) {
// assert (localHost == null ^ lastHost != null)
/*
* 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.
*/
}
}
}
}
}
return ep;
}
/**
* Resamples the local hostname and returns the possibly-updated
* local hostname.
*/
synchronized (localEndpoints) {
// assert(localHostKnown ^ (localHost == null))
if (hostnameProperty != null) {
if (!localHostKnown) {
/*
* If the local hostname is unknown, update ALL
* existing endpoints with the new hostname.
*/
/*
* Only update the localHost field for reference
* in future endpoint creation.
*/
"updated local hostname to: " + localHost);
}
}
}
return localHost;
}
}
/**
* Set the local host name, if currently unknown.
*/
// assert (host != null)
synchronized (localEndpoints) {
/*
* If host is not known, change the host field of ALL
* the local endpoints.
*/
if (!localHostKnown) {
localHostKnown = true;
"local host set to " + host);
}
{
synchronized (epList) {
}
}
}
}
}
}
/**
* 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.
*/
{
synchronized (localEndpoints) {
synchronized (epList) {
}
if (size > 1) {
/*
* Remove all but the last element of the list
* (which contains the most recent hostname).
*/
}
}
/*
* Allow future exports to use the actual bound port
* explicitly (see 6269166).
*/
"default port for server socket factory " + ssf +
" and client socket factory " + csf +
" set to " + port);
}
}
}
/**
* Returns transport for making connections to remote endpoints;
* (here, the default transport at port 0 is used).
*/
return localEndpoint.transport;
}
/**
* Returns the current list of known transports.
* The returned list is an unshared collection of Transports,
* including all transports which may have channels to remote
* endpoints.
*/
// Loop through local endpoints, getting the transport of each one.
Set<TCPTransport> s;
synchronized (localEndpoints) {
// presize s to number of localEndpoints
/*
* Each local endpoint has its transport added to s.
* Note: the transport is the same for all endpoints
* in the list, so it is okay to pick any one of them.
*/
}
}
return s;
}
/**
* Release idle outbound connections to reduce demand on I/O resources.
* All transports are asked to release excess connections.
*/
public static void shedConnectionCaches() {
}
}
/**
* Export the object to accept incoming calls.
*/
}
/**
* Returns a channel for this (remote) endpoint.
*/
return getOutboundTransport().getChannel(this);
}
/**
* Returns address for endpoint
*/
return host;
}
/**
* Returns the port for this endpoint. If this endpoint was
* created as a server endpoint (using getLocalEndpoint) for a
* listening, this method returns (instead of zero) the actual
* bound port suitable for passing to clients.
**/
public int getPort() {
return port;
}
/**
* Returns the port that this endpoint's inbound transport listens
* on, if this endpoint was created as a server endpoint (using
* getLocalEndpoint). If this endpoint was created for the
* the transport has started listening.
**/
public int getListenPort() {
return listenPort;
}
/**
* Returns the transport for incoming connections to this
* endpoint, if this endpoint was created as a server endpoint
* (using getLocalEndpoint).
**/
return transport;
}
/**
* Get the client socket factory associated with this endpoint.
*/
return csf;
}
/**
* Get the server socket factory associated with this endpoint.
*/
return ssf;
}
/**
* Return string representation for endpoint.
*/
"]";
}
public int hashCode() {
return port;
}
return false;
return false;
/*
* Fix for 4254510: perform socket factory *class* equality check
* before socket factory equality check to avoid passing
* a potentially naughty socket factory to this endpoint's
* {client,server} socket factory equals method.
*/
return false;
return false;
return true;
} else {
return false;
}
}
/* codes for the self-describing formats of wire representation */
/**
* Write endpoint to output stream.
*/
} else {
}
}
/**
* Get the endpoint from the input stream.
* @param in the input stream
* @exception IOException If id could not be read (due to stream failure)
*/
throws IOException, ClassNotFoundException
{
int port;
switch (format) {
case FORMAT_HOST_PORT:
break;
case FORMAT_HOST_PORT_FACTORY:
break;
default:
throw new IOException("invalid endpoint format");
}
}
/**
* Write endpoint to output stream in older format used by
* UnicastRef for JDK1.1 compatibility.
*/
throw new InternalError("TCPEndpoint.writeHostPortFormat: " +
"called for endpoint with non-null socket factory");
}
}
/**
* Create a new endpoint from input stream data.
* @param in the input stream
*/
throws IOException
{
}
}
return sf;
}
/**
* Open and return new client socket connection to endpoint.
*/
"opening socket to " + this);
}
try {
if (clientFactory == null) {
}
"Unknown host: " + host, e);
"Connection refused to host: " + host, e);
} catch (IOException e) {
// We might have simply run out of file descriptors
try {
// REMIND: should we retry createSocket?
// don't quit if out of memory
// or shed fails non-catastrophically
}
throw new ConnectIOException("Exception creating connection to: " +
host, e);
}
// set socket to disable Nagle's algorithm (always send immediately)
// TBD: should this be left up to socket factory instead?
try {
socket.setTcpNoDelay(true);
} catch (Exception e) {
// if we fail to set this, ignore and proceed anyway
}
// fix 4187495: explicitly set SO_KEEPALIVE to prevent client hangs
try {
socket.setKeepAlive(true);
} catch (Exception e) {
// ignore and proceed
}
return socket;
}
/**
* Return new server socket to listen for connections on this endpoint.
*/
"creating server socket on " + this);
}
if (serverFactory == null) {
}
// if we listened on an anonymous port, set the default port
// (for this socket factory)
if (listenPort == 0)
return server;
}
/**
* The class FQDN encapsulates a routine that makes a best effort
* attempt to retrieve the fully qualified domain name of the local
* host.
*
* @author Laird Dornin
*/
/**
* strings in which we can store discovered fqdn
*/
this.hostAddress = hostAddress;
}
/**
* Do our best to obtain a fully qualified hostname for the local
* host. Perform the following steps to get a localhostname:
*
* 1. InetAddress.getLocalHost().getHostName() - if contains
* '.' use as FQDN
* 2. if no '.' query name service for FQDN in a thread
* Note: We query the name service for an FQDN by creating
* an InetAddress via a stringified copy of the local ip
* address; this creates an InetAddress with a null hostname.
* Asking for the hostname of this InetAddress causes a name
* service lookup.
*
* 3. if name service takes too long to return, use ip address
* 4. if name service returns but response contains no '.'
* default to ipaddress.
*/
{
int nameServiceTimeOut =
10000);
try {
synchronized(f) {
f.getFQDN();
/* wait to obtain an FQDN */
}
} catch (InterruptedException e) {
/* propagate the exception to the caller */
}
}
}
return hostName;
}
/**
* Method that that will start a thread to wait to retrieve a
* fully qualified domain name from a name service. The spawned
* thread may never return but we have marked it as a daemon so the vm
* will terminate appropriately.
*/
private void getFQDN() {
/* FQDN finder will run in RMI threadgroup. */
t.start();
}
return reverseLookup;
}
/**
* thread to query a name service for the fqdn of this host.
*/
public void run() {
try {
} finally {
synchronized(this) {
this.notify();
}
}
}
}
}