Search in sources :

Example 6 with MessageSendException

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

the class DistributedSharedContextService method save.

public synchronized void save(long timeout) throws Exception {
    if (isMain()) {
        if (contextStore != null) {
            if (isClearBeforeSave) {
                contextStore.clear();
            }
            if (parallelRequestQueueHandlerContainer == null) {
                for (int i = 0; i < sharedContextArray.length; i++) {
                    sharedContextArray[i].save(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 SaveParallelRequest(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 (Exception e) {
                            throw e;
                        } catch (Error e) {
                            throw e;
                        } catch (Throwable th) {
                            // 起きないはず
                            throw new SharedContextSendException(th);
                        }
                    }
                }
            }
        } 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_SAVE, new Long(timeout)));
                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 : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Message(jp.ossc.nimbus.service.publish.Message) 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) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext)

Example 7 with MessageSendException

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

the class DistributedSharedContextService method setRehashEnabled.

public void setRehashEnabled(boolean isEnabled) throws SharedContextSendException, SharedContextTimeoutException {
    if (getState() == STARTED) {
        try {
            Message message = serverConnection.createMessage(subject, Integer.toString(DistributedSharedContextEvent.EVENT_REHASH_SWITCH));
            message.setSubject(clientSubject, null);
            Set receiveClients = serverConnection.getReceiveClientIds(message);
            if (receiveClients.size() != 0) {
                message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_REHASH_SWITCH, isEnabled ? Boolean.TRUE : Boolean.FALSE));
                try {
                    Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 0, defaultTimeout);
                    for (int i = 0; i < responses.length; i++) {
                        Object ret = responses[i].getObject();
                        responses[i].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);
        }
    }
    isRehashEnabled = isEnabled;
}
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 8 with MessageSendException

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

the class DistributedSharedContextService method displayDistributeInfo.

public String displayDistributeInfo() throws SharedContextSendException, SharedContextTimeoutException {
    DistributeGrid grid = new DistributeGrid();
    try {
        Message message = serverConnection.createMessage(subject, Integer.toString(DistributedSharedContextEvent.EVENT_GET_DIST_INFO));
        Set receiveClients = serverConnection.getReceiveClientIds(message);
        if (!isClient) {
            grid.addDistributeInfo(distributeInfo);
        }
        if (receiveClients.size() != 0) {
            long timeout = rehashTimeout;
            message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_GET_DIST_INFO, new Long(timeout)));
            try {
                Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 0, timeout);
                for (int i = 0; i < responses.length; i++) {
                    grid.addDistributeInfo((DistributeInfo) responses[i].getObject());
                    responses[i].recycle();
                }
            } catch (RequestTimeoutException e) {
                throw new SharedContextTimeoutException(e);
            }
        }
    } catch (MessageException e) {
        throw new SharedContextSendException(e);
    } catch (MessageSendException e) {
        throw new SharedContextSendException(e);
    }
    return grid.toString();
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Message(jp.ossc.nimbus.service.publish.Message) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException)

Example 9 with MessageSendException

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

the class ClientConnectionImpl method startReceive.

private void startReceive(long from, boolean isRestart) throws MessageSendException {
    if (socket == null) {
        throw new MessageSendException("Not connected.");
    }
    if (!isRestart && isStartReceive) {
        return;
    }
    try {
        isStartReceive = true;
        send(new StartReceiveMessage(from), isAcknowledge);
    } catch (SocketTimeoutException e) {
        isStartReceive = false;
        throw new MessageSendException(e);
    } catch (SocketException e) {
        isStartReceive = false;
        throw new MessageSendException(e);
    } catch (IOException e) {
        isStartReceive = false;
        throw new MessageSendException(e);
    } catch (ClassNotFoundException e) {
        isStartReceive = false;
        throw new MessageSendException(e);
    }
}
Also used : SocketException(java.net.SocketException) StartReceiveMessage(jp.ossc.nimbus.service.publish.tcp.StartReceiveMessage) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 10 with MessageSendException

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

the class ClientConnectionImpl method addSubject.

public void addSubject(String subject, String[] keys) throws MessageSendException {
    if (socket == null) {
        throw new MessageSendException("Not connected.");
    }
    if (subject == null) {
        return;
    }
    try {
        send(new AddMessage(subject, keys), isAcknowledge);
    } catch (SocketTimeoutException e) {
        throw new MessageSendException(e);
    } catch (SocketException e) {
        throw new MessageSendException(e);
    } catch (IOException e) {
        throw new MessageSendException(e);
    } catch (ClassNotFoundException e) {
        throw new MessageSendException(e);
    }
    if (subjects == null) {
        subjects = Collections.synchronizedMap(new HashMap());
    }
    Set keySet = (Set) subjects.get(subject);
    if (keySet == null) {
        keySet = Collections.synchronizedSet(new HashSet());
        subjects.put(subject, keySet);
    }
    if (keys == null) {
        keySet.add(null);
    } else {
        for (int i = 0; i < keys.length; i++) {
            keySet.add(keys[i]);
        }
    }
}
Also used : SocketException(java.net.SocketException) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) SocketTimeoutException(java.net.SocketTimeoutException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IOException(java.io.IOException) AddMessage(jp.ossc.nimbus.service.publish.tcp.AddMessage) HashSet(java.util.HashSet)

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