Search in sources :

Example 1 with ResponseMessage

use of org.jowidgets.invocation.common.impl.ResponseMessage in project jo-client-platform by jo-source.

the class InvocationClientImpl method getResponseService.

@Override
public IResponseService getResponseService() {
    return new IResponseService() {

        @Override
        public void response(final Object requestId, final Object response) {
            Assert.paramNotNull(requestId, "requestId");
            final TimeStampedObject<Tuple<Object, IMessageChannel>> request = interimRequests.remove(requestId);
            if (request != null) {
                final Tuple<Object, IMessageChannel> tuple = request.getObject();
                final ResponseMessage message = new ResponseMessage(requestId, response);
                tuple.getSecond().send(message, new ExceptionCallback(invocationClientServiceRegistry, tuple.getFirst()));
            } else {
                throw new IllegalStateException("The request id '" + requestId + "' is not known");
            }
        }
    };
}
Also used : IResponseService(org.jowidgets.invocation.common.api.IResponseService) ResponseMessage(org.jowidgets.invocation.common.impl.ResponseMessage) IMessageChannel(org.jowidgets.message.api.IMessageChannel) Tuple(org.jowidgets.util.Tuple)

Example 2 with ResponseMessage

use of org.jowidgets.invocation.common.impl.ResponseMessage in project jo-client-platform by jo-source.

the class InvocationServerMessageReceiver method onMessage.

@Override
public void onMessage(final Object message, final IMessageChannel replyChannel) {
    if (message instanceof MethodInvocationMessage) {
        final MethodInvocationMessage invocationMessage = (MethodInvocationMessage) message;
        final Object invocationId = invocationMessage.getInvocationId();
        invocationServer.registerInvocation(invocationId, replyChannel);
        final IExceptionCallback exceptionCallback = new IExceptionCallback() {

            @Override
            public void exception(final Throwable throwable) {
                invocationServer.unregisterInvocation(invocationId);
                invocationServerServiceRegistry.onCancel(invocationId);
            }
        };
        replyChannel.send(new AcknowledgeMessage(invocationId), exceptionCallback);
        invocationServerServiceRegistry.onMethodInvocation((MethodInvocationMessage) message);
    } else if (message instanceof CancelMessage) {
        final CancelMessage cancelMessage = (CancelMessage) message;
        invocationServerServiceRegistry.onCancel(cancelMessage);
        invocationServer.unregisterInvocation(cancelMessage.getInvocationId());
    } else if (message instanceof ResponseMessage) {
        invocationServerServiceRegistry.onResponse((ResponseMessage) message);
    }
}
Also used : CancelMessage(org.jowidgets.invocation.common.impl.CancelMessage) MethodInvocationMessage(org.jowidgets.invocation.common.impl.MethodInvocationMessage) AcknowledgeMessage(org.jowidgets.invocation.common.impl.AcknowledgeMessage) IExceptionCallback(org.jowidgets.message.api.IExceptionCallback) ResponseMessage(org.jowidgets.invocation.common.impl.ResponseMessage)

Aggregations

ResponseMessage (org.jowidgets.invocation.common.impl.ResponseMessage)2 IResponseService (org.jowidgets.invocation.common.api.IResponseService)1 AcknowledgeMessage (org.jowidgets.invocation.common.impl.AcknowledgeMessage)1 CancelMessage (org.jowidgets.invocation.common.impl.CancelMessage)1 MethodInvocationMessage (org.jowidgets.invocation.common.impl.MethodInvocationMessage)1 IExceptionCallback (org.jowidgets.message.api.IExceptionCallback)1 IMessageChannel (org.jowidgets.message.api.IMessageChannel)1 Tuple (org.jowidgets.util.Tuple)1