}
void asyncRemoteCall(final String fragment, final String methodSignature,
final Object[] args, final AsyncRemoteCallCallback callback) {
if (networkChannel == null) {
throw new RemoteOSGiException("Channel is closed"); //$NON-NLS-1$
}
// check arguments for streams and replace with placeholder
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof InputStream) {
args[i] = getInputStreamPlaceholder((InputStream) args[i]);
} else if (args[i] instanceof OutputStream) {
args[i] = getOutputStreamPlaceholder((OutputStream) args[i]);
}
}
final Integer xid = new Integer(RemoteOSGiServiceImpl.nextXid());
synchronized (callbacks) {
callbacks.put(xid, new AsyncCallback() {
public void result(final RemoteOSGiMessage msg) {
final RemoteCallResultMessage resultMsg = (RemoteCallResultMessage) msg;
if (resultMsg.causedException()) {
callback.remoteCallResult(false, resultMsg
.getException());
}
final Object result = resultMsg.getResult();
final Object res;
if (result instanceof InputStreamHandle) {
res = getInputStreamProxy((InputStreamHandle) result);
} else if (result instanceof OutputStreamHandle) {
res = getOutputStreamProxy((OutputStreamHandle) result);
} else {
res = result;
}
callback.remoteCallResult(true, res);
}
});
}
final RemoteCallMessage invokeMsg = new RemoteCallMessage();
invokeMsg.setServiceID(fragment);
invokeMsg.setMethodSignature(methodSignature);
invokeMsg.setArgs(args);
invokeMsg.setXID(xid.shortValue());
try {
send(invokeMsg);
} catch (final RemoteOSGiException e) {
callbacks.remove(xid);
callback
.remoteCallResult(
false,
new RemoteOSGiException(
"Method invocation of " //$NON-NLS-1$
+ getRemoteAddress()
+ "#" + fragment + " " + methodSignature + " failed.", e)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}