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");
}
}
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();
}
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);
}
}
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;
}
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;
}
Aggregations