Search in sources :

Example 1 with DefaultQueueService

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

the class DistributedSharedContextService method keySet.

public Set keySet(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
    Set result = new HashSet();
    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.addAll(sharedContextArray[i].keySet(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 KeySetParallelRequest(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.addAll((Set) asynchContext.getOutput());
            }
        }
    }
    return result;
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) IndexNotFoundException(jp.ossc.nimbus.beans.IndexNotFoundException) MessageException(jp.ossc.nimbus.service.publish.MessageException) IndexPropertyAccessException(jp.ossc.nimbus.beans.IndexPropertyAccessException) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with DefaultQueueService

use of jp.ossc.nimbus.service.queue.DefaultQueueService 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 3 with DefaultQueueService

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

the class DistributedSharedContextService method putAll.

public void putAll(Map t, long timeout) throws SharedContextSendException, SharedContextTimeoutException {
    final long start = System.currentTimeMillis();
    Map distMap = new HashMap();
    Iterator entries = t.entrySet().iterator();
    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) {
        int completed = 0;
        entries = distMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            if (timeout > 0) {
                final long currentTimeout = timeout - (start - System.currentTimeMillis());
                if (currentTimeout > 0) {
                    ((SharedContext) entry.getKey()).putAll((Map) entry.getValue(), currentTimeout);
                } else {
                    throw new SharedContextTimeoutException("There is a node that is not possible yet putAll. completed=" + completed + "notCompleted=" + (distMap.size() - completed));
                }
            } else {
                ((SharedContext) entry.getKey()).putAll((Map) entry.getValue(), timeout);
            }
            completed++;
        }
    } 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 PutAllParallelRequest((SharedContext) entry.getKey(), (Map) entry.getValue(), 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);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) IndexNotFoundException(jp.ossc.nimbus.beans.IndexNotFoundException) MessageException(jp.ossc.nimbus.service.publish.MessageException) IndexPropertyAccessException(jp.ossc.nimbus.beans.IndexPropertyAccessException) Iterator(java.util.Iterator) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) CacheMap(jp.ossc.nimbus.service.cache.CacheMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with DefaultQueueService

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

the class DistributedSharedContextService method clearAsynch.

public void clearAsynch() throws SharedContextSendException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0; i < sharedContextArray.length; i++) {
            sharedContextArray[i].clearAsynch();
        }
    } 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 ClearAsynchParallelRequest(sharedContextArray[i]), 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);
                }
            }
        }
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) IndexNotFoundException(jp.ossc.nimbus.beans.IndexNotFoundException) MessageException(jp.ossc.nimbus.service.publish.MessageException) IndexPropertyAccessException(jp.ossc.nimbus.beans.IndexPropertyAccessException)

Example 5 with DefaultQueueService

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

the class DistributedSharedContextService method save.

public synchronized void save(long timeout) throws Exception {
    if (isMain()) {
        if (contextStore != null) {
            if (isClearBeforeSave) {
                contextStore.clear();
            }
            if (parallelRequestQueueHandlerContainer == null) {
                for (int i = 0; i < sharedContextArray.length; i++) {
                    sharedContextArray[i].save(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 SaveParallelRequest(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 (Exception e) {
                            throw e;
                        } catch (Error e) {
                            throw e;
                        } catch (Throwable th) {
                            // 起きないはず
                            throw new SharedContextSendException(th);
                        }
                    }
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }
    } else {
        try {
            Message message = serverConnection.createMessage(subject, null);
            Set receiveClients = serverConnection.getReceiveClientIds(message);
            if (receiveClients.size() != 0) {
                message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_SAVE, new Long(timeout)));
                try {
                    Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 1, timeout);
                    Object ret = responses[0].getObject();
                    responses[0].recycle();
                    if (ret instanceof Throwable) {
                        throw new SharedContextSendException((Throwable) ret);
                    }
                } catch (RequestTimeoutException e) {
                    throw new SharedContextTimeoutException(e);
                }
            }
        } catch (MessageException e) {
            throw new SharedContextSendException(e);
        } catch (MessageSendException e) {
            throw new SharedContextSendException(e);
        }
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Message(jp.ossc.nimbus.service.publish.Message) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) EvaluateException(jp.ossc.nimbus.service.interpreter.EvaluateException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) IndexNotFoundException(jp.ossc.nimbus.beans.IndexNotFoundException) MessageException(jp.ossc.nimbus.service.publish.MessageException) IndexPropertyAccessException(jp.ossc.nimbus.beans.IndexPropertyAccessException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext)

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