// Both objects must be registered with the ObjectSpace.
final ObjectSpace serverObjectSpace = new ObjectSpace();
serverObjectSpace.register(42, serverTestObject);
serverObjectSpace.register(777, serverTestObject.getOtherObject());
server.addListener(new Listener() {
public void connected (final Connection connection) {
// Allow the connection to access objects in the ObjectSpace.
serverObjectSpace.addConnection(connection);
}
public void received (Connection connection, Object object) {
// The test is complete when the client sends the OtherObject instance.
if (object == serverTestObject.getOtherObject()) stopEndPoints();
}
});
// ----
Client client = new Client();
register(client.getKryo());
startEndPoint(client);
// The ThreadedListener means the network thread won't be blocked when waiting for RMI responses.
client.addListener(new ThreadedListener(new Listener() {
public void connected (final Connection connection) {
TestObject test = ObjectSpace.getRemoteObject(connection, 42, TestObject.class);
// Normal remote method call.
assertEquals(43.21f, test.other());
// Make a remote method call that returns another remote proxy object.