use of org.teiid.net.socket.Message in project teiid by teiid.
the class ServerWorkItem method run.
/**
* main entry point for remote method calls.
*/
public void run() {
Message result = null;
String loggingContext = null;
final boolean encrypt = !(message.getContents() instanceof ServiceInvocationStruct);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
try {
Thread.currentThread().setContextClassLoader(this.csr.getCallerClassloader());
} catch (Throwable t) {
// ignore
}
message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
if (!(message.getContents() instanceof ServiceInvocationStruct)) {
// $NON-NLS-1$
throw new AssertionError("unknown message contents");
}
final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct) message.getContents();
final ClientService clientService = this.csr.getClientService(serviceStruct.targetClass.getName());
loggingContext = clientService.getLoggingContext();
Method m = clientService.getReflectionHelper().findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
Object methodResult;
try {
methodResult = m.invoke(clientService.getInstance(), serviceStruct.args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
ResultsFuture<Object> future = (ResultsFuture<Object>) methodResult;
future.addCompletionListener(new ResultsFuture.CompletionListener<Object>() {
public void onCompletion(ResultsFuture<Object> completedFuture) {
Message asynchResult = new Message();
try {
asynchResult.setContents(completedFuture.get());
} catch (InterruptedException e) {
asynchResult.setContents(processException(e, clientService.getLoggingContext()));
} catch (ExecutionException e) {
asynchResult.setContents(processException(e.getCause(), clientService.getLoggingContext()));
}
sendResult(asynchResult, encrypt);
}
});
} else {
// synch call
Message resultHolder = new Message();
resultHolder.setContents(methodResult);
result = resultHolder;
}
} catch (Throwable t) {
Message holder = new Message();
holder.setContents(processException(t, loggingContext));
result = holder;
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
if (result != null) {
sendResult(result, encrypt);
}
}
use of org.teiid.net.socket.Message in project teiid by teiid.
the class SocketClientInstance method exceptionOccurred.
public void exceptionOccurred(Throwable t) {
// Object encoding may fail, so send a specific type of message to indicate there was a problem
if (objectSocket.isOpen() && !isClosedException(t)) {
if (workContext.getClientVersion().compareTo(Version.EIGHT_4) >= 0 && t instanceof FailedWriteException) {
FailedWriteException fwe = (FailedWriteException) t;
if (fwe.getObject() instanceof Message) {
Message m = (Message) fwe.getObject();
if (!(m.getMessageKey() instanceof ExceptionHolder)) {
Message exception = new Message();
exception.setContents(m.getMessageKey());
exception.setMessageKey(new ExceptionHolder(fwe.getCause()));
objectSocket.write(exception);
LogManager.log(getLevel(t), LogConstants.CTX_TRANSPORT, t, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40113));
return;
}
}
}
if (workContext.getClientVersion().compareTo(Version.EIGHT_6) >= 0) {
Message exception = new Message();
exception.setMessageKey(new ExceptionHolder(t));
objectSocket.write(exception);
LogManager.log(getLevel(t), LogConstants.CTX_TRANSPORT, t, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40113));
return;
}
}
int level = getLevel(t);
LogManager.log(level, LogConstants.CTX_TRANSPORT, LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL) || level < MessageLevel.WARNING ? t : null, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40114, t.getMessage()));
objectSocket.close();
}
Aggregations