This class is the main enclosing coordinator for RMI connections.
An instance of this class can be created using the RMIOptions class.
The connection class holds information required for the RMI runtime to operate, and is the main representation of the local endpoint of a RMI connection.
Objects in an RMI connection can be used via the RMIVariables class which provide the functionality for
creating remote objects and invoking methods. New or existing instances of variable contexts can be retrieved via the
newVariables() or getVariables(
Context variables can be added to an RMI connection, which are basically named global variables present in a
connection. Clients of a connection can use these names to retrieve objects from the other endpoin. This is often
useful when an RMI server provides a specific functionality via an interface and clients want to get the remote
object to call the given functions on. See putContextVariable(
The RMI connections need to be closed after being used. The closing may be synchronous or asynchronous based on the caller. If the close() method is being called through and RMI invocation, then the connection will be closed asynchronously.
public interface | Event listener that is called when the RMIConnection is closed. |
public interface | I/O error listener interface to get notified about connection errors. |
public static final int | The protocol version of the first RMI library release. |
public static final int | Version 2. |
public static final short | PROTOCOL_VERSION_LATEST = (short)2 The latest protocol version. |
public void | addCloseListener( Adds a connection close listener to this connection. |
public void | addErrorListener( Adds an I/O error listener to this connection. |
public void | close() Marks the RMI connection as closed. |
public void | Closes the RMI connection and waits for the pending requests to be finished. |
public ClassLoaderResolver | Gets the ClassLoaderResolver instance used by this RMI connection. |
public Object | getLocalContextVariable( Gets a previously set named variable on this side of the RMI connection. |
public RMIStatistics | Gets the RMI statistics that were collected. |
public RMIVariables | getVariables( Gets or creates a variables context for the given name. |
public boolean | Checks if this connection is about to be closed, and should no longer be used. |
public boolean | Check if the connection is still in a valid state. |
public static boolean | isRemoteObject( Checks if the argument is a remote proxy object. |
public static boolean | isSameLocationRemoteObjects( Checks if the argument objects are both remote proxies and are used with the same RMI variables context. |
public boolean | Gets if RMI statistics are being collected. |
public RMIVariables | Creates a new unnamed variables context in this connection. |
public void | putContextVariable( Sets a named variable for this RMI connection. |
public void | removeCloseListener( Removes a previously added close listener. |
public void | removeErrorListener( Removes a previously added error listener. |
Modifies the object protocol to include the byte count of the transferred data in case of serializing wrapped objects and serializable objects.
The listener is called when the connection is being closed. It may be called asynchronously, and even before this method finishes.
null
.The listener is called when I/O errors are detected in the connection.
If an I/O error was already detected, then the listener will be called before this method returns.
Listeners are kept until they are explicitly remoeved. They may be called concurrently, and multiple times.
null
.Closing an RMI connection does not happen immediately, calling this method only signals the connection to be closed when the last pending request finishes.
To wait for the pending requests to finish, call closeWait().
If any request is made to any of the proxy objects in this connection after closing, the request may succeed, or an appropriate RMIRuntimeException may be thrown.
Callers should ensure that no requests are running in the system before calling this method. This often requires external synchronization by the user.
This method works the same way as close(), but waits for the requests to properly finish before returning.
If it was set by RMIOptions then the specified instance else a defaulted resolver is returned.
Only local variables are retrieved and no RMI request is made to the other endpoint.
null
if it is not set.
This method returns non-null
if and only if RMIOptions.collectStatistics(true
.
If the connection is still alive (i.e. not closed) then the returned statistics object may be modified if RMI calls are performed concurrently.
null
if none were collected.Named variables are present on both endpoint with a specific name. They can be used to access predetermined variables to encapsulate different parts of code.
The returned variables instance need to be closed for each call of getVariables(
If a named variables has been retrieved, and later closed, a new instance for the name can be retrieved again. I.e. the names are reuseable.
null
or empty, or the given variables context name is too long, and
cannot be encoded via UTF-8 into less than 65536 bytes.A connection is aborting, if there were any I/O errors, or it was explicitly closed, but the closing cannot be done synchronously.
true
if the connection is aborting.This method will return false if any I/O errors are detected, or the connection has been closed.
This method checks if the object is created by the RMI library, and calls to it will be dispatched over an RMI connection. As this is a static method, it doesn't check if it belongs to any specific RMI connection, but only checks if the objects is remote.
Calling this method has the same performance cost as an instanceof
expression.
true
if the argument is a remote proxy.true
if both objects are remote, and bound to the same RMI variables context.The returned variables instance need to be closed by the caller when no longer used.
Named variables can be used to retrieve pre-defined objects remotely. If a connection is supposed to be utilized for a specific task then setting a variable on the server side can make it easy for the client to establish the communication.
The variables are retrivable on the remote endpoint using RMIVariables.getRemoteContextVariable(
Any previously set variable with the same name will be overwritten. Setting null
will remove the
variable.
It is recommended that context variables have an interface which can be used to retrieve on the other side.
null
to remove the current object.null
.null
.