Search in sources :

Example 26 with DefaultQueueService

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

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

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

the class BeanFlowInvokerAccessImpl2 method invokeAsynchFlow.

public Object invokeAsynchFlow(Object obj, BeanFlowMonitor monitor, boolean isReply, int maxAsynchWait) throws Exception {
    QueueHandlerContainer qhc = factoryCallBack.getAsynchInvokeQueueHandlerContainer();
    if (qhc == null) {
        throw new UnsupportedOperationException();
    }
    if (maxAsynchWait > 0 && qhc.size() > maxAsynchWait) {
        throw new UnavailableFlowException(flowName);
    }
    BeanFlowInvoker invoker = (BeanFlowInvoker) factoryCallBack.createFlow(flowName);
    BeanFlowAsynchContext context = null;
    BeanFlowMonitor newMonitor = createMonitor();
    if (isReply) {
        ((BeanFlowMonitorImpl) monitor).addBeanFlowMonitor(newMonitor);
        final DefaultQueueService replyQueue = new DefaultQueueService();
        replyQueue.create();
        replyQueue.start();
        context = new BeanFlowAsynchContext(invoker, obj, newMonitor, replyQueue);
    } else {
        context = new BeanFlowAsynchContext(invoker, obj, newMonitor);
    }
    if (factoryCallBack.getThreadContext() != null) {
        context.putThreadContextAll(factoryCallBack.getThreadContext());
    }
    ((BeanFlowMonitorImpl) newMonitor).addAsynchContext(context);
    qhc.push(context);
    return context;
}
Also used : QueueHandlerContainer(jp.ossc.nimbus.service.queue.QueueHandlerContainer) BeanFlowAsynchContext(jp.ossc.nimbus.service.queue.BeanFlowAsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 29 with DefaultQueueService

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

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

the class DefaultFacadeCallService method syncParallelFacadeCallByQueue.

protected FacadeValue[] syncParallelFacadeCallByQueue(FacadeValue[] values, long timeout) {
    if (requestQueue == null) {
        throw new UnsupportedOperationException();
    }
    jp.ossc.nimbus.service.queue.DefaultQueueService[] replyQueues = new jp.ossc.nimbus.service.queue.DefaultQueueService[values.length];
    for (int i = 0; i < values.length; i++) {
        setHeaderFromThreadContext(values[i]);
        try {
            replyQueues[i] = new DefaultQueueService();
            replyQueues[i].create();
            replyQueues[i].start();
        } catch (Exception e) {
        }
        requestQueue.push(new UnsyncRequest(this, values[i], replyQueues[i]));
    }
    long procTime = 0;
    FacadeValue[] result = new FacadeValue[values.length];
    for (int i = 0; i < values.length; i++) {
        long start = System.currentTimeMillis();
        long curTimeout = timeout - procTime;
        if (curTimeout < 0) {
            curTimeout = 1;
        }
        Object response = replyQueues[i].get(curTimeout);
        procTime += System.currentTimeMillis() - start;
        try {
            replyQueues[i].stop();
            replyQueues[i].destroy();
            replyQueues[i] = null;
        } catch (Exception e) {
        }
        if (response instanceof RuntimeException) {
            throw (RuntimeException) response;
        } else {
            result[i] = (FacadeValue) response;
        }
    }
    return result;
}
Also used : DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException)

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