String method_name = invocation.getMethodName();
Object[] params = invocation.getParameters();
String[] signature = invocation.getSignature();
Class<?>[] class_signature = new Class[signature.length];
RemoteOutputStreamCommandResponse response;
try {
// get the stream that the command wants to access
Long stream_id = remote_command.getStreamId();
OutputStream the_stream;
synchronized (m_lock) {
the_stream = m_remotedOutputStreams.get(stream_id);
if (the_stream == null) {
throw new IllegalArgumentException(LOG.getMsgString(CommI18NResourceKeys.INVALID_OUTSTREAM_ID,
stream_id, remote_command));
}
setLastAccess(stream_id, System.currentTimeMillis());
}
LOG.debug(CommI18NResourceKeys.INVOKING_OUTSTREAM_FROM_REMOTE_CLIENT, stream_id, method_name);
// use reflection to make the call
for (int x = 0; x < signature.length; x++) {
class_signature[x] = ClassUtil.getClassFromTypeName(signature[x]);
}
Method method = OutputStream.class.getMethod(method_name, class_signature);
Object results = method.invoke(the_stream, params);
response = new RemoteOutputStreamCommandResponse(remote_command, results);
// if the client has asked to close the stream, then we will ask that this service be deregistered as soon as possible
// once the stream is closed, a client should not request anything else from our service (obviously, there is nothing else
// this service can provide since the stream is now useless)
if ("close".equals(method_name)) {
setLastAccess(stream_id, 0L);
}
} catch (Exception e) {
LOG.warn(e, CommI18NResourceKeys.FAILED_TO_INVOKE_OUTSTREAM_METHOD, method_name, remote_command);
response = new RemoteOutputStreamCommandResponse(remote_command, e);
}
return response;
}