Search in sources :

Example 1 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class DistributedSharedContextService method startService.

/**
 * サービスの開始処理を行う。<p>
 *
 * @exception Exception サービスの開始処理に失敗した場合
 */
public void startService() throws Exception {
    if (sharedContextKeyDistributorServiceName == null) {
        MD5HashSharedContextKeyDistributorService defaultKeyDistributor = new MD5HashSharedContextKeyDistributorService();
        defaultKeyDistributor.create();
        defaultKeyDistributor.start();
        keyDistributor = defaultKeyDistributor;
    } else {
        keyDistributor = (SharedContextKeyDistributor) ServiceManagerFactory.getServiceObject(sharedContextKeyDistributorServiceName);
    }
    if (contextStoreServiceName != null) {
        contextStore = (ContextStore) ServiceManagerFactory.getServiceObject(contextStoreServiceName);
    }
    if (requestConnectionFactoryServiceName == null) {
        throw new IllegalArgumentException("RequestConnectionFactoryServiceName must be specified.");
    }
    if (sharedContextUpdateListenerServiceNames != null) {
        for (int i = 0; i < sharedContextUpdateListenerServiceNames.length; i++) {
            addSharedContextUpdateListener((SharedContextUpdateListener) ServiceManagerFactory.getServiceObject(sharedContextUpdateListenerServiceNames[i]));
        }
    }
    if (parallelRequestThreadSize > 0) {
        parallelRequestQueueHandlerContainer = new QueueHandlerContainerService();
        parallelRequestQueueHandlerContainer.create();
        parallelRequestQueueHandlerContainer.setQueueHandlerSize(parallelRequestThreadSize);
        if (parallelRequestQueueServiceName == null) {
            DefaultQueueService parallelRequestQueue = new DefaultQueueService();
            parallelRequestQueue.create();
            parallelRequestQueue.start();
            parallelRequestQueueHandlerContainer.setQueueService(parallelRequestQueue);
        } else {
            parallelRequestQueueHandlerContainer.setQueueServiceName(parallelRequestQueueServiceName);
        }
        parallelRequestQueueHandlerContainer.setQueueHandler(new ParallelRequestQueueHandler());
        parallelRequestQueueHandlerContainer.start();
    }
    ServerConnectionFactory factory = (ServerConnectionFactory) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
    serverConnection = (RequestServerConnection) factory.getServerConnection();
    messageReceiver = (MessageReceiver) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
    clientSubject = subject + CLIENT_SUBJECT_SUFFIX;
    targetMessage = serverConnection.createMessage(subject, null);
    if (clusterServiceName == null) {
        throw new IllegalArgumentException("ClusterServiceName must be specified.");
    }
    cluster = (ClusterService) ServiceManagerFactory.getServiceObject(clusterServiceName);
    if (interpreterServiceName != null) {
        interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(interpreterServiceName);
    }
    sharedContextArray = new SharedContextService[distributedSize];
    for (int i = 0; i < sharedContextArray.length; i++) {
        sharedContextArray[i] = isMainDistributed ? new ForDistributedSharedContextService(i) : new SharedContextService();
        if (isManagedDataNode) {
            sharedContextArray[i].setServiceManagerName(getServiceManagerName());
        }
        sharedContextArray[i].setServiceName(getServiceName() + '$' + i);
        sharedContextArray[i].create();
        sharedContextArray[i].setRequestConnectionFactoryServiceName(requestConnectionFactoryServiceName);
        sharedContextArray[i].setClusterServiceName(clusterServiceName);
        if (clientCacheMapServiceName != null) {
            sharedContextArray[i].setClientCacheMap((CacheMap) ServiceManagerFactory.getServiceObject(clientCacheMapServiceName));
        }
        if (serverCacheMapServiceName != null) {
            sharedContextArray[i].setServerCacheMap((CacheMap) ServiceManagerFactory.getServiceObject(serverCacheMapServiceName));
        }
        if (contextStoreServiceName != null) {
            sharedContextArray[i].setContextStoreServiceName(contextStoreServiceName);
        }
        if (interpreterServiceName != null) {
            sharedContextArray[i].setInterpreterServiceName(interpreterServiceName);
        }
        if (interpretContextVariableName != null) {
            sharedContextArray[i].setInterpretContextVariableName(interpretContextVariableName);
        }
        if (executeQueueServiceName != null) {
            sharedContextArray[i].setExecuteQueueServiceName(executeQueueServiceName);
        }
        if (sharedContextTransactionManagerServiceName != null) {
            sharedContextArray[i].setSharedContextTransactionManagerServiceName(sharedContextTransactionManagerServiceName);
        }
        sharedContextArray[i].setExecuteThreadSize(executeThreadSize);
        sharedContextArray[i].setSubject(subject + "$" + i);
        sharedContextArray[i].setClient(isClient || isRehashEnabled ? true : false);
        sharedContextArray[i].setSynchronizeTimeout(synchronizeTimeout);
        sharedContextArray[i].setDefaultTimeout(defaultTimeout);
        sharedContextArray[i].setSynchronizeOnStart(false);
        sharedContextArray[i].setSaveOnlyMain(true);
        sharedContextArray[i].setClearBeforeSave(false);
        sharedContextArray[i].setLoadOnStart(false);
        sharedContextArray[i].setLoadKeyOnStart(false);
        sharedContextArray[i].setSaveOnStop(false);
        sharedContextArray[i].setWaitConnectAllOnStart(isWaitConnectAllOnStart());
        sharedContextArray[i].setWaitConnectTimeout(waitConnectTimeout);
        if (updateListeners != null) {
            for (int j = 0; j < updateListeners.size(); j++) {
                sharedContextArray[i].addSharedContextUpdateListener((SharedContextUpdateListener) updateListeners.get(j));
            }
        }
        Iterator entries = indexMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            if (entry.getValue() instanceof BeanTableIndexKeyFactory) {
                sharedContextArray[i].setIndex((String) entry.getKey(), (BeanTableIndexKeyFactory) entry.getValue());
            } else {
                sharedContextArray[i].setIndex((String) entry.getKey(), (String[]) entry.getValue());
            }
        }
        sharedContextArray[i].start();
    }
    distributeInfo = new DistributeInfo(getId(), distributedSize);
    serverConnection.addServerConnectionListener(this);
    messageReceiver.addSubject(this, isClient ? clientSubject : subject);
    if (!isClient) {
        rehash();
    }
    for (int i = 0; i < sharedContextArray.length; i++) {
        if (sharedContextArray[i].isClient() && sharedContextArray[i].indexManager != null && sharedContextArray[i].indexManager.hasIndex()) {
            sharedContextArray[i].waitConnectMain();
            sharedContextArray[i].synchronize();
        }
    }
    if (isMain()) {
        if (isLoadKeyOnStart) {
            loadKey();
        } else if (isLoadOnStart) {
            load();
        }
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) ServerConnectionFactory(jp.ossc.nimbus.service.publish.ServerConnectionFactory) Iterator(java.util.Iterator) CacheMap(jp.ossc.nimbus.service.cache.CacheMap) HashMap(java.util.HashMap) Map(java.util.Map) BeanTableIndexKeyFactory(jp.ossc.nimbus.beans.BeanTableIndexKeyFactory)

