Search in sources :

Example 1 with IllegalServiceStateException

use of jp.ossc.nimbus.lang.IllegalServiceStateException in project nimbus by nimbus-org.

the class DelayQueueService method pushElement.

protected boolean pushElement(Object element, long timeout) {
    if (getState() != STARTED || fourceEndFlg) {
        throw new IllegalServiceStateException(this);
    }
    if (!(element instanceof QueueElement)) {
        element = new QueueElement(element);
    }
    if (maxThresholdSize > 0 && (pushMonitor.isWait() || (size() >= maxThresholdSize)) && !fourceEndFlg) {
        try {
            if (timeout == 0) {
                return false;
            } else if (timeout < 0) {
                pushMonitor.initAndWaitMonitor();
            } else {
                if (!pushMonitor.initAndWaitMonitor(timeout)) {
                    return false;
                }
            }
        } catch (InterruptedException e) {
            return false;
        } finally {
            pushMonitor.releaseMonitor();
        }
    }
    if (cache == null) {
        queueElements.add(element);
    } else {
        final CachedReference ref = cache.add(element);
        if (ref != null) {
            ref.addCacheRemoveListener(this);
            queueElements.add(ref);
        } else {
            queueElements.add(element);
        }
    }
    int size = size();
    if (size > maxDepth) {
        maxDepth = size;
    }
    count++;
    countDelta++;
    lastPushedTime = System.currentTimeMillis();
    peekMonitor.notifyAllMonitor();
    if (getMonitor.isWait()) {
        long waitTime = 0;
        if (isDelay) {
            Object firstElement = getQueueElement(false);
            if (firstElement != EMPTY) {
                waitTime = delayTime - (System.currentTimeMillis() - ((QueueElement) firstElement).pushTime);
            }
        }
        if (!isDelay || waitTime <= 0) {
            if (isSafeGetOrder) {
                getMonitor.notifyMonitor();
            } else {
                getMonitor.notifyAllMonitor();
            }
        }
    }
    if (pushMonitor.isWait() && size() < maxThresholdSize) {
        pushMonitor.notifyMonitor();
    }
    return true;
}
Also used : IllegalServiceStateException(jp.ossc.nimbus.lang.IllegalServiceStateException) CachedReference(jp.ossc.nimbus.service.cache.CachedReference)

Aggregations

IllegalServiceStateException (jp.ossc.nimbus.lang.IllegalServiceStateException)1 CachedReference (jp.ossc.nimbus.service.cache.CachedReference)1