public class ObjectSpace
extends java.lang.Object
registered
with an ID.
The remote end of connections that have been added
are allowed to
access
registered objects.
It costs at least 2 bytes more to use remote method invocation than just sending the parameters. If the method has a return
value which is not ignored
, an extra byte is written. If the type of a parameter is
not final (note primitives are final) then an extra byte is written for that parameter.
Modifier and Type | Class and Description |
---|---|
static class |
ObjectSpace.InvokeMethod
Internal message to invoke methods remotely.
|
static class |
ObjectSpace.InvokeMethodResult
Internal message to return the result of a remotely invoked method.
|
Constructor and Description |
---|
ObjectSpace()
Creates an ObjectSpace with no connections.
|
ObjectSpace(Connection connection)
Creates an ObjectSpace with the specified connection.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnection(Connection connection)
Allows the remote end of the specified connection to access objects registered in this ObjectSpace.
|
void |
close()
Causes this ObjectSpace to stop listening to the connections for method invocation messages.
|
static RemoteObject |
getRemoteObject(Connection connection,
int objectID,
java.lang.Class... ifaces)
Returns a proxy object that implements the specified interfaces.
|
static <T> T |
getRemoteObject(Connection connection,
int objectID,
java.lang.Class<T> iface)
Identical to
getRemoteObject(Connection, int, Class...) except returns the object cast to the specified interface
type. |
void |
register(int objectID,
java.lang.Object object)
Registers an object to allow the remote end of the ObjectSpace's connections to access it using the specified ID.
|
static void |
registerClasses(com.esotericsoftware.kryo.Kryo kryo)
Registers the classes needed to use ObjectSpaces.
|
void |
remove(int objectID)
Removes an object.
|
void |
remove(java.lang.Object object)
Removes an object.
|
void |
removeConnection(Connection connection)
Removes the specified connection, it will no longer be able to access objects registered in this ObjectSpace.
|
void |
setExecutor(java.util.concurrent.Executor executor)
Sets the executor used to invoke methods when an invocation is received from a remote endpoint.
|
public ObjectSpace()
added
to allow the remote
end of the connections to access objects in this ObjectSpace.public ObjectSpace(Connection connection)
added
.public void setExecutor(java.util.concurrent.Executor executor)
executor
- May be null.public void register(int objectID, java.lang.Object object)
If a connection is added to multiple ObjectSpaces, the same object ID should not be registered in more than one of those ObjectSpaces.
public void remove(int objectID)
public void remove(java.lang.Object object)
public void close()
public void addConnection(Connection connection)
public void removeConnection(Connection connection)
public static <T> T getRemoteObject(Connection connection, int objectID, java.lang.Class<T> iface)
getRemoteObject(Connection, int, Class...)
except returns the object cast to the specified interface
type. The returned object still implements RemoteObject
.public static RemoteObject getRemoteObject(Connection connection, int objectID, java.lang.Class... ifaces)
added
the connection to the ObjectSpace, the remote method invocations
will be ignored.
Methods that return a value will throw TimeoutException
if the response is not received with the
response timeout
.
If non-blocking
is false (the default), then methods that return a value must
not be called from the update thread for the connection. An exception will be thrown if this occurs. Methods with a void
return value can be called on the update thread.
If a proxy returned from this method is part of an object graph sent over the network, the object graph on the receiving side will have the proxy object replaced with the registered object.
RemoteObject
public static void registerClasses(com.esotericsoftware.kryo.Kryo kryo)
Kryo.register(Class, Serializer)