// Path: src/main/java/com/biasedbit/hotpotato/client/connection/HttpConnection.java
// public interface HttpConnection extends ChannelHandler {
// 
//     /**
//      * Shut down the connection, cancelling all requests executing meanwhile.
//      * <p/>
//      * After a connection is shut down, no more requests will be accepted.
//      */
//     void terminate();
// 
//     /**
//      * Returns the unique identifier of this connection.
//      *
//      * @return An identifier of the connection.
//      */
//     String getId();
// 
//     /**
//      * Returns the host address to which this connection is connected to.
//      *
//      * @return The host address to which this connection is currently connected to.
//      */
//     String getHost();
// 
//     /**
//      * Returns the port to which this connection is connected to.
//      *
//      * @return The port of to which this connection is connected to.
//      */
//     int getPort();
// 
//     /**
//      * Returns whether this connection is available to process a request. Connections that execute HTTP 1.0 requests
//      * will <strong>never</strong> return true after the request has been approved for processing as the socket will
//      * be closed by the server.
//      *
//      * @return true if this connection is connected and ready to execute a request
//      */
//     boolean isAvailable();
// 
//     /**
//      * Execute a given request context in this connection. All calls to this method should first test whether this
//      * connection is available or not by calling {@link #isAvailable()} first. If this method is called while
//      * {@link #isAvailable()} would return {@code false}, then implementations will instantly cause a failure on the
//      * request with the reason {@link com.biasedbit.hotpotato.request.HttpRequestFuture#EXECUTION_REJECTED} and return
//      * {@code true}, meaning the request was consumed (and failed).
//      * <p/>
//      * The exception to the above rule is when the request is submitted and the connection goes down meanwhile. In this
//      * case, the request <strong>will not</strong> be marked as failed and this method will return {@code false} so that
//      * the caller may retry the same request in another connection.
//      * <p/>
//      * You should always, <strong>always</strong> test first with {@link #isAvailable()}.
//      * <p/>
//      * This is a non-blocking call.
//      *
//      * @param context Request execution context.
//      *
//      * @return {@code true} if the request was accepted, {@code false} otherwise. If a request is accepted, the
//      * {@code HttpConnection} becomes responsible for calling {@link
//      * com.biasedbit.hotpotato.request.HttpRequestFuture#setFailure(Throwable) setFailure()} or {@link
//      * com.biasedbit.hotpotato.request.HttpRequestFuture#setSuccess(Object,
//      * org.jboss.netty.handler.codec.http.HttpResponse) setSuccess()} on it.
//      */
//     boolean execute(HttpRequestContext context);
// }
// 
// Path: src/main/java/com/biasedbit/hotpotato/client/connection/HttpConnectionListener.java
// public interface HttpConnectionListener {
// 
//     /**
//      * Connection opened event, called by the {@link HttpConnection} when a requested connection establishes.
//      *
//      * @param connection Connection that just established.
//      */
//     void connectionOpened(HttpConnection connection);
// 
//     /**
//      * Connection terminated event, called by the {@link HttpConnection} when an active connection disconnects.
//      *
//      * This is the event that {@link HttpConnection}s that support submission of multiple parallel requests call to
//      * signal disconnection, since some of the requests may still be executed in another connection (e.g. a pipelining
//      * connection that goes down after a couple of requests but still has some more idempotent requests queued).
//      *
//      * @param connection Connection that was disconnected.
//      * @param retryRequests List of pending submitted requests that should be retried in a new connection, if possible.
//      */
//     void connectionTerminated(HttpConnection connection, Collection<HttpRequestContext> retryRequests);
// 
//     /**
//      * Connection terminated event, called by the {@link HttpConnection} when an active connection disconnects.
//      *
//      * This is the event that {@link HttpConnection}s that only support a single request at a time use to signal
//      * disconnection. It can also be used by {@link HttpConnection}s that support submission of multiple parallel
//      * requests (e.g. a pipelining connection) when they disconnect and have no requests that should be retried (i.e.
//      * all pipelined requests executed successfully).
//      *
//      * @param connection Connection that was disconnected.
//      */
//     void connectionTerminated(HttpConnection connection);
// 
//     /**
//      * Connection failed event, called by the {@link HttpConnection} when a connection attempt fails.
//      *
//      * @param connection Connection that failed.
//      */
//     void connectionFailed(HttpConnection connection);
// 
//     /**
//      * Request complete event, called by the {@link HttpConnection} when a response to a request allocated to it is
//      * either received or fails for some reason.
//      *
//      * @param connection Connection in which the event finished.
//      * @param context Request context containing the request that has completed.
//      */
//     void requestFinished(HttpConnection connection, HttpRequestContext context);
// }
// 
// Path: src/main/java/com/biasedbit/hotpotato/client/timeout/TimeoutManager.java
// public interface TimeoutManager {
// 
//     boolean init();
// 
//     void terminate();
// 
//     /**
//      * Manage the timeout for the provided context.
//      *
//      * @param context The request context to monitor. Timeout value is extracted from {@link
//      *                com.biasedbit.hotpotato.client.HttpRequestContext#getTimeout()}.
//      */
//     void manageRequestTimeout(HttpRequestContext context);
// }


