public class ObjectSpace extends 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.
|
static class |
ObjectSpace.RemoteObjectSerializer
Serializes an object registered with an ObjectSpace so the receiving side gets a
RemoteObject proxy rather than the
bytes for the serialized object. |
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,
Class... ifaces)
Returns a proxy object that implements the specified interfaces.
|
static <T> T |
getRemoteObject(Connection connection,
int objectID,
Class<T> iface)
Identical to
getRemoteObject(Connection, int, Class...) except returns the object cast to the specified interface
type. |
protected void |
invoke(Connection connection,
Object target,
ObjectSpace.InvokeMethod invokeMethod)
Invokes the method on the object and, if necessary, sends the result back to the connection that made the invocation
request.
|
void |
register(int objectID,
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(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(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(Executor executor)
executor
- May be null.public void register(int objectID, 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.
objectID
- Must not be Integer.MAX_VALUE.getRemoteObject(Connection, int, Class...)
public void remove(int objectID)
public void remove(Object object)
public void close()
public void addConnection(Connection connection)
public void removeConnection(Connection connection)
protected void invoke(Connection connection, Object target, ObjectSpace.InvokeMethod invokeMethod)
EndPoint
for this ObjectSpace and unless an
executor
has been set.connection
- The remote side of this connection requested the invocation.public static <T> T getRemoteObject(Connection connection, int objectID, 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, 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)
Copyright © 2014. All Rights Reserved.