Package sunlabs.brazil.util.http
Interface HttpSocketPool
-
public interface HttpSocketPoolThis interface represents a cache of idle sockets. Once a request has been handled, the now-idle socket can be remembered and reused later in case another HTTP request is made to the same remote host. Currently, the only instance of this interface is used by theHttpRequestclass.- Version:
- 2.2
- Author:
- Colin Stevens (colin.stevens@sun.com)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose(HttpSocket hs, boolean reuse)Releases anHttpSocketto this pool when it is not in use any more.HttpSocketget(java.lang.String host, int port, boolean reuse)Returns anHttpSocketthat can be used to communicate with the specified port on the named host.
-
-
-
Method Detail
-
get
HttpSocket get(java.lang.String host, int port, boolean reuse) throws java.io.IOException
Returns anHttpSocketthat can be used to communicate with the specified port on the named host.It is this method's responsibility to to fill in all the public member variables of the
HttpSocketbefore returning.For each call to this method, there should eventually be a call to
closewhen theHttpSocketisn't needed anymore.- Parameters:
host- The host name.port- The port number.reuse-trueto request that this pool attempt to find and reuse an existing idle connection,falseto request that this pool establish a new connection to the named host.- Returns:
- The
HttpSocket. - Throws:
java.io.IOException- if there is a problem connecting to the specified port on the named host. TheIOExceptions (and subclasses) that might be thrown depend upon how the socket connection is established. See the socket documentation for further details. Some subclasses that might be thrown are as follows:java.io.UnknownHostException- if the host name cannot be resolved.java.io.ConnectionException- if the named host is not listening on the specified port.java.io.InterruptedIOException- if the connection times out or this thread is interrupted byThread.interrupt.
-
close
void close(HttpSocket hs, boolean reuse)
Releases anHttpSocketto this pool when it is not in use any more.It is this method's responsibility to release resources used by the
HttpSocket, such as closing the underlying socket.After calling this method, the user should not refer to the specified
HttpSocketany more.- Parameters:
hs- TheHttpSocketto release.reuse-trueif the specifiedHttpSocketshould be put back into the idle pool,falseif it should be released immediately.
-
-