Search in sources :

Example 16 with Message

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

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

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

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

the class DistributedSharedContextService method getServerMemberIdSet.

public Set getServerMemberIdSet() {
    if (serverConnection == null) {
        return new HashSet();
    }
    try {
        Message message = serverConnection.createMessage(subject, null);
        Set result = serverConnection.getReceiveClientIds(message);
        if (!isClient) {
            result.add(getId());
        }
        return result;
    } catch (MessageException e) {
        return new HashSet();
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Message(jp.ossc.nimbus.service.publish.Message) MessageException(jp.ossc.nimbus.service.publish.MessageException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 20 with Message

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

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