Search in sources :

Example 6 with Message

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

the class DistributedSharedContextService method onRequestMessage.

public Message onRequestMessage(Object sourceId, int sequence, Message message, String responseSubject, String responseKey) {
    DistributedSharedContextEvent event = null;
    try {
        event = (DistributedSharedContextEvent) message.getObject();
    } catch (MessageException e) {
        return null;
    }
    Message result = null;
    switch(event.type) {
        case DistributedSharedContextEvent.EVENT_GET_DIST_INFO:
            result = onGetDistributeInfo(event, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_REHASH:
            result = onRehash(event, sourceId, sequence, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_REHASH_REQUEST:
            onRehashRequest(event, sourceId, sequence, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_SAVE:
            result = onSave(event, sourceId, sequence, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_LOAD:
            result = onLoad(event, sourceId, sequence, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_LOAD_KEY:
            result = onLoadKey(event, sourceId, sequence, responseSubject, responseKey);
            break;
        case DistributedSharedContextEvent.EVENT_REHASH_SWITCH:
            result = onRehashSwitch(event, responseSubject, responseKey);
            break;
        default:
    }
    return result;
}
Also used : Message(jp.ossc.nimbus.service.publish.Message) MessageException(jp.ossc.nimbus.service.publish.MessageException)

Example 7 with Message

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

the class DistributedSharedContextService method load.

public void load(Object key, long timeout) throws Exception {
    if (isMain()) {
        if (contextStore != null) {
            contextStore.load(this, key);
        } else {
            throw new UnsupportedOperationException();
        }
    } else {
        try {
            Message message = serverConnection.createMessage(subject, key == null ? null : key.toString());
            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)

Example 8 with Message

use of jp.ossc.nimbus.service.publish.Message 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 9 with Message

use of jp.ossc.nimbus.service.publish.Message 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 10 with Message

use of jp.ossc.nimbus.service.publish.Message 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)

Aggregations

Message (jp.ossc.nimbus.service.publish.Message)25 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)15 MessageException (jp.ossc.nimbus.service.publish.MessageException)14 HashSet (java.util.HashSet)10 LinkedHashSet (java.util.LinkedHashSet)10 Set (java.util.Set)10 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)9 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SharedContextSendException (jp.ossc.nimbus.service.context.SharedContextSendException)2 BufferedReader (java.io.BufferedReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Iterator (java.util.Iterator)1 IndexNotFoundException (jp.ossc.nimbus.beans.IndexNotFoundException)1 IndexPropertyAccessException (jp.ossc.nimbus.beans.IndexPropertyAccessException)1 CacheMap (jp.ossc.nimbus.service.cache.CacheMap)1 NoConnectServerException (jp.ossc.nimbus.service.context.NoConnectServerException)1 SharedContextTimeoutException (jp.ossc.nimbus.service.context.SharedContextTimeoutException)1 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)1