Search in sources :

Example 31 with DefaultQueueService

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;
            }
        }
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IllegalCachedReferenceException(jp.ossc.nimbus.service.cache.IllegalCachedReferenceException) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException)

Example 32 with DefaultQueueService

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));
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) QueueHandlerContainer(jp.ossc.nimbus.service.queue.QueueHandlerContainer) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Aggregations

DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)32 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)20 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)14 MessageException (jp.ossc.nimbus.service.publish.MessageException)13 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)11 IndexNotFoundException (jp.ossc.nimbus.beans.IndexNotFoundException)10 IndexPropertyAccessException (jp.ossc.nimbus.beans.IndexPropertyAccessException)10 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)10 QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)10 UnknownHostException (java.net.UnknownHostException)9 DistributedQueueHandlerContainerService (jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService)6 EOFException (java.io.EOFException)3 IOException (java.io.IOException)3 SocketException (java.net.SocketException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 CacheMap (jp.ossc.nimbus.service.cache.CacheMap)3 MessageCreateException (jp.ossc.nimbus.service.publish.MessageCreateException)3