import com.biasedbit.hotpotato.client.connection.HttpConnection;
import com.biasedbit.hotpotato.client.connection.HttpConnectionListener;
import com.biasedbit.hotpotato.client.timeout.TimeoutManager;
import java.util.concurrent.Executor;
/*
 * Copyright 2010 Bruno de Carvalho
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.biasedbit.hotpotato.client.connection.factory;



/**
 * @author <a href="http://bruno.biasedbit.com/">Bruno de Carvalho</a>
 */
public interface HttpConnectionFactory {

    HttpConnection createConnection(String id, String host, int port, HttpConnectionListener listener,
// Path: src/main/java/com/biasedbit/hotpotato/client/connection/HttpConnection.java
// public interface HttpConnection extends ChannelHandler {
// 
//     /**
//      * Shut down the connection, cancelling all requests executing meanwhile.
//      * <p/>
//      * After a connection is shut down, no more requests will be accepted.
//      */
//     void terminate();
// 
//     /**
//      * Returns the unique identifier of this connection.
//      *
//      * @return An identifier of the connection.
//      */
//     String getId();
// 
//     /**
//      * Returns the host address to which this connection is connected to.
//      *
//      * @return The host address to which this connection is currently connected to.
//      */
//     String getHost();
// 
//     /**
//      * Returns the port to which this connection is connected to.
//      *
//      * @return The port of to which this connection is connected to.
//      */
//     int getPort();
// 
//     /**
//      * Returns whether this connection is available to process a request. Connections that execute HTTP 1.0 requests
//      * will <strong>never</strong> return true after the request has been approved for processing as the socket will
//      * be closed by the server.
//      *
//      * @return true if this connection is connected and ready to execute a request
//      */
//     boolean isAvailable();
// 
//     /**
//      * Execute a given request context in this connection. All calls to this method should first test whether this
//      * connection is available or not by calling {@link #isAvailable()} first. If this method is called while
//      * {@link #isAvailable()} would return {@code false}, then implementations will instantly cause a failure on the
//      * request with the reason {@link com.biasedbit.hotpotato.request.HttpRequestFuture#EXECUTION_REJECTED} and return
//      * {@code true}, meaning the request was consumed (and failed).
//      * <p/>
//      * The exception to the above rule is when the request is submitted and the connection goes down meanwhile. In this
//      * case, the request <strong>will not</strong> be marked as failed and this method will return {@code false} so that
//      * the caller may retry the same request in another connection.
//      * <p/>
//      * You should always, <strong>always</strong> test first with {@link #isAvailable()}.
//      * <p/>
//      * This is a non-blocking call.
//      *
//      * @param context Request execution context.
//      *
//      * @return {@code true} if the request was accepted, {@code false} otherwise. If a request is accepted, the
//      * {@code HttpConnection} becomes responsible for calling {@link
//      * com.biasedbit.hotpotato.request.HttpRequestFuture#setFailure(Throwable) setFailure()} or {@link
//      * com.biasedbit.hotpotato.request.HttpRequestFuture#setSuccess(Object,
//      * org.jboss.netty.handler.codec.http.HttpResponse) setSuccess()} on it.
//      */
//     boolean execute(HttpRequestContext context);
// }
// 
// Path: src/main/java/com/biasedbit/hotpotato/client/connection/HttpConnectionListener.java
// public interface HttpConnectionListener {
// 
//     /**
//      * Connection opened event, called by the {@link HttpConnection} when a requested connection establishes.
//      *
//      * @param connection Connection that just established.
//      */
//     void connectionOpened(HttpConnection connection);
// 
//     /**
//      * Connection terminated event, called by the {@link HttpConnection} when an active connection disconnects.
//      *
//      * This is the event that {@link HttpConnection}s that support submission of multiple parallel requests call to
//      * signal disconnection, since some of the requests may still be executed in another connection (e.g. a pipelining
//      * connection that goes down after a couple of requests but still has some more idempotent requests queued).
//      *
//      * @param connection Connection that was disconnected.
//      * @param retryRequests List of pending submitted requests that should be retried in a new connection, if possible.
//      */
//     void connectionTerminated(HttpConnection connection, Collection<HttpRequestContext> retryRequests);
// 
//     /**
//      * Connection terminated event, called by the {@link HttpConnection} when an active connection disconnects.
//      *
//      * This is the event that {@link HttpConnection}s that only support a single request at a time use to signal
//      * disconnection. It can also be used by {@link HttpConnection}s that support submission of multiple parallel
//      * requests (e.g. a pipelining connection) when they disconnect and have no requests that should be retried (i.e.
//      * all pipelined requests executed successfully).
//      *
//      * @param connection Connection that was disconnected.
//      */
//     void connectionTerminated(HttpConnection connection);
// 
//     /**
//      * Connection failed event, called by the {@link HttpConnection} when a connection attempt fails.
//      *
//      * @param connection Connection that failed.
//      */
//     void connectionFailed(HttpConnection connection);
// 
//     /**
//      * Request complete event, called by the {@link HttpConnection} when a response to a request allocated to it is
//      * either received or fails for some reason.
//      *
//      * @param connection Connection in which the event finished.
//      * @param context Request context containing the request that has completed.
//      */
//     void requestFinished(HttpConnection connection, HttpRequestContext context);
// }
// 
// Path: src/main/java/com/biasedbit/hotpotato/client/timeout/TimeoutManager.java
// public interface TimeoutManager {
// 
//     boolean init();
// 
//     void terminate();
// 
//     /**
//      * Manage the timeout for the provided context.
//      *
//      * @param context The request context to monitor. Timeout value is extracted from {@link
//      *                com.biasedbit.hotpotato.client.HttpRequestContext#getTimeout()}.
//      */
//     void manageRequestTimeout(HttpRequestContext context);
// }


// Path: src/main/java/com/biasedbit/hotpotato/client/connection/factory/HttpConnectionFactory.java
import com.biasedbit.hotpotato.client.connection.HttpConnection;
import com.biasedbit.hotpotato.client.connection.HttpConnectionListener;
import com.biasedbit.hotpotato.client.timeout.TimeoutManager;
import java.util.concurrent.Executor;

/*
 * Copyright 2010 Bruno de Carvalho
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.biasedbit.hotpotato.client.connection.factory;



/**
 * @author <a href="http://bruno.biasedbit.com/">Bruno de Carvalho</a>
 */
public interface HttpConnectionFactory {

    HttpConnection createConnection(String id, String host, int port, HttpConnectionListener listener,
                                    TimeoutManager manager);