Example usage for org.apache.http.impl.conn.tsccm WaitingThread wakeup

List of usage examples for org.apache.http.impl.conn.tsccm WaitingThread wakeup

Introduction

In this page you can find the example usage for org.apache.http.impl.conn.tsccm WaitingThread wakeup.

Prototype

public void wakeup() 

Source Link

Document

Wakes up the waiting thread.

Usage

From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java

/**
 * Notifies a waiting thread that a connection is available.
 * This will wake a thread waiting in the specific route pool,
 * if there is one.//from   w  w  w .  jav a  2 s.co m
 * Otherwise, a thread in the connection pool will be notified.
 *
 * @param rospl     the pool in which to notify, or <code>null</code>
 */
protected void notifyWaitingThread(final RouteSpecificPool rospl) {

    //@@@ while this strategy provides for best connection re-use,
    //@@@ is it fair? only do this if the connection is open?
    // Find the thread we are going to notify. We want to ensure that
    // each waiting thread is only interrupted once, so we will remove
    // it from all wait queues before interrupting.
    WaitingThread waitingThread = null;

    poolLock.lock();
    try {

        if ((rospl != null) && rospl.hasThread()) {
            if (log.isDebugEnabled()) {
                log.debug("Notifying thread waiting on pool" + " [" + rospl.getRoute() + "]");
            }
            waitingThread = rospl.nextThread();
        } else if (!waitingThreads.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("Notifying thread waiting on any pool");
            }
            waitingThread = waitingThreads.remove();
        } else if (log.isDebugEnabled()) {
            log.debug("Notifying no-one, there are no waiting threads");
        }

        if (waitingThread != null) {
            waitingThread.wakeup();
        }

    } finally {
        poolLock.unlock();
    }
}

From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java

@Override
public void shutdown() {
    poolLock.lock();/* w w  w .  j  a  v a2 s  . c om*/
    try {
        if (shutdown) {
            return;
        }
        shutdown = true;

        // close all connections that are issued to an application
        final Iterator<BasicPoolEntry> iter1 = leasedConnections.iterator();
        while (iter1.hasNext()) {
            final BasicPoolEntry entry = iter1.next();
            iter1.remove();
            closeConnection(entry);
        }

        // close all free connections
        final Iterator<BasicPoolEntry> iter2 = freeConnections.iterator();
        while (iter2.hasNext()) {
            final BasicPoolEntry entry = iter2.next();
            iter2.remove();

            if (log.isDebugEnabled()) {
                log.debug(
                        "Closing connection" + " [" + entry.getPlannedRoute() + "][" + entry.getState() + "]");
            }
            closeConnection(entry);
        }

        // wake up all waiting threads
        final Iterator<WaitingThread> iwth = waitingThreads.iterator();
        while (iwth.hasNext()) {
            final WaitingThread waiter = iwth.next();
            iwth.remove();
            waiter.wakeup();
        }

        routeToPool.clear();

    } finally {
        poolLock.unlock();
    }
}