コード例 #1
0
  synchronized void transactionExpired(TransactionQueueEvent event) {
    mServicingCount--;
    mTotalExpired++;

    if (mListeners.size() > 0) {
      event = new TransactionQueueEvent(event);

      Iterator it = mListeners.iterator();
      while (it.hasNext()) {
        ((TransactionQueueListener) it.next()).transactionExpired(event);
      }
    }
  }
コード例 #2
0
  synchronized void transactionException(TransactionQueueEvent event, Throwable e) {
    mServicingCount--;
    mTotalServiceExceptions++;

    if (mListeners.size() > 0) {
      event = new TransactionQueueEvent(event, e);

      Iterator it = mListeners.iterator();
      while (it.hasNext()) {
        ((TransactionQueueListener) it.next()).transactionException(event);
      }
    }
  }
コード例 #3
0
  synchronized void uncaughtException(Throwable e) {
    mTotalUncaughtExceptions++;

    if (mExceptionListeners.size() > 0) {
      UncaughtExceptionEvent event = new UncaughtExceptionEvent(this, e);

      Iterator it = mExceptionListeners.iterator();
      while (it.hasNext()) {
        ((UncaughtExceptionListener) it.next()).uncaughtException(event);
      }
    } else {
      Thread current = Thread.currentThread();
      current.getThreadGroup().uncaughtException(current, e);
    }
  }
コード例 #4
0
  /**
   * Enqueues a transaction that will be serviced when a worker is available. If the queue is full
   * or cannot accept new transactions, the transaction is not enqueued, and false is returned.
   *
   * @return true if enqueued, false if queue is full or cannot accept new transactions.
   */
  public synchronized boolean enqueue(Transaction transaction) {
    mTotalEnqueueAttempts++;

    if (transaction == null || mThreadPool.isClosed()) {
      return false;
    }

    int queueSize;
    if ((queueSize = mQueue.size()) >= mMaxSize) {
      if (mListeners.size() > 0) {
        TransactionQueueEvent event = new TransactionQueueEvent(this, transaction);

        Iterator it = mListeners.iterator();
        while (it.hasNext()) {
          ((TransactionQueueListener) it.next()).transactionQueueFull(event);
        }
      }
      return false;
    }

    if (!mSuspended) {
      if (!ensureWaitingThread()) {
        return false;
      }
    }

    mTotalEnqueued++;

    TransactionQueueEvent event = new TransactionQueueEvent(this, transaction);

    mQueue.addLast(event);

    if (++queueSize > mPeakQueueSize) {
      mPeakQueueSize = queueSize;
    }

    notify();

    if (mListeners.size() > 0) {
      Iterator it = mListeners.iterator();
      while (it.hasNext()) {
        ((TransactionQueueListener) it.next()).transactionEnqueued(event);
      }
    }

    return true;
  }
コード例 #5
0
  synchronized void transactionServiced(TransactionQueueEvent event) {
    TransactionQueueEvent svcEvent = new TransactionQueueEvent(event);

    mTotalServiceDuration += (svcEvent.getTimestampMillis() - event.getTimestampMillis());

    if (mListeners.size() > 0) {
      Iterator it = mListeners.iterator();
      while (it.hasNext()) {
        ((TransactionQueueListener) it.next()).transactionServiced(svcEvent);
      }
    }

    // Adjust counters at end in case a listener threw an exception and let
    // the call to transactionException adjust the counters instead.
    mServicingCount--;
    mTotalServiced++;
  }
コード例 #6
0
  synchronized TransactionQueueEvent transactionDequeued(TransactionQueueEvent event) {

    if (++mServicingCount > mPeakServicingCount) {
      mPeakServicingCount = mServicingCount;
    }

    TransactionQueueEvent deqEvent = new TransactionQueueEvent(event);

    mTotalQueueDuration += (deqEvent.getTimestampMillis() - event.getTimestampMillis());

    if (mListeners.size() > 0) {
      Iterator it = mListeners.iterator();
      while (it.hasNext()) {
        ((TransactionQueueListener) it.next()).transactionDequeued(deqEvent);
      }
    }

    return deqEvent;
  }
コード例 #7
0
  public synchronized void removeUncaughtExceptionListener(UncaughtExceptionListener listener) {

    mExceptionListeners.remove(listener);
  }
コード例 #8
0
  public synchronized void addUncaughtExceptionListener(UncaughtExceptionListener listener) {

    mExceptionListeners.add(listener);
  }
コード例 #9
0
  public synchronized void removeTransactionQueueListener(TransactionQueueListener listener) {

    mListeners.remove(listener);
  }
コード例 #10
0
  public synchronized void addTransactionQueueListener(TransactionQueueListener listener) {

    mListeners.add(listener);
  }