Search in sources :

Example 21 with AsynchContext

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

Example 22 with AsynchContext

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

the class DistributedSharedContextService method size.

public int size(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
    int result = 0;
    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 += sharedContextArray[i].size(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 SizeParallelRequest(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 += ((Integer) asynchContext.getOutput()).intValue();
            }
        }
    }
    return result;
}
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 23 with AsynchContext

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

the class DistributedSharedContextService method clear.

public void clear(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("There is a node that is not possible yet clear. completed=" + i + "notCompleted=" + (sharedContextArray.length - i));
            }
            sharedContextArray[i].clear(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 ClearParallelRequest(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);
                }
            }
        }
    }
}
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 24 with AsynchContext

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

the class DistributedSharedContextService method analyzeIndex.

public void analyzeIndex(String name, long timeout) throws SharedContextSendException, SharedContextTimeoutException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0; i < sharedContextArray.length; i++) {
            sharedContextArray[i].analyzeIndex(name);
        }
    } 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 AnalyzeIndexParallelRequest(sharedContextArray[i], name), 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 (SharedContextIllegalIndexException e) {
                    throw e;
                } catch (SharedContextSendException e) {
                    throw e;
                } catch (SharedContextTimeoutException 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 25 with AsynchContext

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

AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)25 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)20 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)13 MessageException (jp.ossc.nimbus.service.publish.MessageException)11 IndexNotFoundException (jp.ossc.nimbus.beans.IndexNotFoundException)10 IndexPropertyAccessException (jp.ossc.nimbus.beans.IndexPropertyAccessException)10 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)10 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)10 UnknownHostException (java.net.UnknownHostException)8 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 Set (java.util.Set)3 CacheMap (jp.ossc.nimbus.service.cache.CacheMap)2 QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)2 IOException (java.io.IOException)1