1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.http.nio; 29 30 import org.apache.http.HttpConnection; 31 import org.apache.http.HttpRequest; 32 import org.apache.http.HttpResponse; 33 import org.apache.http.protocol.HttpContext; 34 35 /** 36 * Abstract non-blocking HTTP connection interface. Each connection contains an 37 * HTTP execution context, which can be used to maintain a processing state, 38 * as well as the actual {@link HttpRequest} and {@link HttpResponse} that are 39 * being transmitted over this connection. Both the request and 40 * the response objects can be {@code null} if there is no incoming or 41 * outgoing message currently being transferred. 42 * <p> 43 * Please note non-blocking HTTP connections are stateful and not thread safe. 44 * Input / output operations on non-blocking HTTP connections should be 45 * restricted to the dispatch events triggered by the I/O event dispatch thread. 46 * However, the {@link IOControl} interface is fully threading safe and can be 47 * manipulated from any thread. 48 * 49 * @since 4.0 50 */ 51 public interface NHttpConnection extends HttpConnection, IOControl { 52 53 int ACTIVE = 0; 54 int CLOSING = 1; 55 int CLOSED = 2; 56 57 /** 58 * Returns status of the connection: 59 * <p> 60 * {@link #ACTIVE}: connection is active. 61 * <p> 62 * {@link #CLOSING}: connection is being closed. 63 * <p> 64 * {@link #CLOSED}: connection has been closed. 65 * 66 * @return connection status. 67 */ 68 int getStatus(); 69 70 /** 71 * Returns the current HTTP request if one is being received / transmitted. 72 * Otherwise returns {@code null}. 73 * 74 * @return HTTP request, if available, {@code null} otherwise. 75 */ 76 HttpRequest getHttpRequest(); 77 78 /** 79 * Returns the current HTTP response if one is being received / transmitted. 80 * Otherwise returns {@code null}. 81 * 82 * @return HTTP response, if available, {@code null} otherwise. 83 */ 84 HttpResponse getHttpResponse(); 85 86 /** 87 * Returns an HTTP execution context associated with this connection. 88 * @return HTTP context 89 */ 90 HttpContext getContext(); 91 92 }