Search in sources :

Example 6 with RequestTimeoutException

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

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

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

Example 9 with RequestTimeoutException

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

the class SharedQueueService method lockFirst.

protected Object lockFirst(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
    if (isMain()) {
        List keys = null;
        if (context.size() != 0) {
            synchronized (context) {
                if (context.size() != 0) {
                    Iterator itr = context.keySet().iterator();
                    for (int i = 0; i < seekDepth && itr.hasNext(); i++) {
                        if (keys == null) {
                            keys = new ArrayList();
                        }
                        keys.add(itr.next());
                    }
                }
            }
        }
        if (keys == null || keys.size() == 0) {
            return null;
        }
        for (int i = 0; i < keys.size(); i++) {
            Object key = keys.get(i);
            try {
                if (lock(key, true, true, timeout)) {
                    return key;
                }
            } catch (SharedContextTimeoutException e) {
                continue;
            }
        }
        return null;
    } else {
        Object lockedKey = null;
        final long start = System.currentTimeMillis();
        try {
            String key = getId().toString() + Thread.currentThread().getId();
            Message message = serverConnection.createMessage(subject, key);
            Set receiveClients = serverConnection.getReceiveClientIds(message);
            if (receiveClients.size() != 0) {
                message.setObject(new SharedQueueEvent(SharedQueueEvent.EVENT_LOCK_FIRST, null, new Object[] { new Long(Thread.currentThread().getId()), new Long(timeout) }));
                Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, key, 1, timeout);
                Object ret = responses[0].getObject();
                responses[0].recycle();
                if (ret instanceof Throwable) {
                    throw new SharedContextSendException((Throwable) ret);
                } else {
                    lockedKey = ret;
                }
            } else {
                throw new NoConnectServerException("Main server is not found.");
            }
        } catch (MessageException e) {
            throw new SharedContextSendException(e);
        } catch (MessageSendException e) {
            throw new SharedContextSendException(e);
        } catch (RequestTimeoutException e) {
            final boolean isNoTimeout = timeout <= 0;
            timeout = isNoTimeout ? timeout : timeout - (System.currentTimeMillis() - start);
            if (!isNoTimeout && timeout <= 0) {
                throw new SharedContextTimeoutException("timeout=" + timeout + ", processTime=" + (System.currentTimeMillis() - start), e);
            } else {
                return lockFirst(timeout);
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Error e) {
            throw e;
        }
        if (lockedKey != null) {
            Lock lock = null;
            synchronized (keyLockMap) {
                lock = (Lock) keyLockMap.get(lockedKey);
                if (lock == null) {
                    lock = new Lock(lockedKey);
                    keyLockMap.put(lockedKey, lock);
                }
            }
            final boolean isNoTimeout = timeout <= 0;
            timeout = isNoTimeout ? timeout : timeout - (System.currentTimeMillis() - start);
            if (!isNoTimeout && timeout <= 0) {
                unlock(lockedKey);
                throw new SharedContextTimeoutException("timeout=" + timeout + ", processTime=" + (System.currentTimeMillis() - start));
            } else if (!lock.acquire(getId(), true, timeout)) {
                unlock(lockedKey);
                return null;
            }
        }
        return lockedKey;
    }
}
Also used : Message(jp.ossc.nimbus.service.publish.Message) SharedContextSendException(jp.ossc.nimbus.service.context.SharedContextSendException) RequestTimeoutException(jp.ossc.nimbus.service.publish.RequestTimeoutException) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException) NoConnectServerException(jp.ossc.nimbus.service.context.NoConnectServerException) SharedContextTimeoutException(jp.ossc.nimbus.service.context.SharedContextTimeoutException)

Aggregations

Message (jp.ossc.nimbus.service.publish.Message)9 MessageException (jp.ossc.nimbus.service.publish.MessageException)9 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)9 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)9 HashSet (java.util.HashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 Set (java.util.Set)8 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)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 SharedContextSendException (jp.ossc.nimbus.service.context.SharedContextSendException)1 SharedContextTimeoutException (jp.ossc.nimbus.service.context.SharedContextTimeoutException)1 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)1 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)1 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)1