// Path: src/main/java/com/biasedbit/hotpotato/client/HttpRequestContext.java
// public class HttpRequestContext<T> {
// 
//     // internal vars --------------------------------------------------------------------------------------------------
// 
//     private final String host;
//     private final int port;
//     private final int timeout;
//     private final HttpRequest request;
//     private final HttpResponseProcessor<T> processor;
//     private final HttpRequestFuture<T> future;
// 
//     // constructors ---------------------------------------------------------------------------------------------------
// 
//     public HttpRequestContext(String host, int port, int timeout, HttpRequest request,
//                               HttpResponseProcessor<T> processor, HttpRequestFuture<T> future) {
//         if (host == null) {
//             throw new IllegalArgumentException("Host cannot be null");
//         }
//         if ((port <= 0) || (port > 65536)) {
//             throw new IllegalArgumentException("Invalid port: " + port);
//         }
//         if (request == null) {
//             throw new IllegalArgumentException("HttpRequest cannot be null");
//         }
//         if (processor == null) {
//             throw new IllegalArgumentException("HttpResponseProcessor cannot be null");
//         }
//         if (future == null) {
//             throw new IllegalArgumentException("HttpRequestFuture cannot be null");
//         }
// 
//         this.timeout = timeout < 0 ? 0 : timeout;
//         this.host = host;
//         this.port = port;
//         this.request = request;
//         this.processor = processor;
//         this.future = future;
//     }
// 
//     public HttpRequestContext(String host, int timeout, HttpRequest request, HttpResponseProcessor<T> processor,
//                               HttpRequestFuture<T> future) {
//         this(host, 80, timeout, request, processor, future);
//     }
// 
//     // public methods -------------------------------------------------------------------------------------------------
// 
//     /**
//      * Determines (based on request method) if a request is idempotent or not, based on recommendations of the RFC.
//      *
//      * Idempotent requests: GET, HEAD, PUT, DELETE, OPTIONS, TRACE
//      * Non-idempotent requests: POST, PATCH, CONNECT (not sure about this last one, couldn't find any info on it...)
//      *
//      * @return true if request is idempotent, false otherwise.
//      */
//     public boolean isIdempotent() {
//         return !(this.request.getMethod().equals(HttpMethod.POST) ||
//                  this.request.getMethod().equals(HttpMethod.PATCH) ||
//                  this.request.getMethod().equals(HttpMethod.CONNECT));
//     }
// 
//     // getters & setters ----------------------------------------------------------------------------------------------
// 
//     public String getHost() {
//         return host;
//     }
// 
//     public int getPort() {
//         return port;
//     }
// 
//     public int getTimeout() {
//         return timeout;
//     }
// 
//     public HttpRequest getRequest() {
//         return request;
//     }
// 
//     public HttpResponseProcessor<T> getProcessor() {
//         return processor;
//     }
// 
//     public HttpRequestFuture<T> getFuture() {
//         return future;
//     }
// 
//     // low level overrides --------------------------------------------------------------------------------------------
// 
//     @Override
//     public String toString() {
//         return new StringBuilder()
//                 .append(this.request.getProtocolVersion()).append(' ')
//                 .append(this.request.getMethod()).append(' ')
//                 .append(this.request.getUri()).append(" (")
//                 .append(this.host).append(':')
//                 .append(this.port).append(')').append("@").append(Integer.toHexString(this.hashCode())).toString();
//     }
// }


import com.biasedbit.hotpotato.client.HttpRequestContext;
/*
 * 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.timeout;


/**
 * Facility to manage timeouts for requests.
 *
 * @author <a href="http://bruno.biasedbit.com/">Bruno de Carvalho</a>
 */
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()}.
     */
// Path: src/main/java/com/biasedbit/hotpotato/client/HttpRequestContext.java
// public class HttpRequestContext<T> {
// 
//     // internal vars --------------------------------------------------------------------------------------------------
// 
//     private final String host;
//     private final int port;
//     private final int timeout;
//     private final HttpRequest request;
//     private final HttpResponseProcessor<T> processor;
//     private final HttpRequestFuture<T> future;
// 
//     // constructors ---------------------------------------------------------------------------------------------------
// 
//     public HttpRequestContext(String host, int port, int timeout, HttpRequest request,
//                               HttpResponseProcessor<T> processor, HttpRequestFuture<T> future) {
//         if (host == null) {
//             throw new IllegalArgumentException("Host cannot be null");
//         }
//         if ((port <= 0) || (port > 65536)) {
//             throw new IllegalArgumentException("Invalid port: " + port);
//         }
//         if (request == null) {
//             throw new IllegalArgumentException("HttpRequest cannot be null");
//         }
//         if (processor == null) {
//             throw new IllegalArgumentException("HttpResponseProcessor cannot be null");
//         }
//         if (future == null) {
//             throw new IllegalArgumentException("HttpRequestFuture cannot be null");
//         }
// 
//         this.timeout = timeout < 0 ? 0 : timeout;
//         this.host = host;
//         this.port = port;
//         this.request = request;
//         this.processor = processor;
//         this.future = future;
//     }
// 
//     public HttpRequestContext(String host, int timeout, HttpRequest request, HttpResponseProcessor<T> processor,
//                               HttpRequestFuture<T> future) {
//         this(host, 80, timeout, request, processor, future);
//     }
// 
//     // public methods -------------------------------------------------------------------------------------------------
// 
//     /**
//      * Determines (based on request method) if a request is idempotent or not, based on recommendations of the RFC.
//      *
//      * Idempotent requests: GET, HEAD, PUT, DELETE, OPTIONS, TRACE
//      * Non-idempotent requests: POST, PATCH, CONNECT (not sure about this last one, couldn't find any info on it...)
//      *
//      * @return true if request is idempotent, false otherwise.
//      */
//     public boolean isIdempotent() {
//         return !(this.request.getMethod().equals(HttpMethod.POST) ||
//                  this.request.getMethod().equals(HttpMethod.PATCH) ||
//                  this.request.getMethod().equals(HttpMethod.CONNECT));
//     }
// 
//     // getters & setters ----------------------------------------------------------------------------------------------
// 
//     public String getHost() {
//         return host;
//     }
// 
//     public int getPort() {
//         return port;
//     }
// 
//     public int getTimeout() {
//         return timeout;
//     }
// 
//     public HttpRequest getRequest() {
//         return request;
//     }
// 
//     public HttpResponseProcessor<T> getProcessor() {
//         return processor;
//     }
// 
//     public HttpRequestFuture<T> getFuture() {
//         return future;
//     }
// 
//     // low level overrides --------------------------------------------------------------------------------------------
// 
//     @Override
//     public String toString() {
//         return new StringBuilder()
//                 .append(this.request.getProtocolVersion()).append(' ')
//                 .append(this.request.getMethod()).append(' ')
//                 .append(this.request.getUri()).append(" (")
//                 .append(this.host).append(':')
//                 .append(this.port).append(')').append("@").append(Integer.toHexString(this.hashCode())).toString();
//     }
// }


// Path: src/main/java/com/biasedbit/hotpotato/client/timeout/TimeoutManager.java
import com.biasedbit.hotpotato.client.HttpRequestContext;

/*
 * 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.timeout;


/**
 * Facility to manage timeouts for requests.
 *
 * @author <a href="http://bruno.biasedbit.com/">Bruno de Carvalho</a>
 */
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);