use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class ServerConnectionImpl method initAsynchSend.
private void initAsynchSend(ServiceName queueServiceName, ServiceName queueFactoryServiceName, int asynchSendThreadSize, boolean isMulticast) throws Exception {
if (asynchSendThreadSize <= 0) {
return;
}
asynchAcceptQueueHandlerContainer = new QueueHandlerContainerService();
asynchAcceptQueueHandlerContainer.create();
if (queueServiceName == null) {
DefaultQueueService acceptQueue = new DefaultQueueService();
acceptQueue.create();
acceptQueue.start();
asynchAcceptQueueHandlerContainer.setQueueService(acceptQueue);
} else {
asynchAcceptQueueHandlerContainer.setQueueServiceName(queueServiceName);
}
asynchAcceptQueueHandlerContainer.setQueueHandlerSize(1);
asynchAcceptQueueHandlerContainer.setQueueHandler(new AsynchAcceptQueueHandler());
asynchAcceptQueueHandlerContainer.setIgnoreNullElement(true);
asynchAcceptQueueHandlerContainer.setWaitTimeout(1000l);
asynchAcceptQueueHandlerContainer.start();
if (!isMulticast) {
queueSelector = new ClientDistributedQueueSelector();
queueSelector.create();
queueSelector.setDistributedSize(asynchSendThreadSize);
if (queueFactoryServiceName != null) {
queueSelector.setQueueFactoryServiceName(queueFactoryServiceName);
}
queueSelector.start();
DistributedQueueHandlerContainerService distributedQueueHandlerContainer = new DistributedQueueHandlerContainerService();
distributedQueueHandlerContainer.create();
distributedQueueHandlerContainer.setDistributedQueueSelector(queueSelector);
distributedQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
distributedQueueHandlerContainer.setIgnoreNullElement(true);
distributedQueueHandlerContainer.setWaitTimeout(1000l);
distributedQueueHandlerContainer.start();
asynchSendQueueHandlerContainer = distributedQueueHandlerContainer;
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class ServerConnectionImpl method initSend.
private void initSend(ServiceName sendQueueServiceName, int sendThreadSize) throws Exception {
if (sendThreadSize >= 2) {
sendQueueHandlerContainer = new QueueHandlerContainerService();
sendQueueHandlerContainer.create();
if (sendQueueServiceName == null) {
DefaultQueueService sendQueue = new DefaultQueueService();
sendQueue.create();
sendQueue.start();
sendQueueHandlerContainer.setQueueService(sendQueue);
} else {
sendQueueHandlerContainer.setQueueServiceName(sendQueueServiceName);
}
sendQueueHandlerContainer.setQueueHandlerSize(sendThreadSize);
sendQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
sendQueueHandlerContainer.start();
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedSharedContextService method putAllAsynch.
public void putAllAsynch(Map t) throws SharedContextSendException {
Iterator entries = t.entrySet().iterator();
Map distMap = new HashMap();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
SharedContext context = selectDistributeContext(entry.getKey());
Map map = (Map) distMap.get(context);
if (map == null) {
map = new HashMap();
distMap.put(context, map);
}
map.put(entry.getKey(), entry.getValue());
}
if (parallelRequestQueueHandlerContainer == null) {
entries = distMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
((SharedContext) entry.getKey()).putAllAsynch((Map) entry.getValue());
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
AsynchContext asynchContext = new AsynchContext(new PutAllAsynchParallelRequest((SharedContext) entry.getKey(), (Map) entry.getValue()), 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 (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 DistributedSharedContextService method containsValue.
public boolean containsValue(Object value, 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("nodeSize=" + sharedContextArray.length + ", responseCount=" + i);
}
if (sharedContextArray[i].containsValue(value, timeout)) {
return true;
}
}
} 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 ContainsValueParallelRequest(sharedContextArray[i], value, 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);
}
if (((Boolean) asynchContext.getOutput()).booleanValue()) {
return true;
}
}
}
}
return false;
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedSharedContextService method synchronize.
public synchronized void synchronize(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
if (sharedContextArray == null || sharedContextArray.length == 0) {
return;
}
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 synchronized. completed=" + i + "notCompleted=" + (sharedContextArray.length - i));
}
sharedContextArray[i].synchronize(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 SynchronizeParallelRequest(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 (RuntimeException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
}
Aggregations