long opnum)
throws Exception
{
boolean force = false;
RemoteRef localRef;
Exception exception = null;
/*
* Attempt object activation if active ref is unknown.
* Throws a RemoteException if object can't be activated.
*/
synchronized (this) {
if (ref == null) {
localRef = activate(force);
force = true;
} else {
localRef = ref;
}
}
for (int retries = MAX_RETRIES; retries > 0; retries--) {
try {
return localRef.invoke(obj, method, params, opnum);
} catch (NoSuchObjectException e) {
/*
* Object is not active in VM; retry call
*/
exception = e;
} catch (ConnectException e) {
/*
* Failure during connection setup; retry call
*/
exception = e;
} catch (UnknownHostException e) {
/*
* Failure during connection setup; retry call.
*/
exception = e;
} catch (ConnectIOException e) {
/*
* Failure setting up multiplexed connection or reusing
* cached connection; retry call
*/
exception = e;
} catch (MarshalException e) {
/*
* Failure during parameter serialization; call may
* have reached server, so call retry not possible.
*/
throw e;
} catch (ServerError e) {
/*
* Call reached server; propagate remote exception.
*/
throw e;
} catch (ServerException e) {
/*
* Call reached server; propagate remote exception
*/
throw e;
} catch (RemoteException e) {
/*
* This is a catch-all for other RemoteExceptions.
* UnmarshalException being the only one relevant.
*
* StubNotFoundException should never show up because
* it is generally thrown when attempting to locate
* a stub.
*
* UnexpectedException should never show up because
* it is only thrown by a stub and would be wrapped
* in a ServerException if it was propagated by a
* remote call.
*/
synchronized (this) {
if (localRef == ref) {
ref = null; // this may be overly conservative
}
}
throw e;
}
if (retries > 1) {
/*
* Activate object, since object could not be reached.
*/
synchronized (this) {
if (localRef.remoteEquals(ref) || ref == null) {
RemoteRef newRef = activate(force);
if (newRef.remoteEquals(localRef) &&
exception instanceof NoSuchObjectException &&
force == false) {
/*
* If last exception was NoSuchObjectException,
* then old value of ref is definitely wrong,