Cleaned up RMI field names

This commit is contained in:
nathan 2019-01-09 18:18:05 +01:00
parent 5183309262
commit c927f87316
6 changed files with 25 additions and 27 deletions

View File

@ -1280,12 +1280,12 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
* *
* @see RemoteObject * @see RemoteObject
* *
* @param objectID this is the remote object ID (assigned by RMI). This is NOT the kryo registration ID * @param rmiId this is the remote object ID (assigned by RMI). This is NOT the kryo registration ID
* @param iFace this is the RMI interface * @param iFace this is the RMI interface
*/ */
@Override @Override
public public
RemoteObject getProxyObject(final int objectID, final Class<?> iFace) { RemoteObject getProxyObject(final int rmiId, final Class<?> iFace) {
if (iFace == null) { if (iFace == null) {
throw new IllegalArgumentException("iface cannot be null."); throw new IllegalArgumentException("iface cannot be null.");
} }
@ -1296,14 +1296,13 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
// we want to have a connection specific cache of IDs // we want to have a connection specific cache of IDs
// because this is PER CONNECTION, there is no need for synchronize(), since there will not be any issues with concurrent // because this is PER CONNECTION, there is no need for synchronize(), since there will not be any issues with concurrent
// access, but there WILL be issues with thread visibility because a different worker thread can be called for different connections // access, but there WILL be issues with thread visibility because a different worker thread can be called for different connections
RemoteObject remoteObject = proxyIdCache.get(objectID); RemoteObject remoteObject = proxyIdCache.get(rmiId);
if (remoteObject == null) { if (remoteObject == null) {
// duplicates are fine, as they represent the same object (as specified by the ID) on the remote side. // duplicates are fine, as they represent the same object (as specified by the ID) on the remote side.
// remoteObject = rmiBridge.createProxyObject(this, objectID, iFace);
// the ACTUAL proxy is created in the connection impl. // the ACTUAL proxy is created in the connection impl.
RmiProxyHandler proxyObject = new RmiProxyHandler(this, objectID, iFace); RmiProxyHandler proxyObject = new RmiProxyHandler(this, rmiId, iFace);
proxyListeners.add(proxyObject.getListener()); proxyListeners.add(proxyObject.getListener());
Class<?>[] temp = new Class<?>[2]; Class<?>[] temp = new Class<?>[2];
@ -1312,7 +1311,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
remoteObject = (RemoteObject) Proxy.newProxyInstance(RmiBridge.class.getClassLoader(), temp, proxyObject); remoteObject = (RemoteObject) Proxy.newProxyInstance(RmiBridge.class.getClassLoader(), temp, proxyObject);
proxyIdCache.put(objectID, remoteObject); proxyIdCache.put(rmiId, remoteObject);
} }
return remoteObject; return remoteObject;

View File

@ -39,7 +39,7 @@ class InvocationHandlerSerializer extends Serializer<Object> {
public public
void write(Kryo kryo, Output output, Object object) { void write(Kryo kryo, Output output, Object object) {
RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(object); RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(object);
output.writeInt(handler.objectID, true); output.writeInt(handler.rmiObjectId, true);
} }
@Override @Override

View File

@ -32,14 +32,14 @@ class InvocationResultSerializer extends FieldSerializer<InvokeMethodResult> {
public public
void write(Kryo kryo, Output output, InvokeMethodResult result) { void write(Kryo kryo, Output output, InvokeMethodResult result) {
super.write(kryo, output, result); super.write(kryo, output, result);
output.writeInt(result.objectID, true); output.writeInt(result.rmiObjectId, true);
} }
@Override @Override
public public
InvokeMethodResult read(Kryo kryo, Input input, Class<InvokeMethodResult> type) { InvokeMethodResult read(Kryo kryo, Input input, Class<InvokeMethodResult> type) {
InvokeMethodResult result = super.read(kryo, input, type); InvokeMethodResult result = super.read(kryo, input, type);
result.objectID = input.readInt(true); result.rmiObjectId = input.readInt(true);
return result; return result;
} }
} }

View File

@ -39,8 +39,8 @@ package dorkbox.network.rmi;
*/ */
public public
class InvokeMethodResult implements RmiMessage { class InvokeMethodResult implements RmiMessage {
public int objectID; public int rmiObjectId;
public byte responseID; public byte responseId;
public Object result; public Object result;
} }

View File

@ -256,7 +256,7 @@ class RmiObjectLocalHandler extends RmiObjectHandler {
if (o instanceof RemoteObject) { if (o instanceof RemoteObject) {
RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(o); RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(o);
int id = handler.objectID; int id = handler.rmiObjectId;
field.set(message, connection.getImplementationObject(id)); field.set(message, connection.getImplementationObject(id));
fields.add(field); fields.add(field);
} }
@ -309,7 +309,7 @@ class RmiObjectLocalHandler extends RmiObjectHandler {
if (o instanceof RemoteObject) { if (o instanceof RemoteObject) {
RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(o); RmiProxyHandler handler = (RmiProxyHandler) Proxy.getInvocationHandler(o);
int id = handler.objectID; int id = handler.rmiObjectId;
field.set(message, connection.getImplementationObject(id)); field.set(message, connection.getImplementationObject(id));
} }
else { else {

View File

@ -71,7 +71,7 @@ class RmiProxyHandler implements InvocationHandler {
private final boolean[] pendingResponses = new boolean[64]; private final boolean[] pendingResponses = new boolean[64];
private final ConnectionImpl connection; private final ConnectionImpl connection;
public final int objectID; // this is the RMI id public final int rmiObjectId; // this is the RMI id
public final int ID; // this is the KRYO id public final int ID; // this is the KRYO id
@ -97,16 +97,16 @@ class RmiProxyHandler implements InvocationHandler {
/** /**
* @param connection this is really the network client -- there is ONLY ever 1 connection * @param connection this is really the network client -- there is ONLY ever 1 connection
* @param objectID this is the remote object ID (assigned by RMI). This is NOT the kryo registration ID * @param rmiId this is the remote object ID (assigned by RMI). This is NOT the kryo registration ID
* @param iFace this is the RMI interface * @param iFace this is the RMI interface
*/ */
public public
RmiProxyHandler(final ConnectionImpl connection, final int objectID, final Class<?> iFace) { RmiProxyHandler(final ConnectionImpl connection, final int rmiId, final Class<?> iFace) {
super(); super();
this.connection = connection; this.connection = connection;
this.objectID = objectID; this.rmiObjectId = rmiId;
this.proxyString = "<proxy #" + objectID + ">"; this.proxyString = "<proxy #" + rmiId + ">";
EndPoint endPointConnection = this.connection.getEndPoint(); EndPoint endPointConnection = this.connection.getEndPoint();
final RmiSerializationManager serializationManager = endPointConnection.getSerialization(); final RmiSerializationManager serializationManager = endPointConnection.getSerialization();
@ -114,8 +114,7 @@ class RmiProxyHandler implements InvocationHandler {
KryoExtra kryoExtra = null; KryoExtra kryoExtra = null;
try { try {
kryoExtra = serializationManager.takeKryo(); kryoExtra = serializationManager.takeKryo();
this.ID = kryoExtra.getRegistration(iFace) this.ID = kryoExtra.getRegistration(iFace).getId();
.getId();
} finally { } finally {
if (kryoExtra != null) { if (kryoExtra != null) {
serializationManager.returnKryo(kryoExtra); serializationManager.returnKryo(kryoExtra);
@ -128,9 +127,9 @@ class RmiProxyHandler implements InvocationHandler {
@Override @Override
public public
void received(Connection connection, InvokeMethodResult invokeMethodResult) { void received(Connection connection, InvokeMethodResult invokeMethodResult) {
byte responseID = invokeMethodResult.responseID; byte responseID = invokeMethodResult.responseId;
if (invokeMethodResult.objectID != objectID) { if (invokeMethodResult.rmiObjectId != rmiId) {
return; return;
} }
@ -165,7 +164,7 @@ class RmiProxyHandler implements InvocationHandler {
String name = method.getName(); String name = method.getName();
if (name.equals("close")) { if (name.equals("close")) {
connection.removeRmiListeners(objectID, getListener()); connection.removeRmiListeners(rmiObjectId, getListener());
return null; return null;
} }
else if (name.equals("setResponseTimeout")) { else if (name.equals("setResponseTimeout")) {
@ -227,10 +226,10 @@ class RmiProxyHandler implements InvocationHandler {
} }
InvokeMethod invokeMethod = new InvokeMethod(); InvokeMethod invokeMethod = new InvokeMethod();
invokeMethod.objectID = this.objectID; invokeMethod.objectID = this.rmiObjectId;
invokeMethod.args = args; invokeMethod.args = args;
// which method do we access? // which method do we access? We always want to access the IMPLEMENTATION (if available!)
CachedMethod[] cachedMethods = connection.getEndPoint() CachedMethod[] cachedMethods = connection.getEndPoint()
.getSerialization() .getSerialization()
.getMethods(ID); .getMethods(ID);
@ -419,7 +418,7 @@ class RmiProxyHandler implements InvocationHandler {
int hashCode() { int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + this.objectID; result = prime * result + this.rmiObjectId;
return result; return result;
} }
@ -436,6 +435,6 @@ class RmiProxyHandler implements InvocationHandler {
return false; return false;
} }
RmiProxyHandler other = (RmiProxyHandler) obj; RmiProxyHandler other = (RmiProxyHandler) obj;
return this.objectID == other.objectID; return this.rmiObjectId == other.rmiObjectId;
} }
} }