final synchronized Object remoteInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Long id = callId.getAndIncrement();
RemoteInstance remoteInstance;
remoteInstance = getRemoteInstanceFromProxy(proxy);
if (remoteInstance == null)
remoteInstance = new RemoteInstance(null, proxy.getClass().getInterfaces()[0].getName());
if (args != null) {
for (int n = 0; n < args.length; n++) {
RemoteInstance remoteRef = callHandler.getRemoteReference(args[n]);
if (remoteRef != null)
args[n] = remoteRef;
}
}
String methodId = method.toString().substring(15);
IRemoteMessage remoteCall = new RemoteCall(remoteInstance, methodId, args, id);
sendMessage(remoteCall);
RemoteReturn remoteReturn = null;
boolean bReturned = false;
do {
synchronized (remoteReturns) {
for (RemoteReturn ret : remoteReturns) {
if (ret.getCallId().equals(id)) {
bReturned = true;
remoteReturn = ret;
break;
}
}
if (bReturned)
remoteReturns.remove(remoteReturn);
else {
try {
remoteReturns.wait();
}
catch (InterruptedException ie) {}
}
}
}
while (socket.isConnected() && !bReturned);
if (!socket.isConnected() && !bReturned)
throw new LipeRMIException("Connection aborted"); //$NON-NLS-1$
if (remoteReturn.isThrowing() && remoteReturn.getRet() instanceof Throwable)
throw ((Throwable) remoteReturn.getRet()).getCause();
if (remoteReturn.getRet() instanceof RemoteInstance) {
RemoteInstance remoteInstanceReturn = (RemoteInstance) remoteReturn.getRet();
Object proxyReturn = remoteInstanceProxys.get(remoteInstanceReturn);
if (proxyReturn == null) {
proxyReturn = CallProxy.buildProxy(remoteInstanceReturn, this);
remoteInstanceProxys.put(remoteInstanceReturn, proxyReturn);
}