Search in sources :

Example 1 with BeanFlowAsynchContext

use of jp.ossc.nimbus.service.queue.BeanFlowAsynchContext in project nimbus by nimbus-org.

the class BeanFlowMonitorImpl method cancel.

public void cancel() {
    if (monitorSet != null) {
        Iterator monitors = monitorSet.iterator();
        while (monitors.hasNext()) {
            BeanFlowMonitor monitor = (BeanFlowMonitor) monitors.next();
            monitor.cancel();
        }
    }
    if (asynchContextSet != null) {
        Iterator contexts = asynchContextSet.iterator();
        while (contexts.hasNext()) {
            BeanFlowAsynchContext context = (BeanFlowAsynchContext) contexts.next();
            context.cancel();
            contexts.remove();
        }
    }
}
Also used : Iterator(java.util.Iterator) BeanFlowAsynchContext(jp.ossc.nimbus.service.queue.BeanFlowAsynchContext)

Example 2 with BeanFlowAsynchContext

use of jp.ossc.nimbus.service.queue.BeanFlowAsynchContext in project nimbus by nimbus-org.

the class BeanFlowInvokerAccessImpl2 method getAsynchReply.

public Object getAsynchReply(Object context, BeanFlowMonitor monitor, long timeout, boolean isCancel) throws BeanFlowAsynchTimeoutException, Exception {
    BeanFlowAsynchContext asynchContext = (BeanFlowAsynchContext) context;
    Queue queue = asynchContext.getResponseQueue();
    if (queue == null) {
        return null;
    }
    asynchContext = (BeanFlowAsynchContext) queue.get(timeout);
    if (asynchContext == null) {
        if (isCancel) {
            if (monitor != null) {
                monitor.cancel();
                monitor.stop();
            }
            BeanFlowInvoker invoker = ((BeanFlowAsynchContext) context).getBeanFlowInvoker();
            if (invoker != null) {
                invoker.end();
            }
        }
        throw new BeanFlowAsynchTimeoutException(flowName);
    }
    if (asynchContext != null) {
        BeanFlowMonitor subMonitor = asynchContext.getBeanFlowMonitor();
        if (subMonitor != null) {
            ((BeanFlowMonitorImpl) subMonitor).removeAsynchContext((BeanFlowAsynchContext) context);
            if (monitor != null) {
                ((BeanFlowMonitorImpl) monitor).removeBeanFlowMonitor(subMonitor);
            }
        }
    }
    BeanFlowInvoker invoker = ((BeanFlowAsynchContext) context).getBeanFlowInvoker();
    if (invoker != null) {
        invoker.end();
    }
    try {
        asynchContext.checkError();
    } catch (Throwable th) {
        if (th instanceof Exception) {
            throw (Exception) th;
        } else {
            throw (Error) th;
        }
    }
    return asynchContext.getOutput();
}
Also used : BeanFlowAsynchContext(jp.ossc.nimbus.service.queue.BeanFlowAsynchContext) Queue(jp.ossc.nimbus.service.queue.Queue) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException) DeploymentException(jp.ossc.nimbus.core.DeploymentException) TransactionManagerFactoryException(jp.ossc.nimbus.service.transaction.TransactionManagerFactoryException)

Example 3 with BeanFlowAsynchContext

use of jp.ossc.nimbus.service.queue.BeanFlowAsynchContext in project nimbus by nimbus-org.

the class BeanFlowInvokerAccessImpl2 method invokeAsynchFlow.

public Object invokeAsynchFlow(Object obj, BeanFlowMonitor monitor, BeanFlowAsynchInvokeCallback callback, int maxAsynchWait) throws Exception {
    QueueHandlerContainer qhc = factoryCallBack.getAsynchInvokeQueueHandlerContainer();
    if (qhc == null) {
        throw new UnsupportedOperationException();
    }
    if (maxAsynchWait > 0 && qhc.size() > maxAsynchWait) {
        throw new UnavailableFlowException(flowName);
    }
    BeanFlowInvoker invoker = (BeanFlowInvoker) factoryCallBack.createFlow(flowName);
    BeanFlowMonitor newMonitor = createMonitor();
    if (callback != null) {
        ((BeanFlowMonitorImpl) monitor).addBeanFlowMonitor(newMonitor);
    }
    BeanFlowAsynchContext context = callback == null ? new BeanFlowAsynchContext(invoker, obj, newMonitor) : new BeanFlowAsynchContext(invoker, obj, newMonitor, callback);
    if (factoryCallBack.getThreadContext() != null) {
        context.putThreadContextAll(factoryCallBack.getThreadContext());
    }
    ((BeanFlowMonitorImpl) newMonitor).addAsynchContext(context);
    qhc.push(context);
    return context;
}
Also used : QueueHandlerContainer(jp.ossc.nimbus.service.queue.QueueHandlerContainer) BeanFlowAsynchContext(jp.ossc.nimbus.service.queue.BeanFlowAsynchContext)

Example 4 with BeanFlowAsynchContext

use of jp.ossc.nimbus.service.queue.BeanFlowAsynchContext in project nimbus by nimbus-org.

the class BeanFlowInvokerAccessImpl2 method invokeAsynchFlow.

public Object invokeAsynchFlow(Object obj, BeanFlowMonitor monitor, boolean isReply, int maxAsynchWait) throws Exception {
    QueueHandlerContainer qhc = factoryCallBack.getAsynchInvokeQueueHandlerContainer();
    if (qhc == null) {
        throw new UnsupportedOperationException();
    }
    if (maxAsynchWait > 0 && qhc.size() > maxAsynchWait) {
        throw new UnavailableFlowException(flowName);
    }
    BeanFlowInvoker invoker = (BeanFlowInvoker) factoryCallBack.createFlow(flowName);
    BeanFlowAsynchContext context = null;
    BeanFlowMonitor newMonitor = createMonitor();
    if (isReply) {
        ((BeanFlowMonitorImpl) monitor).addBeanFlowMonitor(newMonitor);
        final DefaultQueueService replyQueue = new DefaultQueueService();
        replyQueue.create();
        replyQueue.start();
        context = new BeanFlowAsynchContext(invoker, obj, newMonitor, replyQueue);
    } else {
        context = new BeanFlowAsynchContext(invoker, obj, newMonitor);
    }
    if (factoryCallBack.getThreadContext() != null) {
        context.putThreadContextAll(factoryCallBack.getThreadContext());
    }
    ((BeanFlowMonitorImpl) newMonitor).addAsynchContext(context);
    qhc.push(context);
    return context;
}
Also used : QueueHandlerContainer(jp.ossc.nimbus.service.queue.QueueHandlerContainer) BeanFlowAsynchContext(jp.ossc.nimbus.service.queue.BeanFlowAsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Aggregations

BeanFlowAsynchContext (jp.ossc.nimbus.service.queue.BeanFlowAsynchContext)4 QueueHandlerContainer (jp.ossc.nimbus.service.queue.QueueHandlerContainer)2 Iterator (java.util.Iterator)1 DeploymentException (jp.ossc.nimbus.core.DeploymentException)1 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)1 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)1 Queue (jp.ossc.nimbus.service.queue.Queue)1 TransactionManagerFactoryException (jp.ossc.nimbus.service.transaction.TransactionManagerFactoryException)1