use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class SharedContextService method startService.
/**
* サービスの開始処理を行う。<p>
*
* @exception Exception サービスの開始処理に失敗した場合
*/
public void startService() throws Exception {
if (requestConnectionFactoryServiceName == null) {
throw new IllegalArgumentException("RequestConnectionFactoryServiceName must be specified.");
}
updateLock = new SynchronizeLock();
referLock = new SynchronizeLock();
if (isClient) {
if (clientCacheMapServiceName != null) {
cacheMap = (CacheMap) ServiceManagerFactory.getServiceObject(clientCacheMapServiceName);
} else if (clientCacheMap != null) {
cacheMap = clientCacheMap;
}
} else {
if (serverCacheMapServiceName != null) {
cacheMap = (CacheMap) ServiceManagerFactory.getServiceObject(serverCacheMapServiceName);
} else if (serverCacheMap != null) {
cacheMap = serverCacheMap;
}
}
if (interpreterServiceName != null) {
interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(interpreterServiceName);
}
if (sharedContextTransactionManagerServiceName != null) {
sharedContextTransactionManager = (SharedContextTransactionManager) ServiceManagerFactory.getServiceObject(sharedContextTransactionManagerServiceName);
}
executeQueueHandlerContainer = new QueueHandlerContainerService();
executeQueueHandlerContainer.create();
executeQueueHandlerContainer.setQueueHandlerSize(executeThreadSize);
if (executeQueueServiceName != null) {
executeQueueHandlerContainer.setQueueServiceName(executeQueueServiceName);
} else if (executeThreadSize > 0) {
DefaultQueueService executeQueue = new DefaultQueueService();
executeQueue.create();
executeQueue.start();
executeQueueHandlerContainer.setQueueService(executeQueue);
}
executeQueueHandlerContainer.setQueueHandler(new ExecuteQueueHandler());
executeQueueHandlerContainer.start();
if (sharedContextUpdateListenerServiceNames != null) {
for (int i = 0; i < sharedContextUpdateListenerServiceNames.length; i++) {
addSharedContextUpdateListener((SharedContextUpdateListener) ServiceManagerFactory.getServiceObject(sharedContextUpdateListenerServiceNames[i]));
}
}
ServerConnectionFactory factory = (ServerConnectionFactory) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
serverConnection = (RequestServerConnection) factory.getServerConnection();
targetMessage = serverConnection.createMessage(subject, null);
messageReceiver = (MessageReceiver) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
clientSubject = subject + CLIENT_SUBJECT_SUFFIX;
allTargetMessage = serverConnection.createMessage(subject, null);
allTargetMessage.setSubject(clientSubject, null);
messageReceiver.addSubject(this, isClient ? clientSubject : subject);
if (clusterServiceName == null) {
throw new IllegalArgumentException("ClusterServiceName must be specified.");
}
cluster = (ClusterService) ServiceManagerFactory.getServiceObject(clusterServiceName);
cluster.addClusterListener(this);
/*
lockTimeoutTimer = new Timer(true);
*/
lockTimeoutTimer = new Timer("SharedContext LockTimeoutTimerThread of " + getServiceNameObject(), true);
super.startService();
if (isWaitConnectAllOnStart) {
final long startTime = System.currentTimeMillis();
final Object myId = cluster.getUID();
while (true) {
List clusterMembers = cluster.getMembers();
Set clientIds = serverConnection.getClientIds();
clientIds.add(myId);
int clientSize = clientIds.size();
clientIds.addAll(clusterMembers);
if (clientIds.size() == clientSize) {
clientIds = serverConnection.getReceiveClientIds(allTargetMessage);
clientIds.add(myId);
clientSize = clientIds.size();
clientIds.addAll(clusterMembers);
if (clientIds.size() == clientSize) {
break;
}
}
long elapsedTime = System.currentTimeMillis() - startTime;
if (elapsedTime >= waitConnectTimeout) {
throw new Exception("A timeout occurred while waiting for all to connect. elapsedTime=" + elapsedTime);
}
Thread.sleep(100l);
}
}
if (isSynchronizeOnStart && !isMain()) {
waitConnectMain();
try {
synchronize();
} catch (NoConnectServerException e) {
if (!isClient) {
throw e;
}
}
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService 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