Search in sources :

Example 1 with Queue

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

the class MethodAsynchronousInterceptorServiceTest method test4.

public void test4() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    final ServiceMetaData interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(MethodAsynchronousInterceptorService.class.getName());
    interceptorServiceData.setName("MethodAsynchronousInterceptor");
    interceptorServiceData.addDepends(interceptorServiceData.createDependsMetaData("Test", "Queue"));
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    MethodAsynchronousInterceptorService interceptor = (MethodAsynchronousInterceptorService) ServiceManagerFactory.getService("Test", "MethodAsynchronousInterceptor");
    final ServiceMetaData queueServiceData = new ServiceMetaData();
    queueServiceData.setCode(DefaultQueueService.class.getName());
    queueServiceData.setName("Queue");
    queueServiceData.setInstance(ServiceMetaData.INSTANCE_TYPE_THREADLOCAL);
    ServiceManagerFactory.registerService("Test", queueServiceData);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setResponseQueueServiceName(new ServiceName("Test", "Queue"));
        interceptor.setInvokerThreadSize(3);
        interceptor.setReturnResponse(false);
        ServiceManagerFactory.findManager("Test").startAllService();
        for (int i = 0; i < 3; i++) {
            Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

                public Object invoke(InvocationContext context) throws Throwable {
                    Thread.sleep(500);
                    return "test";
                }
            }).invokeNext(new DefaultMethodInvocationContext(new Integer(i), Integer.class.getMethod("toString", (Class[]) null), null));
            assertNull(ret);
        }
        Queue queue = (Queue) ServiceManagerFactory.getServiceObject("Test", "Queue");
        for (int i = 0; i < 3; i++) {
            AsynchronousResponse response = (AsynchronousResponse) queue.get();
            assertNotNull(response);
            assertEquals("test", response.getReturnObject());
        }
        assertNull(queue.get(500));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) Invoker(jp.ossc.nimbus.service.aop.Invoker) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Queue(jp.ossc.nimbus.service.queue.Queue) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 2 with Queue

use of jp.ossc.nimbus.service.queue.Queue 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 Queue

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

the class UnsynchFacadeCallerService method handleDequeuedObject.

/**
 * {@link Queue}から取り出した{@link UnsyncRequest}の処理を行う。<p>
 *
 * @param obj Queueから取り出したUnsyncRequest
 * @exception Throwable IOC Facade EJB呼び出しに失敗した場合
 */
public void handleDequeuedObject(Object obj) throws Throwable {
    if (obj == null) {
        return;
    }
    final UnsyncRequest request = (UnsyncRequest) obj;
    final FacadeValue facadeValue = request.getFacadeValue();
    Object result = null;
    try {
        result = request.getFacadeCaller().syncFacadeCall(facadeValue);
    } catch (RuntimeException e) {
        result = e;
    }
    final Queue replyQueue = request.getReplyQueue();
    if (replyQueue != null) {
        replyQueue.push(result);
    }
}
Also used : FacadeValue(jp.ossc.nimbus.ioc.FacadeValue) Queue(jp.ossc.nimbus.service.queue.Queue)

Example 4 with Queue

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

the class DatabaseTimerScheduleFactoryService method createQueue.

protected Queue createQueue(String scheduleName, ResultSet rs) throws Exception {
    Queue queue = null;
    if (scheduleQueueServiceNameQueryIndex > 0) {
        final String serviceNameStr = rs.getString(scheduleQueueServiceNameQueryIndex);
        if (serviceNameStr != null) {
            final ServiceNameEditor serviceNameEditor = new ServiceNameEditor();
            serviceNameEditor.setAsText(serviceNameStr);
            queue = (Queue) ServiceManagerFactory.getServiceObject((ServiceName) serviceNameEditor.getValue());
        }
    }
    if (queue == null) {
        if (scheduleQueueServiceName != null) {
            queue = (Queue) ServiceManagerFactory.getServiceObject(scheduleQueueServiceName);
        } else {
            queue = scheduleQueue;
        }
    }
    return queue;
}
Also used : Queue(jp.ossc.nimbus.service.queue.Queue)

