Search in sources :

Example 1 with IInvocationCallback

use of org.jowidgets.invocation.service.common.api.IInvocationCallback in project jo-client-platform by jo-source.

the class InvocationServiceClientImpl method getMethodService.

@Override
public <RES, INT_RES, REQ, RESP, PARAM> IMethodInvocationService<RES, INT_RES, REQ, RESP, PARAM> getMethodService(final String methodName, final long timeout) {
    Assert.paramNotNull(methodName, "methodName");
    return new IMethodInvocationService<RES, INT_RES, REQ, RESP, PARAM>() {

        @Override
        public void invoke(final IInvocationCallback<RES> invocationCallback, final IInterimResponseCallback<INT_RES> interimResponseCallback, final IInterimRequestCallback<REQ, RESP> interimRequestCallback, final PARAM parameter) {
            final IMethod method = invocationClient.getMethod(methodName);
            if (method == null) {
                throw new IllegalArgumentException("No server method registered for method name '" + methodName + "'.");
            } else {
                final Object invocationId = invocationCallbackService.registerInvocation(invocationCallback, interimResponseCallback, interimRequestCallback, timeout, invocationClient);
                method.invoke(invocationId, parameter);
            }
        }
    };
}
Also used : IMethodInvocationService(org.jowidgets.invocation.service.common.api.IMethodInvocationService) IInterimResponseCallback(org.jowidgets.invocation.service.common.api.IInterimResponseCallback) IInterimRequestCallback(org.jowidgets.invocation.service.common.api.IInterimRequestCallback) IInvocationCallback(org.jowidgets.invocation.service.common.api.IInvocationCallback) IMethod(org.jowidgets.invocation.common.api.IMethod)

Example 2 with IInvocationCallback

use of org.jowidgets.invocation.service.common.api.IInvocationCallback in project jo-client-platform by jo-source.

the class MethodImpl method invoke.

@Override
public void invoke(final Object invocationId, final Object parameter) {
    final IInvocationCallbackService invocationCallbackService = invocationServer.getInvocationCallbackService();
    cancelService.registerInvocation(invocationId);
    final IInvocationCallback<Object> invocationCallback = new IInvocationCallback<Object>() {

        @Override
        public void addCancelListener(final ICancelListener cancelListener) {
            cancelService.registerCancelListener(invocationId, cancelListener);
        }

        @Override
        public void finished(final Object result) {
            invocationCallbackService.finished(invocationId, result);
            cancelService.unregisterInvocation(invocationId);
        }

        @Override
        public void exeption(final Throwable exception) {
            invocationCallbackService.exeption(invocationId, exception);
            cancelService.unregisterInvocation(invocationId);
        }
    };
    final IInterimResponseCallback<Object> interimResponseCallback = new IInterimResponseCallback<Object>() {

        @Override
        public void response(final Object progress) {
            invocationCallbackService.interimResponse(invocationId, progress);
        }
    };
    final IInterimRequestCallback<Object, Object> interimRequestCallback = new IInterimRequestCallback<Object, Object>() {

        @Override
        public void request(final IInterimResponseCallback<Object> callback, final Object question) {
            final Object requestId = responseService.register(callback);
            invocationCallbackService.interimRequest(invocationId, requestId, question);
        }
    };
    try {
        methodInvocationService.invoke(invocationCallback, interimResponseCallback, interimRequestCallback, parameter);
    } catch (final Exception e) {
        invocationCallback.exeption(e);
    }
}
Also used : IInterimResponseCallback(org.jowidgets.invocation.service.common.api.IInterimResponseCallback) IInterimRequestCallback(org.jowidgets.invocation.service.common.api.IInterimRequestCallback) IInvocationCallback(org.jowidgets.invocation.service.common.api.IInvocationCallback) IInvocationCallbackService(org.jowidgets.invocation.common.api.IInvocationCallbackService) ICancelListener(org.jowidgets.invocation.service.common.api.ICancelListener)

Aggregations

IInterimRequestCallback (org.jowidgets.invocation.service.common.api.IInterimRequestCallback)2 IInterimResponseCallback (org.jowidgets.invocation.service.common.api.IInterimResponseCallback)2 IInvocationCallback (org.jowidgets.invocation.service.common.api.IInvocationCallback)2 IInvocationCallbackService (org.jowidgets.invocation.common.api.IInvocationCallbackService)1 IMethod (org.jowidgets.invocation.common.api.IMethod)1 ICancelListener (org.jowidgets.invocation.service.common.api.ICancelListener)1 IMethodInvocationService (org.jowidgets.invocation.service.common.api.IMethodInvocationService)1