001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.nio;
029
030import org.apache.http.HttpConnection;
031import org.apache.http.HttpRequest;
032import org.apache.http.HttpResponse;
033import org.apache.http.protocol.HttpContext;
034
035/**
036 * Abstract non-blocking HTTP connection interface. Each connection contains an
037 * HTTP execution context, which can be used to maintain a processing state,
038 * as well as the actual {@link HttpRequest} and {@link HttpResponse} that are
039 * being transmitted over this connection. Both the request and
040 * the response objects can be {@code null} if there is no incoming or
041 * outgoing message currently being transferred.
042 * <p>
043 * Please note non-blocking HTTP connections are stateful and not thread safe.
044 * Input / output operations on non-blocking HTTP connections should be
045 * restricted to the dispatch events triggered by the I/O event dispatch thread.
046 * However, the {@link IOControl} interface is fully threading safe and can be
047 * manipulated from any thread.
048 *
049 * @since 4.0
050 */
051public interface NHttpConnection extends HttpConnection, IOControl {
052
053    public static final int ACTIVE      = 0;
054    public static final int CLOSING     = 1;
055    public static final int CLOSED      = 2;
056
057    /**
058     * Returns status of the connection:
059     * <p>
060     * {@link #ACTIVE}: connection is active.
061     * <p>
062     * {@link #CLOSING}: connection is being closed.
063     * <p>
064     * {@link #CLOSED}: connection has been closed.
065     *
066     * @return connection status.
067     */
068    int getStatus();
069
070    /**
071     * Returns the current HTTP request if one is being received / transmitted.
072     * Otherwise returns {@code null}.
073     *
074     * @return HTTP request, if available, {@code null} otherwise.
075     */
076    HttpRequest getHttpRequest();
077
078    /**
079     * Returns the current HTTP response if one is being received / transmitted.
080     * Otherwise returns {@code null}.
081     *
082     * @return HTTP response, if available, {@code null} otherwise.
083     */
084    HttpResponse getHttpResponse();
085
086    /**
087     * Returns an HTTP execution context associated with this connection.
088     * @return HTTP context
089     */
090    HttpContext getContext();
091
092}