Code cleanup
This commit is contained in:
parent
4f7acde039
commit
37adecd68a
|
@ -38,10 +38,10 @@ import dorkbox.network.connection.ping.PingTuple;
|
|||
import dorkbox.network.connection.wrapper.ChannelNetworkWrapper;
|
||||
import dorkbox.network.connection.wrapper.ChannelNull;
|
||||
import dorkbox.network.connection.wrapper.ChannelWrapper;
|
||||
import dorkbox.network.rmi.RMI;
|
||||
import dorkbox.network.rmi.RemoteObject;
|
||||
import dorkbox.network.rmi.RemoteObjectCallback;
|
||||
import dorkbox.network.rmi.RmiImplHandler;
|
||||
import dorkbox.network.rmi.Rmi;
|
||||
import dorkbox.network.rmi.RmiBridge;
|
||||
import dorkbox.network.rmi.RmiRegistration;
|
||||
import dorkbox.network.util.CryptoSerializationManager;
|
||||
import dorkbox.util.collections.IntMap;
|
||||
|
@ -108,7 +108,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
//
|
||||
// RMI fields
|
||||
//
|
||||
private final RmiImplHandler rmiImplHandler;
|
||||
private final RmiBridge rmiBridge;
|
||||
private final Map<Integer, RemoteObject> proxyIdCache = new WeakHashMap<Integer, RemoteObject>(8);
|
||||
private final IntMap<RemoteObjectCallback> rmiRegistrationCallbacks = new IntMap<>();
|
||||
private int rmiRegistrationID = 0; // protected by synchronized (rmiRegistrationCallbacks)
|
||||
|
@ -118,10 +118,10 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public
|
||||
ConnectionImpl(final Logger logger, final EndPoint endPoint, final RmiImplHandler rmiImplHandler) {
|
||||
ConnectionImpl(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
||||
this.logger = logger;
|
||||
this.endPoint = endPoint;
|
||||
this.rmiImplHandler = rmiImplHandler;
|
||||
this.rmiBridge = rmiBridge;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1097,7 +1097,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
// we use kryo to create a new instance - so only return it on error or when it's done creating a new instance
|
||||
manager.returnKryo(kryo);
|
||||
|
||||
rmiImplHandler.register(rmiImplHandler.nextObjectId(), remotePrimaryObject);
|
||||
rmiBridge.register(rmiBridge.nextObjectId(), remotePrimaryObject);
|
||||
|
||||
LinkedList<ClassObject> remoteClasses = new LinkedList<ClassObject>();
|
||||
remoteClasses.add(new ClassObject(implementationClass, remotePrimaryObject));
|
||||
|
@ -1106,7 +1106,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
while ((remoteClassObject = remoteClasses.pollFirst()) != null) {
|
||||
// we have to check for any additional fields that will have proxy information
|
||||
for (Field field : remoteClassObject.clazz.getDeclaredFields()) {
|
||||
if (field.getAnnotation(RMI.class) != null) {
|
||||
if (field.getAnnotation(Rmi.class) != null) {
|
||||
boolean prev = field.isAccessible();
|
||||
field.setAccessible(true);
|
||||
final Object o = field.get(remoteClassObject.object);
|
||||
|
@ -1114,7 +1114,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
|
||||
final Class<?> type = field.getType();
|
||||
|
||||
rmiImplHandler.register(rmiImplHandler.nextObjectId(), o);
|
||||
rmiBridge.register(rmiBridge.nextObjectId(), o);
|
||||
remoteClasses.offerLast(new ClassObject(type, o));
|
||||
}
|
||||
}
|
||||
|
@ -1126,7 +1126,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
connection.TCP(new RmiRegistration(rmiID)).flush();
|
||||
}
|
||||
}
|
||||
else if (remoteRegistration.remoteObjectId > RmiImplHandler.INVALID_RMI) {
|
||||
else if (remoteRegistration.remoteObjectId > RmiBridge.INVALID_RMI) {
|
||||
// THIS IS ON THE REMOTE CONNECTION (where the object will really exist)
|
||||
//
|
||||
// GET a LOCAL rmi object, if none get a specific, GLOBAL rmi object (objects that are not bound to a single connection).
|
||||
|
@ -1167,15 +1167,15 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
public
|
||||
<T> int getRegisteredId(final T object) {
|
||||
// always check local before checking global, because less contention on the synchronization
|
||||
RmiImplHandler globalRmiImplHandler = endPoint.globalRmiImplHandler;
|
||||
RmiBridge globalRmiBridge = endPoint.globalRmiBridge;
|
||||
|
||||
if (globalRmiImplHandler == null) {
|
||||
throw new NullPointerException("Unable to call 'getRegisteredId' when the globalRmiImplHandler is null!");
|
||||
if (globalRmiBridge == null) {
|
||||
throw new NullPointerException("Unable to call 'getRegisteredId' when the globalRmiBridge is null!");
|
||||
}
|
||||
|
||||
int object1 = globalRmiImplHandler.getRegisteredId(object);
|
||||
int object1 = globalRmiBridge.getRegisteredId(object);
|
||||
if (object1 == Integer.MAX_VALUE) {
|
||||
return rmiImplHandler.getRegisteredId(object);
|
||||
return rmiBridge.getRegisteredId(object);
|
||||
} else {
|
||||
return object1;
|
||||
}
|
||||
|
@ -1196,7 +1196,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
|
||||
if (remoteObject == null) {
|
||||
// duplicates are fine, as they represent the same object (as specified by the ID) on the remote side.
|
||||
remoteObject = rmiImplHandler.createProxyObject(this, objectID, type);
|
||||
remoteObject = rmiBridge.createProxyObject(this, objectID, type);
|
||||
proxyIdCache.put(objectID, remoteObject);
|
||||
}
|
||||
|
||||
|
@ -1210,16 +1210,16 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
|
|||
@Override
|
||||
public
|
||||
Object getImplementationObject(final int objectID) {
|
||||
if (RmiImplHandler.isGlobal(objectID)) {
|
||||
RmiImplHandler globalRmiImplHandler = endPoint.globalRmiImplHandler;
|
||||
if (RmiBridge.isGlobal(objectID)) {
|
||||
RmiBridge globalRmiBridge = endPoint.globalRmiBridge;
|
||||
|
||||
if (globalRmiImplHandler == null) {
|
||||
if (globalRmiBridge == null) {
|
||||
throw new NullPointerException("Unable to call 'getRegisteredId' when the gloablRmiBridge is null!");
|
||||
}
|
||||
|
||||
return globalRmiImplHandler.getRegisteredObject(objectID);
|
||||
return globalRmiBridge.getRegisteredObject(objectID);
|
||||
} else {
|
||||
return rmiImplHandler.getRegisteredObject(objectID);
|
||||
return rmiBridge.getRegisteredObject(objectID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,12 +42,11 @@ import dorkbox.network.connection.wrapper.ChannelNetworkWrapper;
|
|||
import dorkbox.network.connection.wrapper.ChannelWrapper;
|
||||
import dorkbox.network.pipeline.KryoEncoder;
|
||||
import dorkbox.network.pipeline.KryoEncoderCrypto;
|
||||
import dorkbox.network.rmi.RmiImplHandler;
|
||||
import dorkbox.network.rmi.RmiBridge;
|
||||
import dorkbox.network.store.NullSettingsStore;
|
||||
import dorkbox.network.store.SettingsStore;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.Property;
|
||||
import dorkbox.util.SerializationManager;
|
||||
import dorkbox.util.crypto.CryptoECC;
|
||||
import dorkbox.util.entropy.Entropy;
|
||||
import dorkbox.util.exceptions.InitializationException;
|
||||
|
@ -164,7 +163,7 @@ class EndPoint<C extends Connection> {
|
|||
final ECPublicKeyParameters publicKey;
|
||||
|
||||
final SecureRandom secureRandom;
|
||||
final RmiImplHandler globalRmiImplHandler;
|
||||
final RmiBridge globalRmiBridge;
|
||||
|
||||
private final CountDownLatch blockUntilDone = new CountDownLatch(1);
|
||||
|
||||
|
@ -322,10 +321,10 @@ class EndPoint<C extends Connection> {
|
|||
if (this.rmiEnabled) {
|
||||
// these register the listener for registering a class implementation for RMI (internal use only)
|
||||
this.connectionManager.add(new RegisterRmiSystemListener());
|
||||
this.globalRmiImplHandler = new RmiImplHandler(logger, options.rmiExecutor, true);
|
||||
this.globalRmiBridge = new RmiBridge(logger, options.rmiExecutor, true);
|
||||
}
|
||||
else {
|
||||
this.globalRmiImplHandler = null;
|
||||
this.globalRmiBridge = null;
|
||||
}
|
||||
|
||||
serializationManager.finishInit();
|
||||
|
@ -420,7 +419,7 @@ class EndPoint<C extends Connection> {
|
|||
* Returns the serialization wrapper if there is an object type that needs to be added outside of the basics.
|
||||
*/
|
||||
public
|
||||
SerializationManager getSerialization() {
|
||||
dorkbox.network.util.CryptoSerializationManager getSerialization() {
|
||||
return this.serializationManager;
|
||||
}
|
||||
|
||||
|
@ -434,8 +433,8 @@ class EndPoint<C extends Connection> {
|
|||
* @return a new network connection
|
||||
*/
|
||||
protected
|
||||
ConnectionImpl newConnection(final Logger logger, final EndPoint<C> endPoint, final RmiImplHandler rmiImplHandler) {
|
||||
return new ConnectionImpl(logger, endPoint, rmiImplHandler);
|
||||
ConnectionImpl newConnection(final Logger logger, final EndPoint<C> endPoint, final RmiBridge rmiBridge) {
|
||||
return new ConnectionImpl(logger, endPoint, rmiBridge);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,9 +449,9 @@ class EndPoint<C extends Connection> {
|
|||
Connection connection0(MetaChannel metaChannel) {
|
||||
ConnectionImpl connection;
|
||||
|
||||
RmiImplHandler rmiImplHandler = null;
|
||||
RmiBridge rmiBridge = null;
|
||||
if (metaChannel != null && rmiEnabled) {
|
||||
rmiImplHandler = new RmiImplHandler(logger, rmiExecutor, false);
|
||||
rmiBridge = new RmiBridge(logger, rmiExecutor, false);
|
||||
}
|
||||
|
||||
// setup the extras needed by the network connection.
|
||||
|
@ -461,7 +460,7 @@ class EndPoint<C extends Connection> {
|
|||
if (metaChannel != null) {
|
||||
ChannelWrapper<C> wrapper;
|
||||
|
||||
connection = newConnection(logger, this, rmiImplHandler);
|
||||
connection = newConnection(logger, this, rmiBridge);
|
||||
metaChannel.connection = connection;
|
||||
|
||||
if (metaChannel.localChannel != null) {
|
||||
|
@ -479,10 +478,10 @@ class EndPoint<C extends Connection> {
|
|||
// now initialize the connection channels with whatever extra info they might need.
|
||||
connection.init(wrapper, (ConnectionManager<Connection>) this.connectionManager);
|
||||
|
||||
if (rmiImplHandler != null) {
|
||||
if (rmiBridge != null) {
|
||||
// notify our remote object space that it is able to receive method calls.
|
||||
connection.listeners()
|
||||
.add(rmiImplHandler.getListener());
|
||||
.add(rmiBridge.getListener());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -800,8 +799,8 @@ class EndPoint<C extends Connection> {
|
|||
*/
|
||||
public
|
||||
<T> int createGlobalObject(final T globalObject) {
|
||||
int globalObjectId = globalRmiImplHandler.nextObjectId();
|
||||
globalRmiImplHandler.register(globalObjectId, globalObject);
|
||||
int globalObjectId = globalRmiBridge.nextObjectId();
|
||||
globalRmiBridge.register(globalObjectId, globalObject);
|
||||
return globalObjectId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class RegisterRmiSystemListener implements Listener.OnMessageReceived<Connection
|
|||
@Override
|
||||
public
|
||||
void received(final ConnectionImpl connection, final RmiRegistration registerClass) {
|
||||
// register this into the RmiImplHandler
|
||||
// register this into the RmiBridge
|
||||
connection.registerInternal(connection, registerClass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class RegistrationWrapper<C extends Connection> implements UdpServer {
|
|||
*/
|
||||
public
|
||||
boolean rmiEnabled() {
|
||||
return endPoint.globalRmiImplHandler != null;
|
||||
return endPoint.globalRmiBridge != null;
|
||||
}
|
||||
|
||||
public
|
||||
|
|
|
@ -36,7 +36,7 @@ import dorkbox.network.connection.ConnectionImpl;
|
|||
import dorkbox.network.connection.EndPoint;
|
||||
import dorkbox.network.connection.Listener;
|
||||
import dorkbox.network.connection.ListenerBridge;
|
||||
import dorkbox.network.rmi.RmiImplHandler;
|
||||
import dorkbox.network.rmi.RmiBridge;
|
||||
import dorkbox.util.exceptions.InitializationException;
|
||||
import dorkbox.util.exceptions.SecurityException;
|
||||
|
||||
|
@ -64,8 +64,8 @@ class ListenerTest extends BaseTest {
|
|||
// quick and dirty test to also test connection sub-classing
|
||||
class TestConnectionA extends ConnectionImpl {
|
||||
public
|
||||
TestConnectionA(final Logger logger, final EndPoint endPoint, final RmiImplHandler rmiImplHandler) {
|
||||
super(logger, endPoint, rmiImplHandler);
|
||||
TestConnectionA(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
||||
super(logger, endPoint, rmiBridge);
|
||||
}
|
||||
|
||||
public
|
||||
|
@ -77,8 +77,8 @@ class ListenerTest extends BaseTest {
|
|||
|
||||
class TestConnectionB extends TestConnectionA {
|
||||
public
|
||||
TestConnectionB(final Logger logger, final EndPoint endPoint, final RmiImplHandler rmiImplHandler) {
|
||||
super(logger, endPoint, rmiImplHandler);
|
||||
TestConnectionB(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
||||
super(logger, endPoint, rmiBridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,7 +109,7 @@ class ListenerTest extends BaseTest {
|
|||
Server server = new Server(configuration) {
|
||||
@Override
|
||||
public
|
||||
TestConnectionA newConnection(final Logger logger, final EndPoint endPoint, final RmiImplHandler rmiBridge) {
|
||||
TestConnectionA newConnection(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
||||
return new TestConnectionA(logger, endPoint, rmiBridge);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user