Search in sources :

Example 21 with DefaultQueueService

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

the class ServerConnectionImpl method initAsynchSend.

private void initAsynchSend(ServiceName queueServiceName, ServiceName queueFactoryServiceName, int asynchSendThreadSize, boolean isMulticast) throws Exception {
    if (asynchSendThreadSize <= 0) {
        return;
    }
    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();
    if (!isMulticast) {
        queueSelector = new ClientDistributedQueueSelector();
        queueSelector.create();
        queueSelector.setDistributedSize(asynchSendThreadSize);
        if (queueFactoryServiceName != null) {
            queueSelector.setQueueFactoryServiceName(queueFactoryServiceName);
        }
        queueSelector.start();
        DistributedQueueHandlerContainerService distributedQueueHandlerContainer = new DistributedQueueHandlerContainerService();
        distributedQueueHandlerContainer.create();
        distributedQueueHandlerContainer.setDistributedQueueSelector(queueSelector);
        distributedQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
        distributedQueueHandlerContainer.setIgnoreNullElement(true);
        distributedQueueHandlerContainer.setWaitTimeout(1000l);
        distributedQueueHandlerContainer.start();
        asynchSendQueueHandlerContainer = distributedQueueHandlerContainer;
    }
}
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 22 with DefaultQueueService

use of jp.ossc.nimbus.service.queue.DefaultQueueService 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.start();
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 23 with DefaultQueueService

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

the class DistributedSharedContextService method putAllAsynch.

public void putAllAsynch(Map t) throws SharedContextSendException {
    Iterator entries = t.entrySet().iterator();
    Map distMap = new HashMap();
    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) {
        entries = distMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            ((SharedContext) entry.getKey()).putAllAsynch((Map) entry.getValue());
        }
    } 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 PutAllAsynchParallelRequest((SharedContext) entry.getKey(), (Map) entry.getValue()), 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 : 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 24 with DefaultQueueService

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

the class DistributedSharedContextService method containsValue.

public boolean containsValue(Object value, 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("nodeSize=" + sharedContextArray.length + ", responseCount=" + i);
            }
            if (sharedContextArray[i].containsValue(value, timeout)) {
                return true;
            }
        }
    } 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 ContainsValueParallelRequest(sharedContextArray[i], value, 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);
                }
                if (((Boolean) asynchContext.getOutput()).booleanValue()) {
                    return true;
                }
            }
        }
    }
    return false;
}
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 25 with DefaultQueueService

use of jp.ossc.nimbus.service.queue.DefaultQueueService 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);
                }
            }
        }
    }
}
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)

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