use of jp.ossc.nimbus.service.queue.AsynchContext 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);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext 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.AsynchContext 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.AsynchContext 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.AsynchContext in project nimbus by nimbus-org.
the class DefaultGeneration method compete.
public void compete(int threadNum, long timeout) throws Exception {
if (queueHandlerContainer == null && threadNum < 2) {
for (int i = 0; i < seeds.length; i++) {
if (seeds[i].getFitness() == null) {
seeds[i].fit(this);
}
}
} else {
long start = System.currentTimeMillis();
QueueHandlerContainer qhc = queueHandlerContainer;
if (qhc == null) {
QueueHandlerContainerService service = new QueueHandlerContainerService();
service.create();
service.setQueueHandler(new FitHandler());
service.setQueueHandlerSize(threadNum);
service.setQueueHandlerNowaitOnStop(true);
service.setReleaseQueue(false);
service.setIgnoreNullElement(true);
service.setWaitTimeout(1000l);
service.setQueueHandlerNowaitOnStop(true);
service.start();
qhc = service;
} else {
if (qhc.getQueueHandler() == null) {
qhc.setQueueHandler(new FitHandler());
}
}
DefaultQueueService responseQueue = new DefaultQueueService();
responseQueue.create();
responseQueue.start();
for (int i = 0; i < seeds.length; i++) {
qhc.push(new AsynchContext(new Object[] { this, seeds[i] }, responseQueue));
}
for (int i = 0; i < seeds.length; i++) {
long currentTimeout = timeout > 0 ? timeout - (System.currentTimeMillis() - start) : timeout;
if (timeout > 0 && currentTimeout <= 0) {
throw new Exception("Compete timeout. timeout=" + timeout);
}
AsynchContext ctx = (AsynchContext) responseQueue.get(currentTimeout);
if (ctx == null) {
throw new Exception("Compete timeout. timeout=" + timeout);
} else {
try {
ctx.checkError();
} catch (Exception e) {
throw e;
} catch (Throwable th) {
throw (Error) th;
}
}
}
if (queueHandlerContainer == null) {
((QueueHandlerContainerService) qhc).stop();
((QueueHandlerContainerService) qhc).destroy();
}
}
Arrays.sort(seeds, new SeedComparator(fitnessOrder));
}
Aggregations