Search in sources :

Example 26 with MessageSendException

use of jp.ossc.nimbus.service.publish.MessageSendException in project nimbus by nimbus-org.

the class ServerConnectionImpl method close.

public synchronized void close() {
    if (clientAcceptor != null) {
        clientAcceptor.stopNoWait();
    }
    if (serverSocket != null) {
        try {
            serverSocket.close();
        } catch (IOException e) {
        }
    }
    try {
        send(createMessage(MessageImpl.MESSAGE_TYPE_SERVER_CLOSE));
    } catch (MessageSendException e) {
    }
    final Iterator clientItr = clients.iterator();
    while (clientItr.hasNext()) {
        ClientImpl client = (ClientImpl) clientItr.next();
        client.close();
    }
    clientAcceptor = null;
    if (sendQueueHandlerContainer != null) {
        sendQueueHandlerContainer.stop();
        sendQueueHandlerContainer.destroy();
        sendQueueHandlerContainer = null;
    }
    if (asynchAcceptQueueHandlerContainer != null) {
        asynchAcceptQueueHandlerContainer.stop();
        asynchAcceptQueueHandlerContainer.destroy();
        asynchAcceptQueueHandlerContainer = null;
    }
    if (asynchSendQueueHandlerContainer != null) {
        asynchSendQueueHandlerContainer.stop();
        asynchSendQueueHandlerContainer.destroy();
        asynchSendQueueHandlerContainer = null;
    }
    if (queueSelector != null) {
        queueSelector.stop();
        queueSelector.destroy();
        queueSelector = null;
    }
}
Also used : MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Iterator(java.util.Iterator) IOException(java.io.IOException)

Example 27 with MessageSendException

use of jp.ossc.nimbus.service.publish.MessageSendException in project nimbus by nimbus-org.

the class DistributedSharedContextService method load.

public synchronized void load(long timeout) throws Exception {
    if (isMain()) {
        if (contextStore != null) {
            contextStore.load(this);
        } else {
            throw new UnsupportedOperationException();
        }
    } else {
        try {
            Message message = serverConnection.createMessage(subject, null);
            Set receiveClients = serverConnection.getReceiveClientIds(message);
            if (receiveClients.size() != 0) {
                message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_LOAD));
                try {
                    Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 1, timeout);
                    Object ret = responses[0].getObject();
                    responses[0].recycle();
                    if (ret instanceof Throwable) {
                        throw new SharedContextSendException((Throwable) ret);
                    }
                } catch (RequestTimeoutException e) {
                    throw new SharedContextTimeoutException(e);
                }
            }
        } catch (MessageException e) {
            throw new SharedContextSendException(e);
        } catch (MessageSendException e) {
            throw new SharedContextSendException(e);
        }
    }
}
Also used : RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Message(jp.ossc.nimbus.service.publish.Message) MessageException(jp.ossc.nimbus.service.publish.MessageException)

Example 28 with MessageSendException

use of jp.ossc.nimbus.service.publish.MessageSendException in project nimbus by nimbus-org.

the class DistributedSharedContextService method onLoadKey.

protected synchronized Message onLoadKey(DistributedSharedContextEvent event, final Object sourceId, final int sequence, final String responseSubject, final String responseKey) {
    if (isMain()) {
        Thread loadThread = new Thread() {

            public void run() {
                Message response = null;
                try {
                    if (contextStore != null) {
                        contextStore.loadKey(DistributedSharedContextService.this);
                    } else {
                        throw new UnsupportedOperationException();
                    }
                    response = createResponseMessage(responseSubject, responseKey, null);
                } catch (Throwable th) {
                    response = createResponseMessage(responseSubject, responseKey, th);
                }
                try {
                    serverConnection.response(sourceId, sequence, response);
                } catch (MessageSendException e) {
                    getLogger().write("DSCS_00002", new Object[] { isClient ? clientSubject : subject, response }, e);
                }
            }
        };
        loadThread.start();
    }
    return null;
}
Also used : MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Message(jp.ossc.nimbus.service.publish.Message)

Example 29 with MessageSendException

use of jp.ossc.nimbus.service.publish.MessageSendException in project nimbus by nimbus-org.

the class DistributedSharedContextService method onRehash.

protected Message onRehash(final DistributedSharedContextEvent event, final Object sourceId, final int sequence, final String responseSubject, final String responseKey) {
    final DistributeInfo info = (DistributeInfo) event.value;
    Thread rehashThread = new Thread() {

        public void run() {
            Message response = null;
            try {
                info.apply(distributeInfo, sharedContextArray);
                response = createResponseMessage(responseSubject, responseKey, null);
            } catch (Throwable th) {
                response = createResponseMessage(responseSubject, responseKey, th);
            }
            try {
                serverConnection.response(sourceId, sequence, response);
            } catch (MessageSendException e) {
                getLogger().write("DSCS_00002", new Object[] { isClient ? clientSubject : subject, response }, e);
            }
        }
    };
    rehashThread.start();
    return null;
}
Also used : MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Message(jp.ossc.nimbus.service.publish.Message)

Example 30 with MessageSendException

use of jp.ossc.nimbus.service.publish.MessageSendException in project nimbus by nimbus-org.

the class DistributedSharedContextService method loadKey.

public synchronized void loadKey(long timeout) throws Exception {
    if (isMain()) {
        if (contextStore != null) {
            contextStore.loadKey(this);
        } else {
            throw new UnsupportedOperationException();
        }
    } else {
        try {
            Message message = serverConnection.createMessage(subject, null);
            Set receiveClients = serverConnection.getReceiveClientIds(message);
            if (receiveClients.size() != 0) {
                message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_LOAD_KEY));
                try {
                    Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 1, timeout);
                    Object ret = responses[0].getObject();
                    responses[0].recycle();
                    if (ret instanceof Throwable) {
                        throw new SharedContextSendException((Throwable) ret);
                    }
                } catch (RequestTimeoutException e) {
                    throw new SharedContextTimeoutException(e);
                }
            }
        } catch (MessageException e) {
            throw new SharedContextSendException(e);
        } catch (MessageSendException e) {
            throw new SharedContextSendException(e);
        }
    }
}
Also used : RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) Message(jp.ossc.nimbus.service.publish.Message) MessageException(jp.ossc.nimbus.service.publish.MessageException)

Aggregations

MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)32 Message (jp.ossc.nimbus.service.publish.Message)15 HashSet (java.util.HashSet)14 Set (java.util.Set)14 IOException (java.io.IOException)13 MessageException (jp.ossc.nimbus.service.publish.MessageException)13 SocketException (java.net.SocketException)9 SocketTimeoutException (java.net.SocketTimeoutException)9 LinkedHashSet (java.util.LinkedHashSet)9 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)9 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Iterator (java.util.Iterator)4 ConnectException (jp.ossc.nimbus.service.publish.ConnectException)4 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)4 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)4 EOFException (java.io.EOFException)3 Map (java.util.Map)3 MessageCreateException (jp.ossc.nimbus.service.publish.MessageCreateException)3