michael@0: /*
michael@0: * ====================================================================
michael@0: * Licensed to the Apache Software Foundation (ASF) under one
michael@0: * or more contributor license agreements. See the NOTICE file
michael@0: * distributed with this work for additional information
michael@0: * regarding copyright ownership. The ASF licenses this file
michael@0: * to you under the Apache License, Version 2.0 (the
michael@0: * "License"); you may not use this file except in compliance
michael@0: * with the License. You may obtain a copy of the License at
michael@0: *
michael@0: * http://www.apache.org/licenses/LICENSE-2.0
michael@0: *
michael@0: * Unless required by applicable law or agreed to in writing,
michael@0: * software distributed under the License is distributed on an
michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0: * KIND, either express or implied. See the License for the
michael@0: * specific language governing permissions and limitations
michael@0: * under the License.
michael@0: * ====================================================================
michael@0: *
michael@0: * This software consists of voluntary contributions made by many
michael@0: * individuals on behalf of the Apache Software Foundation. For more
michael@0: * information on the Apache Software Foundation, please see
michael@0: * .
michael@0: *
michael@0: */
michael@0:
michael@0: package ch.boye.httpclientandroidlib;
michael@0:
michael@0: import java.io.IOException;
michael@0:
michael@0: /**
michael@0: * A generic HTTP connection, useful on client and server side.
michael@0: *
michael@0: * @since 4.0
michael@0: */
michael@0: public interface HttpConnection {
michael@0:
michael@0: /**
michael@0: * Closes this connection gracefully.
michael@0: * This method will attempt to flush the internal output
michael@0: * buffer prior to closing the underlying socket.
michael@0: * This method MUST NOT be called from a different thread to force
michael@0: * shutdown of the connection. Use {@link #shutdown shutdown} instead.
michael@0: */
michael@0: public void close() throws IOException;
michael@0:
michael@0: /**
michael@0: * Checks if this connection is open.
michael@0: * @return true if it is open, false if it is closed.
michael@0: */
michael@0: public boolean isOpen();
michael@0:
michael@0: /**
michael@0: * Checks whether this connection has gone down.
michael@0: * Network connections may get closed during some time of inactivity
michael@0: * for several reasons. The next time a read is attempted on such a
michael@0: * connection it will throw an IOException.
michael@0: * This method tries to alleviate this inconvenience by trying to
michael@0: * find out if a connection is still usable. Implementations may do
michael@0: * that by attempting a read with a very small timeout. Thus this
michael@0: * method may block for a small amount of time before returning a result.
michael@0: * It is therefore an expensive operation.
michael@0: *
michael@0: * @return true
if attempts to use this connection are
michael@0: * likely to succeed, or false
if they are likely
michael@0: * to fail and this connection should be closed
michael@0: */
michael@0: public boolean isStale();
michael@0:
michael@0: /**
michael@0: * Sets the socket timeout value.
michael@0: *
michael@0: * @param timeout timeout value in milliseconds
michael@0: */
michael@0: void setSocketTimeout(int timeout);
michael@0:
michael@0: /**
michael@0: * Returns the socket timeout value.
michael@0: *
michael@0: * @return positive value in milliseconds if a timeout is set,
michael@0: * 0
if timeout is disabled or -1
if
michael@0: * timeout is undefined.
michael@0: */
michael@0: int getSocketTimeout();
michael@0:
michael@0: /**
michael@0: * Force-closes this connection.
michael@0: * This is the only method of a connection which may be called
michael@0: * from a different thread to terminate the connection.
michael@0: * This method will not attempt to flush the transmitter's
michael@0: * internal buffer prior to closing the underlying socket.
michael@0: */
michael@0: public void shutdown() throws IOException;
michael@0:
michael@0: /**
michael@0: * Returns a collection of connection metrics.
michael@0: *
michael@0: * @return HttpConnectionMetrics
michael@0: */
michael@0: HttpConnectionMetrics getMetrics();
michael@0:
michael@0: }