Fixed RMI close method. Code polish

This commit is contained in:
nathan 2019-01-28 09:53:42 +01:00
parent debd0716cd
commit 518c98e3af
4 changed files with 57 additions and 57 deletions

View File

@ -48,12 +48,9 @@ class ConnectionRmiImplSupport implements ConnectionRmiSupport {
private final LockFreeIntMap<RemoteObjectCallback> rmiRegistrationCallbacks;
private volatile int rmiCallbackId = 0;
final ConnectionImpl connection;
protected final Logger logger;
protected
ConnectionRmiImplSupport(final ConnectionImpl connection, final RmiBridge rmiGlobalBridge) {
this.connection = connection;
@ -194,16 +191,68 @@ class ConnectionRmiImplSupport implements ConnectionRmiSupport {
return false;
}
void runCallback(final Class<?> interfaceClass, final int callbackId, final Object remoteObject) {
RemoteObjectCallback callback = rmiRegistrationCallbacks.remove(callbackId);
try {
//noinspection unchecked
callback.created(remoteObject);
} catch (Exception e) {
logger.error("Error getting or creating the remote object " + interfaceClass, e);
}
}
/**
* Used by RMI by the LOCAL side when setting up the to fetch an object for the REMOTE side
*
* @return the registered ID for a specific object, or RmiBridge.INVALID_RMI if there was no ID.
*/
public
<T> int getRegisteredId(final T object) {
// always check global before checking local, because less contention on the synchronization
int objectId = rmiGlobalBridge.getRegisteredId(object);
if (objectId != RmiBridge.INVALID_RMI) {
return objectId;
}
else {
// might return RmiBridge.INVALID_RMI;
return rmiLocalBridge.getRegisteredId(object);
}
}
/**
* This is used by RMI for the REMOTE side, to get the implementation
*
* @param objectId this is the RMI object ID
*/
public
Object getImplementationObject(final int objectId) {
if (RmiBridge.isGlobal(objectId)) {
return rmiGlobalBridge.getRegisteredObject(objectId);
} else {
return rmiLocalBridge.getRegisteredObject(objectId);
}
}
/**
* Removes a proxy object from the system
*/
void removeProxyObject(final RmiProxyHandler rmiProxyHandler) {
proxyListeners.remove(rmiProxyHandler.getListener());
proxyIdCache.remove(rmiProxyHandler.rmiObjectId);
}
/**
* For network connections, the interface class kryo ID == implementation class kryo ID, so they switch automatically.
* For local connections, we have to switch it appropriately in the LocalRmiProxy
*/
public
RmiRegistration createNewRmiObject(final NetworkSerializationManager serialization, final Class<?> interfaceClass, final Class<?> implementationClass, final int callbackId) {
RmiRegistration createNewRmiObject(final NetworkSerializationManager serialization, final Class<?> interfaceClass, final int callbackId) {
KryoExtra kryo = null;
Object object = null;
int rmiId = 0;
Class<?> implementationClass = serialization.getRmiImpl(interfaceClass);
try {
kryo = serialization.takeKryo();
@ -293,50 +342,6 @@ class ConnectionRmiImplSupport implements ConnectionRmiSupport {
return new RmiRegistration(interfaceClass, rmiId, callbackId, object);
}
public
void runCallback(final Class<?> interfaceClass, final int callbackId, final Object remoteObject) {
RemoteObjectCallback callback = rmiRegistrationCallbacks.remove(callbackId);
try {
//noinspection unchecked
callback.created(remoteObject);
} catch (Exception e) {
logger.error("Error getting or creating the remote object " + interfaceClass, e);
}
}
/**
* Used by RMI by the LOCAL side when setting up the to fetch an object for the REMOTE side
*
* @return the registered ID for a specific object, or RmiBridge.INVALID_RMI if there was no ID.
*/
public
<T> int getRegisteredId(final T object) {
// always check global before checking local, because less contention on the synchronization
int objectId = rmiGlobalBridge.getRegisteredId(object);
if (objectId != RmiBridge.INVALID_RMI) {
return objectId;
}
else {
// might return RmiBridge.INVALID_RMI;
return rmiLocalBridge.getRegisteredId(object);
}
}
/**
* This is used by RMI for the REMOTE side, to get the implementation
*
* @param objectId this is the RMI object ID
*/
public
Object getImplementationObject(final int objectId) {
if (RmiBridge.isGlobal(objectId)) {
return rmiGlobalBridge.getRegisteredObject(objectId);
} else {
return rmiLocalBridge.getRegisteredObject(objectId);
}
}
/**
* Warning. This is an advanced method. You should probably be using {@link Connection#createRemoteObject(Class, RemoteObjectCallback)}
* <p>

View File

@ -136,9 +136,7 @@ class ConnectionRmiLocalSupport extends ConnectionRmiImplSupport {
EndPoint endPoint = connection.getEndPoint();
NetworkSerializationManager serialization = endPoint.getSerialization();
Class<?> rmiImpl = serialization.getRmiImpl(registration.interfaceClass);
RmiRegistration registrationResult = createNewRmiObject(serialization, interfaceClass, rmiImpl, callbackId);
RmiRegistration registrationResult = createNewRmiObject(serialization, interfaceClass, callbackId);
connection.send(registrationResult);
// connection transport is flushed in calling method (don't need to do it here)
}

View File

@ -54,11 +54,8 @@ class ConnectionRmiNetworkSupport extends ConnectionRmiImplSupport {
// have to lookup the implementation class
NetworkSerializationManager serialization = connection.getEndPoint().getSerialization();
Class<?> rmiImpl = serialization.getRmiImpl(interfaceClass);
// For network connections, the interface class kryo ID == implementation class kryo ID, so they switch automatically.
RmiRegistration registrationResult = createNewRmiObject(serialization, interfaceClass, rmiImpl, callbackId);
RmiRegistration registrationResult = createNewRmiObject(serialization, interfaceClass, callbackId);
connection.send(registrationResult);
// connection transport is flushed in calling method (don't need to do it here)
}

View File

@ -168,7 +168,7 @@ class RmiProxyHandler implements InvocationHandler {
String name = method.getName();
if (name.equals("close")) {
rmiSupport.removeAllListeners();
rmiSupport.removeProxyObject(this);
return null;
}
else if (name.equals("setResponseTimeout")) {