Search in sources :

Example 11 with AsynchContext

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

the class DistributedClientConnectionImpl method startReceive.

public void startReceive(long from) throws MessageSendException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ((ClientConnection) connectionList.get(i)).startReceive(from);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
        }
        responseQueue.accept();
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = new AsynchContext(new StartReceiveParallelRequest((ClientConnection) connectionList.get(i), from), responseQueue);
            parallelRequestQueueHandlerContainer.push(asynchContext);
        }
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext == null) {
                break;
            } else {
                try {
                    asynchContext.checkError();
                } catch (MessageSendException e) {
                    throw e;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Error e) {
                    throw e;
                } catch (Throwable th) {
                    // 起きないはず
                    throw new MessageSendException(th);
                }
            }
        }
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException)

Example 12 with AsynchContext

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

the class DistributedClientConnectionImpl method stopReceive.

public void stopReceive() throws MessageSendException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ((ClientConnection) connectionList.get(i)).stopReceive();
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
        }
        responseQueue.accept();
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = new AsynchContext(new StopReceiveParallelRequest((ClientConnection) connectionList.get(i)), responseQueue);
            parallelRequestQueueHandlerContainer.push(asynchContext);
        }
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext == null) {
                break;
            } else {
                try {
                    asynchContext.checkError();
                } catch (MessageSendException e) {
                    throw e;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Error e) {
                    throw e;
                } catch (Throwable th) {
                    // 起きないはず
                    throw new MessageSendException(th);
                }
            }
        }
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException)

Example 13 with AsynchContext

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

the class DistributedClientConnectionImpl method addSubject.

public void addSubject(String subject, String[] keys) throws MessageSendException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ((ClientConnection) connectionList.get(i)).addSubject(subject, keys);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
        }
        responseQueue.accept();
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = new AsynchContext(new AddSubjectParallelRequest((ClientConnection) connectionList.get(i), subject, keys), responseQueue);
            parallelRequestQueueHandlerContainer.push(asynchContext);
        }
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext == null) {
                break;
            } else {
                try {
                    asynchContext.checkError();
                } catch (MessageSendException e) {
                    throw e;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Error e) {
                    throw e;
                } catch (Throwable th) {
                    // 起きないはず
                    throw new MessageSendException(th);
                }
            }
        }
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException)

Example 14 with AsynchContext

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

the class DistributedClientConnectionImpl method close.

public void close() {
    try {
        if (parallelRequestQueueHandlerContainer == null) {
            for (int i = 0, imax = connectionList.size(); i < imax; i++) {
                try {
                    ((ClientConnection) connectionList.get(i)).close();
                } catch (RuntimeException e) {
                }
            }
        } else {
            DefaultQueueService responseQueue = new DefaultQueueService();
            try {
                responseQueue.create();
                responseQueue.start();
            } catch (Exception e) {
            }
            responseQueue.accept();
            for (int i = 0, imax = connectionList.size(); i < imax; i++) {
                AsynchContext asynchContext = new AsynchContext(new CloseParallelRequest((ClientConnection) connectionList.get(i)), responseQueue);
                parallelRequestQueueHandlerContainer.push(asynchContext);
            }
            for (int i = 0, imax = connectionList.size(); i < imax; i++) {
                AsynchContext asynchContext = (AsynchContext) responseQueue.get();
                if (asynchContext == null) {
                    break;
                } else {
                    try {
                        asynchContext.checkError();
                    } catch (Throwable th) {
                    // 起きないはず
                    }
                }
            }
        }
        if (parallelRequestQueueHandlerContainer != null) {
            parallelRequestQueueHandlerContainer.stop();
            parallelRequestQueueHandlerContainer.destroy();
            parallelRequestQueueHandlerContainer = null;
        }
    } finally {
        id = null;
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException)

Example 15 with AsynchContext

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

the class DistributedClientConnectionImpl method connect.

public void connect(Object id) throws ConnectException {
    Object tmpId = null;
    if (id == null) {
        try {
            tmpId = new GlobalUID();
        } catch (UnknownHostException e) {
            throw new ConnectException(e);
        }
    } else {
        tmpId = id;
    }
    if (connectionList.size() > 1) {
        try {
            parallelRequestQueueHandlerContainer = new QueueHandlerContainerService();
            parallelRequestQueueHandlerContainer.create();
            parallelRequestQueueHandlerContainer.setQueueHandlerSize(connectionList.size());
            DefaultQueueService parallelRequestQueue = new DefaultQueueService();
            parallelRequestQueue.create();
            parallelRequestQueue.start();
            parallelRequestQueueHandlerContainer.setQueueService(parallelRequestQueue);
            parallelRequestQueueHandlerContainer.setQueueHandler(new ParallelRequestQueueHandler());
            parallelRequestQueueHandlerContainer.setIgnoreNullElement(true);
            parallelRequestQueueHandlerContainer.setWaitTimeout(1000l);
            parallelRequestQueueHandlerContainer.start();
        } catch (Exception e) {
            throw new ConnectException(e);
        }
    }
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ClientConnection connection = (ClientConnection) connectionList.get(i);
            connection.setServiceManagerName(serviceManagerName);
            connection.connect(tmpId);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
        }
        responseQueue.accept();
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = new AsynchContext(new ConnectParallelRequest((ClientConnection) connectionList.get(i), tmpId), responseQueue);
            parallelRequestQueueHandlerContainer.push(asynchContext);
        }
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext == null) {
                break;
            } else {
                try {
                    asynchContext.checkError();
                } catch (ConnectException e) {
                    throw e;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Error e) {
                    throw e;
                } catch (Throwable th) {
                    // 起きないはず
                    throw new ConnectException(th);
                }
            }
        }
    }
    this.id = tmpId;
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) UnknownHostException(java.net.UnknownHostException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) GlobalUID(jp.ossc.nimbus.util.net.GlobalUID)

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