From b5192547f71a76287d418f4ab3c6bb5c30171d33 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 22 Jul 2015 10:36:19 +0200 Subject: [PATCH] Client now implements Connection --- .../src/dorkbox/network/Client.java | 108 +++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/Dorkbox-Network/src/dorkbox/network/Client.java b/Dorkbox-Network/src/dorkbox/network/Client.java index 966498db..dbcb6c9c 100644 --- a/Dorkbox-Network/src/dorkbox/network/Client.java +++ b/Dorkbox-Network/src/dorkbox/network/Client.java @@ -25,10 +25,13 @@ import dorkbox.network.connection.registration.local.RegistrationLocalHandlerCli import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientTCP; import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientUDP; import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientUDT; +import dorkbox.network.rmi.RemoteObject; +import dorkbox.network.rmi.TimeoutException; import dorkbox.network.util.udt.UdtEndpointProxy; import dorkbox.util.NamedThreadFactory; import dorkbox.util.OS; import dorkbox.util.exceptions.InitializationException; +import dorkbox.util.exceptions.NetException; import dorkbox.util.exceptions.SecurityException; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; @@ -57,7 +60,7 @@ import java.net.InetSocketAddress; */ @SuppressWarnings("unused") public -class Client extends EndPointClient { +class Client extends EndPointClient implements Connection { private final Configuration options; @@ -307,6 +310,49 @@ class Client extends EndPointClient { } } + + @Override + public + boolean hasRemoteKeyChanged() { + return this.connectionManager.getConnection0().hasRemoteKeyChanged(); + } + + @Override + public + String getRemoteHost() { + return this.connectionManager.getConnection0().getRemoteHost(); + } + + @Override + public + EndPoint getEndPoint() { + return this; + } + + @Override + public + int id() { + return this.connectionManager.getConnection0().id(); + } + + @Override + public + String idAsHex() { + return this.connectionManager.getConnection0().idAsHex(); + } + + @Override + public + boolean hasUDP() { + return this.connectionManager.getConnection0().hasUDP(); + } + + @Override + public + boolean hasUDT() { + return this.connectionManager.getConnection0().hasUDT(); + } + /** * Expose methods to send objects to a destination when the connection has become idle. */ @@ -357,4 +403,64 @@ class Client extends EndPointClient { this.registrationLock.notify(); } } + + /** + * Returns a new proxy object implements the specified interface. Methods invoked on the proxy object will be + * invoked remotely on the object with the specified ID in the ObjectSpace for the current connection. + *

+ * This will request a registration ID from the remote endpoint, and will block until the object + * has been returned. + *

+ * Methods that return a value will throw {@link TimeoutException} if the + * response is not received with the + * {@link RemoteObject#setResponseTimeout(int) response timeout}. + *

+ * If {@link RemoteObject#setNonBlocking(boolean) 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 (non-proxy) object. + * + * @see RemoteObject + */ + public + Iface createRemoteObject(final Class remoteImplementationClass) throws NetException { + return this.connectionManager.getConnection0().createRemoteObject(remoteImplementationClass); + } + + + /** + * Returns a new proxy object implements the specified interface. Methods invoked on the proxy object will be + * invoked remotely on the object with the specified ID in the ObjectSpace for the current connection. + *

+ * This will REUSE a registration ID from the remote endpoint, and will block until the object + * has been returned. + *

+ * Methods that return a value will throw {@link TimeoutException} if the + * response is not received with the + * {@link RemoteObject#setResponseTimeout(int) response timeout}. + *

+ * If {@link RemoteObject#setNonBlocking(boolean) 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 (non-proxy) object. + * + * @see RemoteObject + */ + public + Iface getRemoteObject(final int objectId) throws NetException { + return this.connectionManager.getConnection0().getRemoteObject(objectId); + } + + + }