예제 #1
0
  /**
   * Notify all ConnectionListeners. Service implementations are expected to use this method to
   * broadcast connection events.
   *
   * <p>The provided default implementation queues the event into an internal event queue. An event
   * dispatcher thread dequeues events from the queue and dispatches them to the registered
   * ConnectionListeners. Note that the event dispatching occurs in a separate thread, thus avoiding
   * potential deadlock problems.
   *
   * @param type the ConnectionEvent type
   */
  protected void notifyConnectionListeners(int type) {
    /*
     * Don't bother queuing an event if there's no listeners.
     * Yes, listeners could be removed after checking, which
     * just makes this an expensive no-op.
     */
    if (connectionListeners.size() > 0) {
      ConnectionEvent e = new ConnectionEvent(this, type);
      queueEvent(e, connectionListeners);
    }

    /* Fix for broken JDK1.1.x Garbage collector :
     *  The 'conservative' GC in JDK1.1.x occasionally fails to
     *  garbage-collect Threads which are in the wait state.
     *  This would result in thread (and consequently memory) leaks.
     *
     * We attempt to fix this by sending a 'terminator' event
     * to the queue, after we've sent the CLOSED event. The
     * terminator event causes the event-dispatching thread to
     * self destruct.
     */
    if (type == ConnectionEvent.CLOSED) q.terminateQueue();
  }
예제 #2
0
 /** Stop the event dispatcher thread so the queue can be garbage collected. */
 protected void finalize() throws Throwable {
   super.finalize();
   q.terminateQueue();
 }