示例#1
0
  /** Remove the complete queued object list. FIXME extract some method */
  public LinkObject remove() {
    LinkObject element;
    boolean gotLock;

    if (!enabled) {
      if (log.isInfoEnabled()) log.info("FastQueue.remove: queue disabled, remove aborted");
      return null;
    }

    gotLock = lock.lockRemove();
    try {

      if (!gotLock) {
        if (enabled) {
          if (log.isInfoEnabled())
            log.info("FastQueue.remove: Remove aborted although queue enabled");
        } else {
          if (log.isInfoEnabled()) log.info("FastQueue.remove: queue disabled, remove aborted");
        }
        return null;
      }

      if (log.isTraceEnabled()) {
        log.trace("FastQueue.remove: remove starting with size " + size);
      }
      if (checkLock) {
        if (inRemove) log.warn("FastQueue.remove: Detected other remove");
        inRemove = true;
        if (inMutex) log.warn("FastQueue.remove: Detected other mutex in remove");
        inMutex = true;
      }

      element = first;

      first = last = null;
      size = 0;

      if (checkLock) {
        if (!inMutex) log.warn("FastQueue.remove: Cancelled by other mutex in remove");
        inMutex = false;
        if (!inRemove) log.warn("FastQueue.remove: Cancelled by other remove");
        inRemove = false;
      }
      if (log.isTraceEnabled()) {
        log.trace("FastQueue.remove: remove ending with size " + size);
      }

    } finally {
      lock.unlockRemove();
    }
    return element;
  }
示例#2
0
 public void setEnabled(boolean enable) {
   enabled = enable;
   if (!enabled) {
     lock.abortRemove();
     last = first = null;
   }
 }
示例#3
0
 /**
  * Set add wait timeout (default 10000 msec)
  *
  * @param timeout
  */
 public void setAddWaitTimeout(long timeout) {
   addWaitTimeout = timeout;
   lock.setAddWaitTimeout(addWaitTimeout);
 }
示例#4
0
 /**
  * get current add wait timeout
  *
  * @return current wait timeout
  */
 public long getAddWaitTimeout() {
   addWaitTimeout = lock.getAddWaitTimeout();
   return addWaitTimeout;
 }
示例#5
0
 /** Generate Queue SingleRemoveSynchronizedAddLock and set add and wait Timeouts */
 public FastQueue() {
   lock = new SingleRemoveSynchronizedAddLock();
   lock.setAddWaitTimeout(addWaitTimeout);
   lock.setRemoveWaitTimeout(removeWaitTimeout);
 }
示例#6
0
  /**
   * Add new data to the queue.
   *
   * <p>FIXME extract some method
   */
  public boolean add(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
    boolean ok = true;

    if (!enabled) {
      if (log.isInfoEnabled()) log.info("FastQueue.add: queue disabled, add aborted");
      return false;
    }

    lock.lockAdd();
    try {
      if (log.isTraceEnabled()) {
        log.trace("FastQueue.add: starting with size " + size);
      }
      if (checkLock) {
        if (inAdd) log.warn("FastQueue.add: Detected other add");
        inAdd = true;
        if (inMutex) log.warn("FastQueue.add: Detected other mutex in add");
        inMutex = true;
      }

      if ((maxQueueLength > 0) && (size >= maxQueueLength)) {
        ok = false;
        if (log.isTraceEnabled()) {
          log.trace(
              "FastQueue.add: Could not add, since queue is full ("
                  + size
                  + ">="
                  + maxQueueLength
                  + ")");
        }
      } else {
        LinkObject element = new LinkObject(msg, destination, payload);
        if (size == 0) {
          first = last = element;
          size = 1;
        } else {
          if (last == null) {
            ok = false;
            log.error(
                "FastQueue.add: Could not add, since last is null although size is "
                    + size
                    + " (>0)");
          } else {
            last.append(element);
            last = element;
            size++;
          }
        }
      }

      if (first == null) {
        log.error("FastQueue.add: first is null, size is " + size + " at end of add");
      }
      if (last == null) {
        log.error("FastQueue.add: last is null, size is " + size + " at end of add");
      }

      if (checkLock) {
        if (!inMutex) log.warn("FastQueue.add: Cancelled by other mutex in add");
        inMutex = false;
        if (!inAdd) log.warn("FastQueue.add: Cancelled by other add");
        inAdd = false;
      }
      if (log.isTraceEnabled()) log.trace("FastQueue.add: add ending with size " + size);

    } finally {
      lock.unlockAdd(true);
    }
    return ok;
  }
示例#7
0
 /** unlock queue for next remove */
 public void unlockRemove() {
   lock.unlockRemove();
 }
示例#8
0
 /** unlock queue for next add */
 public void unlockAdd() {
   lock.unlockAdd(size > 0 ? true : false);
 }
示例#9
0
 /**
  * set remove wait timeout ( default 30000 msec)
  *
  * @param timeout
  */
 public void setRemoveWaitTimeout(long timeout) {
   removeWaitTimeout = timeout;
   lock.setRemoveWaitTimeout(removeWaitTimeout);
 }
示例#10
0
 /**
  * get current remove wait timeout
  *
  * @return The timeout
  */
 public long getRemoveWaitTimeout() {
   removeWaitTimeout = lock.getRemoveWaitTimeout();
   return removeWaitTimeout;
 }