use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedSharedContextService method size.
public int size(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
int result = 0;
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
long start = System.currentTimeMillis();
final boolean isNoTimeout = timeout <= 0;
timeout = isNoTimeout ? timeout : timeout - (System.currentTimeMillis() - start);
if (!isNoTimeout && timeout < 0) {
throw new SharedContextTimeoutException("nodeSize=" + sharedContextArray.length + ", responseCount=" + i);
}
result += sharedContextArray[i].size(timeout);
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new SizeParallelRequest(sharedContextArray[i], timeout), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextSendException e) {
throw e;
} catch (SharedContextTimeoutException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
result += ((Integer) asynchContext.getOutput()).intValue();
}
}
}
return result;
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedSharedContextService method clear.
public void clear(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
long start = System.currentTimeMillis();
final boolean isNoTimeout = timeout <= 0;
timeout = isNoTimeout ? timeout : timeout - (System.currentTimeMillis() - start);
if (!isNoTimeout && timeout < 0) {
throw new SharedContextTimeoutException("There is a node that is not possible yet clear. completed=" + i + "notCompleted=" + (sharedContextArray.length - i));
}
sharedContextArray[i].clear(timeout);
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new ClearParallelRequest(sharedContextArray[i], timeout), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextSendException e) {
throw e;
} catch (SharedContextTimeoutException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService 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;
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedSharedContextService method analyzeIndex.
public void analyzeIndex(String name, long timeout) throws SharedContextSendException, SharedContextTimeoutException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
sharedContextArray[i].analyzeIndex(name);
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new AnalyzeIndexParallelRequest(sharedContextArray[i], name), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextIllegalIndexException e) {
throw e;
} catch (SharedContextSendException e) {
throw e;
} catch (SharedContextTimeoutException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DefaultFacadeCallService method syncParallelFacadeCallByQueue.
protected FacadeValue[] syncParallelFacadeCallByQueue(FacadeValue[] values, long timeout) {
if (requestQueue == null) {
throw new UnsupportedOperationException();
}
jp.ossc.nimbus.service.queue.DefaultQueueService[] replyQueues = new jp.ossc.nimbus.service.queue.DefaultQueueService[values.length];
for (int i = 0; i < values.length; i++) {
setHeaderFromThreadContext(values[i]);
try {
replyQueues[i] = new DefaultQueueService();
replyQueues[i].create();
replyQueues[i].start();
} catch (Exception e) {
}
requestQueue.push(new UnsyncRequest(this, values[i], replyQueues[i]));
}
long procTime = 0;
FacadeValue[] result = new FacadeValue[values.length];
for (int i = 0; i < values.length; i++) {
long start = System.currentTimeMillis();
long curTimeout = timeout - procTime;
if (curTimeout < 0) {
curTimeout = 1;
}
Object response = replyQueues[i].get(curTimeout);
procTime += System.currentTimeMillis() - start;
try {
replyQueues[i].stop();
replyQueues[i].destroy();
replyQueues[i] = null;
} catch (Exception e) {
}
if (response instanceof RuntimeException) {
throw (RuntimeException) response;
} else {
result[i] = (FacadeValue) response;
}
}
return result;
}
Aggregations