Search in sources :

Example 1 with UserQuestionRequest

use of org.jowidgets.cap.remoting.common.UserQuestionRequest in project jo-client-platform by jo-source.

the class RemoteMethodInvocationHandler method invokeRemoteMethod.

private Object invokeRemoteMethod(final Object proxy, final Method method, final Object[] args) {
    final Class<?>[] parameterTypes = method.getParameterTypes();
    final IResultCallback<Object> resultCallback = getResultCallback(parameterTypes, args);
    final IExecutionCallback executionCallback = getExecutionCallback(parameterTypes, args);
    final ArrayList<InputStream> inputStreams = getInputStreams(parameterTypes, args);
    final IInterimResponseCallback<Progress> interimResponseCallback;
    final IInterimRequestCallback<UserQuestionRequest, UserQuestionResult> userQuestionRequestCallback;
    if (executionCallback != null) {
        interimResponseCallback = new ProgressResponseCallback(executionCallback);
        userQuestionRequestCallback = new UserQuestionRequestCallback(executionCallback);
    } else {
        interimResponseCallback = new DummyProgressResponseCallback();
        userQuestionRequestCallback = new DummyUserQuestionRequestCallback(resultCallback);
    }
    final InputStreamRequestCallback inputStreamRequestCallback;
    if (!EmptyCheck.isEmpty(inputStreams)) {
        inputStreamRequestCallback = new InputStreamRequestCallback(inputStreams);
    } else {
        inputStreamRequestCallback = null;
    }
    final GenericInterimRequestCallback interimRequestCallback = new GenericInterimRequestCallback(userQuestionRequestCallback, inputStreamRequestCallback);
    final RemoteInvocationParameter parameter = new RemoteInvocationParameter(serviceId, method.getName(), parameterTypes, getFilteredArgs(args, parameterTypes));
    if (resultCallback != null) {
        invokeAsync(resultCallback, interimResponseCallback, interimRequestCallback, parameter, executionCallback, inputStreams);
        return null;
    } else {
        return invokeSync(interimResponseCallback, interimRequestCallback, parameter, executionCallback, inputStreams);
    }
}
Also used : Progress(org.jowidgets.cap.remoting.common.Progress) RemoteInvocationParameter(org.jowidgets.cap.remoting.common.RemoteInvocationParameter) InputStream(java.io.InputStream) IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) UserQuestionRequest(org.jowidgets.cap.remoting.common.UserQuestionRequest) UserQuestionResult(org.jowidgets.cap.common.api.execution.UserQuestionResult)

Example 2 with UserQuestionRequest

use of org.jowidgets.cap.remoting.common.UserQuestionRequest in project jo-client-platform by jo-source.

the class ServerExecutionCallback method userQuestion.

@Override
public UserQuestionResult userQuestion(final String question) {
    final ValueHolder<UserQuestionResult> result = new ValueHolder<UserQuestionResult>();
    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    interimRequestCallback.request(new IInterimResponseCallback<Object>() {

        @Override
        public void response(final Object response) {
            final UserQuestionResult userQuestionResult = (UserQuestionResult) response;
            result.set(userQuestionResult);
            lock.lock();
            condition.signal();
            lock.unlock();
        }
    }, new UserQuestionRequest(question));
    lock.lock();
    condition.awaitUninterruptibly();
    lock.unlock();
    return result.get();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) UserQuestionResult(org.jowidgets.cap.common.api.execution.UserQuestionResult) ValueHolder(org.jowidgets.util.ValueHolder) UserQuestionRequest(org.jowidgets.cap.remoting.common.UserQuestionRequest) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

UserQuestionResult (org.jowidgets.cap.common.api.execution.UserQuestionResult)2 UserQuestionRequest (org.jowidgets.cap.remoting.common.UserQuestionRequest)2 InputStream (java.io.InputStream)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)1 Progress (org.jowidgets.cap.remoting.common.Progress)1 RemoteInvocationParameter (org.jowidgets.cap.remoting.common.RemoteInvocationParameter)1 ValueHolder (org.jowidgets.util.ValueHolder)1