Example 5 with Queue

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

the class DatabaseTimerScheduleFactoryService method createSchedule.

protected TimerScheduleService createSchedule(ResultSet rs, int rowNum) throws Exception {
    final TimerScheduleService schedule = new TimerScheduleService();
    final String name = createScheduleName(rs, rowNum);
    schedule.setServiceManagerName(getServiceManagerName());
    schedule.setServiceName(name);
    schedule.setName(name);
    schedule.setTask(createScheduleTask(name, rs));
    schedule.setStartTime(createStartTime(name, rs));
    final Boolean isExecuteWhenOverStartTime = createExecuteWhenOverStartTime(name, rs);
    if (isExecuteWhenOverStartTime != null) {
        schedule.setExecuteWhenOverStartTime(isExecuteWhenOverStartTime.booleanValue());
    }
    schedule.setEndTime(createEndTime(name, rs));
    final long delay = createDelay(name, rs);
    if (delay > 0) {
        schedule.setDelay(delay);
    }
    final long period = createPeriod(name, rs);
    if (period > 0) {
        schedule.setPeriod(period);
    }
    final int count = createCount(name, rs);
    if (count > 0) {
        schedule.setCount(count);
    }
    final Boolean isFixedRate = createFixedRate(name, rs);
    if (isFixedRate != null) {
        schedule.setFixedRate(isFixedRate.booleanValue());
    }
    final String[] dependsScheduleNames = createDependsScheduleNames(name, rs);
    if (dependsScheduleNames != null) {
        schedule.setDependsScheduleNames(dependsScheduleNames);
    }
    final long dependencyTimeout = createDependencyTimeout(name, rs);
    if (dependencyTimeout > 0) {
        schedule.setDependencyTimeout(dependencyTimeout);
    }
    final long dependencyConfirmInterval = createDependencyConfirmInterval(name, rs);
    if (dependencyConfirmInterval > 0) {
        schedule.setDependencyConfirmInterval(dependencyConfirmInterval);
    }
    final String errorLogMessageId = createErrorLogMessageId(name, rs);
    if (errorLogMessageId != null) {
        schedule.setErrorLogMessageId(errorLogMessageId);
    }
    final String timeoutLogMessageId = createTimeoutLogMessageId(name, rs);
    if (timeoutLogMessageId != null) {
        schedule.setTimeoutLogMessageId(timeoutLogMessageId);
    }
    final Journal journal = createJournal(name, rs);
    if (journal != null) {
        schedule.setJournal(journal);
    }
    final Queue queue = createQueue(name, rs);
    if (queue != null) {
        schedule.setQueue(queue);
    }
    final Boolean isGarbageQueue = createGarbageQueue(name, rs);
    if (isGarbageQueue != null) {
        schedule.setGarbageQueue(isGarbageQueue.booleanValue());
    }
    final ScheduleStateManager stateManager = createScheduleStateManager(name, rs);
    if (stateManager != null) {
        schedule.setScheduleStateManager(stateManager);
    }
    return schedule;
}
Also used : Journal(jp.ossc.nimbus.service.journal.Journal) Queue(jp.ossc.nimbus.service.queue.Queue)

Aggregations

Queue (jp.ossc.nimbus.service.queue.Queue)5 DeploymentException (jp.ossc.nimbus.core.DeploymentException)1 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)1 ServiceName (jp.ossc.nimbus.core.ServiceName)1 FacadeValue (jp.ossc.nimbus.ioc.FacadeValue)1 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)1 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)1 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)1 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)1 Invoker (jp.ossc.nimbus.service.aop.Invoker)1 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)1 Journal (jp.ossc.nimbus.service.journal.Journal)1 BeanFlowAsynchContext (jp.ossc.nimbus.service.queue.BeanFlowAsynchContext)1 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)1 TransactionManagerFactoryException (jp.ossc.nimbus.service.transaction.TransactionManagerFactoryException)1