Search in sources :

Example 6 with AsynchContext

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

the class ServerConnectionImpl method sendAsynch.

public void sendAsynch(Message message) {
    if (asynchSendQueueHandlerContainer == null) {
        throw new UnsupportedOperationException();
    }
    addSendMessageCache((MessageImpl) message);
    if (clients.size() == 0) {
        return;
    }
    ClientImpl[] clientArray = (ClientImpl[]) clients.values().toArray(new ClientImpl[clients.size()]);
    for (int i = 0; i < clientArray.length; i++) {
        if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
            continue;
        }
        asynchSendQueueHandlerContainer.push(new AsynchContext(new SendRequest(clientArray[i], (MessageImpl) message)));
    }
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext)

Example 7 with AsynchContext

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

the class ServerConnectionImpl method send.

public void send(Message message) throws MessageSendException {
    addSendMessageCache((MessageImpl) message);
    if (clients.size() == 0) {
        return;
    }
    ClientImpl[] clientArray = (ClientImpl[]) clients.values().toArray(new ClientImpl[clients.size()]);
    if (sendQueueHandlerContainer == null) {
        for (int i = 0; i < clientArray.length; i++) {
            if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
                continue;
            }
            clientArray[i].send((MessageImpl) message);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        responseQueue.accept();
        for (int i = 0; i < clientArray.length; i++) {
            if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
                clientArray[i] = null;
                continue;
            }
            sendQueueHandlerContainer.push(new AsynchContext(new SendRequest(clientArray[i], (MessageImpl) message), responseQueue));
        }
        List errorClients = new ArrayList();
        for (int i = 0; i < clientArray.length; i++) {
            if (clientArray[i] == null) {
                continue;
            }
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext.getThrowable() != null) {
                errorClients.add(((SendRequest) asynchContext.getInput()).client);
            }
        }
        if (errorClients.size() != 0) {
            throw new MessageSendException("Send error : clients=" + errorClients + ", message=" + message);
        }
    }
}
Also used : MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) ArrayList(java.util.ArrayList) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) ArrayList(java.util.ArrayList) List(java.util.List) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ConnectException(jp.ossc.nimbus.service.publish.ConnectException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException)

Example 8 with AsynchContext

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

the class ServerConnectionImpl method send.

public synchronized void send(Message message) throws MessageSendException {
    long startTime = System.currentTimeMillis();
    if (clients.size() == 0) {
        addSendMessageCache((MessageImpl) message);
        return;
    }
    try {
        if (sendQueueHandlerContainer == null) {
            List currentClients = new ArrayList();
            final Iterator clientItr = clients.iterator();
            while (clientItr.hasNext()) {
                ClientImpl client = (ClientImpl) clientItr.next();
                if (!client.isStartReceive() || !client.isTargetMessage(message)) {
                    continue;
                }
                currentClients.add(client);
            }
            int retryCount = -1;
            while (currentClients.size() != 0 && retryCount < maxSendRetryCount) {
                Iterator itr = currentClients.iterator();
                while (itr.hasNext()) {
                    ClientImpl client = (ClientImpl) itr.next();
                    try {
                        client.send(message);
                        itr.remove();
                    } catch (MessageSendException e) {
                        if (logger != null) {
                            if ((retryCount + 1) >= maxSendRetryCount) {
                                if (sendErrorRetryOverMessageId != null) {
                                    logger.write(sendErrorRetryOverMessageId, new Object[] { client, message }, e);
                                }
                            } else {
                                if (sendErrorMessageId != null) {
                                    logger.write(sendErrorMessageId, new Object[] { client, message }, e);
                                }
                            }
                        }
                    }
                }
                retryCount++;
            }
            if (currentClients.size() != 0) {
                throw new MessageSendException("Send error : clients=" + currentClients + ", message=" + message);
            }
            ((MessageImpl) message).setSend(true);
        } else {
            final Map sendContexts = new HashMap();
            final Iterator clientItr = clients.iterator();
            while (clientItr.hasNext()) {
                ClientImpl client = (ClientImpl) clientItr.next();
                if (!client.isStartReceive() || !client.isTargetMessage(message)) {
                    continue;
                }
                SendRequest sendRequest = createSendRequest(client, (MessageImpl) message);
                AsynchContext asynchContext = createAsynchContext(sendRequest, sendResponseQueue);
                sendContexts.put(client, asynchContext);
                sendQueueHandlerContainer.push(asynchContext);
            }
            Throwable th = null;
            for (int i = 0, imax = sendContexts.size(); i < imax; i++) {
                AsynchContext asynchContext = (AsynchContext) sendResponseQueue.get();
                if (asynchContext == null) {
                    Iterator itr = sendContexts.values().iterator();
                    while (itr.hasNext()) {
                        ((AsynchContext) itr.next()).cancel();
                    }
                    throw new MessageSendException("Interrupted the waiting for a response sent : clients=" + sendContexts.keySet() + ", message=" + message, new InterruptedException());
                } else if (asynchContext.isCancel()) {
                    i--;
                    continue;
                } else if (asynchContext.getThrowable() == null) {
                    sendContexts.remove(((SendRequest) asynchContext.getInput()).client);
                } else {
                    th = asynchContext.getThrowable();
                }
                recycleAsynchContext(asynchContext);
            }
            if (sendContexts.size() != 0) {
                throw new MessageSendException("Send error : clients=" + sendContexts.keySet() + ", message=" + message, th);
            }
            ((MessageImpl) message).setSend(true);
        }
    } finally {
        addSendMessageCache((MessageImpl) message);
        sendProcessTime += (System.currentTimeMillis() - startTime);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with AsynchContext

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

the class ServerConnectionImpl method createAsynchContext.

protected AsynchContext createAsynchContext(SendRequest input, Queue queue) {
    AsynchContext result = null;
    if (asynchContextBuffer.size() != 0) {
        synchronized (asynchContextBuffer) {
            if (asynchContextBuffer.size() != 0) {
                result = (AsynchContext) asynchContextBuffer.remove(0);
                result.setInput(input);
                result.setResponseQueue(queue);
            }
        }
    }
    if (result == null) {
        result = new AsynchContext(input, queue);
    }
    return result;
}
Also used : AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext)

Example 10 with AsynchContext

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

the class DistributedClientConnectionImpl method removeSubject.

public void removeSubject(String subject) throws MessageSendException {
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ((ClientConnection) connectionList.get(i)).removeSubject(subject);
        }
    } 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 RemoveSubjectParallelRequest((ClientConnection) connectionList.get(i), subject), 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)

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