Example 2 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class ServerConnectionImpl method initSend.

private void initSend(ServiceName sendQueueServiceName, int sendThreadSize, boolean isMulticast) throws Exception {
    if (!isMulticast && sendThreadSize >= 1) {
        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.setIgnoreNullElement(true);
        sendQueueHandlerContainer.setWaitTimeout(1000l);
        sendQueueHandlerContainer.start();
        sendResponseQueue = new DefaultQueueService();
        try {
            sendResponseQueue.create();
            sendResponseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        sendResponseQueue.accept();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException) EOFException(java.io.EOFException) CancelledKeyException(java.nio.channels.CancelledKeyException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 3 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService 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.setIgnoreNullElement(true);
        sendQueueHandlerContainer.setWaitTimeout(1000l);
        sendQueueHandlerContainer.start();
        sendResponseQueue = new DefaultQueueService();
        try {
            sendResponseQueue.create();
            sendResponseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        sendResponseQueue.accept();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException) EOFException(java.io.EOFException) CancelledKeyException(java.nio.channels.CancelledKeyException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 4 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class ServerConnectionImpl method initAsynchSend.

private void initAsynchSend(ServiceName queueServiceName, ServiceName queueFactoryServiceName, int clientQueueDistributedSize) throws Exception {
    if (clientQueueDistributedSize > 0) {
        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();
        queueSelector = new ClientDistributedQueueSelector();
        queueSelector.create();
        queueSelector.setDistributedSize(clientQueueDistributedSize);
        if (queueFactoryServiceName != null) {
            queueSelector.setQueueFactoryServiceName(queueFactoryServiceName);
        }
        queueSelector.start();
        asynchSendQueueHandlerContainer = new DistributedQueueHandlerContainerService();
        asynchSendQueueHandlerContainer.create();
        asynchSendQueueHandlerContainer.setDistributedQueueSelector(queueSelector);
        asynchSendQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
        asynchSendQueueHandlerContainer.setIgnoreNullElement(true);
        asynchSendQueueHandlerContainer.setWaitTimeout(1000l);
        asynchSendQueueHandlerContainer.start();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 5 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class DefaultPingPongHandlerService method startService.

@Override
public void startService() throws Exception {
    if (pingSendQueueHandlerContainerServiceName != null) {
        queue = (QueueHandlerContainer) ServiceManagerFactory.getServiceObject(pingSendQueueHandlerContainerServiceName);
    } else {
        QueueHandlerContainerService qhc = new QueueHandlerContainerService();
        qhc.setQueueHandlerSize(queueHandlerSize);
        qhc.setMaxRetryCount(3);
        queue = qhc;
    }
    pingByteBuffer = ByteBuffer.wrap(pingMessage.getBytes());
    queue.setQueueHandler(new PingSendQueueHandler());
    queue.accept();
    daemon.start();
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService)

Aggregations

QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)12 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)10 DistributedQueueHandlerContainerService (jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService)7 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 SocketException (java.net.SocketException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 CancelledKeyException (java.nio.channels.CancelledKeyException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ClosedSelectorException (java.nio.channels.ClosedSelectorException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 MessageCreateException (jp.ossc.nimbus.service.publish.MessageCreateException)2 MessageException (jp.ossc.nimbus.service.publish.MessageException)2 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)2 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 HashSet (java.util.HashSet)1