com.ning.http.client.providers.netty
Class NettyConnectionsPool

java.lang.Object
  extended by com.ning.http.client.providers.netty.NettyConnectionsPool
All Implemented Interfaces:
ConnectionsPool<String,org.jboss.netty.channel.Channel>

public class NettyConnectionsPool
extends Object
implements ConnectionsPool<String,org.jboss.netty.channel.Channel>

A simple implementation of ConnectionsPool based on a ConcurrentHashMap


Constructor Summary
NettyConnectionsPool(AsyncHttpClientConfig config)
           
 
Method Summary
 boolean addConnection(String uri, org.jboss.netty.channel.Channel connection)
          Add a connection tpo the pool
 boolean canCacheConnection()
          Return true if a connection can be cached.
 void destroy()
          Destroy all connections that has been cached by this instance.
 org.jboss.netty.channel.Channel getConnection(String uri)
          Return the connection associated with the uri
 boolean removeAllConnections(org.jboss.netty.channel.Channel connection)
          Remove all connections from the cache.
 org.jboss.netty.channel.Channel removeConnection(String uri)
          Remove the connection associated with the uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NettyConnectionsPool

public NettyConnectionsPool(AsyncHttpClientConfig config)
Method Detail

addConnection

public boolean addConnection(String uri,
                             org.jboss.netty.channel.Channel connection)
Add a connection tpo the pool

Specified by:
addConnection in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>
Parameters:
uri - a uri used to retrieve the cached connection
connection - an I/O connection
Returns:
true if added.

getConnection

public org.jboss.netty.channel.Channel getConnection(String uri)
Return the connection associated with the uri

Specified by:
getConnection in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>
Parameters:
uri - the uri used when invoking addConnection
Returns:
the connection associated with the uri

removeConnection

public org.jboss.netty.channel.Channel removeConnection(String uri)
Remove the connection associated with the uri.

Specified by:
removeConnection in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>
Parameters:
uri - the uri used when invoking addConnection
Returns:
the connection associated with the uri

removeAllConnections

public boolean removeAllConnections(org.jboss.netty.channel.Channel connection)
Remove all connections from the cache. A connection might have been associated with several uri.

Specified by:
removeAllConnections in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>
Parameters:
connection - a connection
Returns:
the true if the connection has been removed

canCacheConnection

public boolean canCacheConnection()
Return true if a connection can be cached. A implementation can decide based on some rules to allow caching Calling this method is equivalent of checking the returned value of ConnectionsPool.addConnection(Object, Object)

Specified by:
canCacheConnection in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>
Returns:
true if a connection can be cached.

destroy

public void destroy()
Destroy all connections that has been cached by this instance.

Specified by:
destroy in interface ConnectionsPool<String,org.jboss.netty.channel.Channel>


Copyright © 2010. All Rights Reserved.