new conn manager, part 1 - it compiles

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@498258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-01-21 09:07:57 +00:00
parent fcc94427da
commit b5a4cb74b0
4 changed files with 1783 additions and 0 deletions

View File

@ -0,0 +1,118 @@
/*
* $HeadURL$
* $Revision$
* $Date$
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.conn;
/**
* Management interface for {@link ManagedClientConnection client connections}.
*
* @author Michael Becke
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*
* <!-- empty lines to avoid svn diff problems -->
* @version $Revision$ $Date$
*
* @since 4.0
*/
public interface ClientConnectionManager {
/**
* Obtains a connection.
* This method will block until a connection becomes available
* or the connection manager is {@link #shutdown shut down}.
*
* @param route where the connection should point to
*
* @return a connection that can be used to communicate
* along the given route
*/
ManagedClientConnection getConnection(HostConfiguration route)
;
/**
* Obtains a connection within a given time.
* This method will block until a connection becomes available,
* the timeout expires, or the connection manager is
* {@link #shutdown shut down}.
*
* @param route where the connection should point to
* @param timeout the timeout in milliseconds
*
* @return a connection that can be used to communicate
* along the given route
*
* @throws ConnectionPoolTimeoutException
* in case of a timeout
*/
ManagedClientConnection getConnection(HostConfiguration route,
long timeout)
throws ConnectionPoolTimeoutException
;
/**
* Releases a connection for use by others.
*
* @param conn the connection to release
*/
void releaseConnection(ManagedClientConnection conn)
;
/**
* Closes idle connections in the pool.
* Open connections in the pool that have not been used for the
* timespan given by the timeout argument will be closed.
* Currently allocated connections are not subject to this method.
*
* @param idletime the idle time in milliseconds
*
* @since 3.0
*/
void closeIdleConnections(long idletime)
;
/**
* Shuts down this connection manager and releases allocated resources.
* This includes closing all connections, whether they are currently
* used or not.
*/
void shutdown()
;
} // interface ClientConnectionManager

View File

@ -0,0 +1,109 @@
/*
* $HeadURL$
* $Revision$
* $Date$
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.conn;
import java.io.IOException;
import java.net.Socket;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpHost;
import org.apache.http.HttpInetConnection;
import org.apache.http.protocol.HttpContext;
import org.apache.http.params.HttpParams;
/**
* A client-side connection with advanced connection logic.
* Instances are typically obtained from a connection manager.
*
* @author <a href="mailto:rolandw@apache.org">Roland Weber</a>
*
*
* <!-- empty lines to avoid svn diff problems -->
* @version $Revision$ $Date$
*
* @since 4.0
*/
public interface ManagedClientConnection
extends HttpClientConnection, HttpInetConnection {
/**
* Indicates whether this connection is secure.
* The return value is well-defined only while the connection is open.
* It may change even while the connection is open.
*
* @return <code>true</code> if this connection is secure,
* <code>false</code> otherwise
*/
boolean isSecure()
;
/**
* Opens this connection according to the given route.
*
* @param route the route along which to open. It will be opened
* to the proxy if present, or directly to the target.
* @param context the context for opening this connection
* @param params the parameters for opening this connection
*
* @throws IOException in case of a problem
*/
void open(HostConfiguration route, HttpContext context, HttpParams params)
throws IOException
;
/* *
* Indicates that a tunnel has been created.
*
* @param route the route along which the tunnel has been created
* @param params the parameters for updating the connection
*/
//@@@ tunnelCreated in the old implementation triggers layering
//@@@ of the TLS/SSL connection. This should be split in two.
/* *
* Releases this connection back to it's connection manager.
*
* @throws IllegalStateException
* if this connection is already released
* /
boolean release()
throws IllegalStateException
;
*/
} // interface ManagedClientConnection

View File

@ -0,0 +1,188 @@
/*
* $HeadURL$
* $Revision$
* $Date$
*
* ====================================================================
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.conn.impl;
import java.io.IOException;
import java.net.InetAddress;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpResponse;
import org.apache.http.params.HttpParams;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.ManagedClientConnection;
/**
* Abstract adapter from {@link OperatedClientConnection operated} to
* {@link ManagedClientConnection managed} client connections.
* Read and write methods are delegated to the wrapped connection.
* Operations affecting the connection state have to be implemented
* by derived classes. Operations for querying the connection state
* are delegated to the wrapped connection if there is one, or
* return a default value if there is none.
*
* @author <a href="mailto:rolandw@apache.org">Roland Weber</a>
*
*
* <!-- empty lines to avoid svn diff problems -->
* @version $Revision$ $Date$
*
* @since 4.0
*/
public abstract class AbstractClientConnectionAdapter
implements ManagedClientConnection {
/** The wrapped connection. */
protected OperatedClientConnection wrappedConnection;
/**
* Creates a new connection adapter.
*
* @param conn the connection to wrap, or <code>null</code>
*/
protected AbstractClientConnectionAdapter(OperatedClientConnection conn) {
wrappedConnection = conn;
} // <constructor>
/**
* Asserts that there is a wrapped connection to delegate to.
*
* @throws IllegalStateException if there is no wrapped connection
*/
protected final void assertWrappedConn() {
if (wrappedConnection == null) {
throw new IllegalStateException("No wrapped connection.");
}
}
// non-javadoc, see interface HttpConnection
public boolean isOpen() {
if (wrappedConnection == null)
return false;
return wrappedConnection.isOpen();
}
// non-javadoc, see interface HttpConnection
public boolean isStale() {
if (wrappedConnection == null)
return true;
return wrappedConnection.isStale();
}
// non-javadoc, see interface HttpClientConnection
public void flush()
throws IOException {
assertWrappedConn();
wrappedConnection.flush();
}
// non-javadoc, see interface HttpClientConnection
public boolean isResponseAvailable(int timeout)
throws IOException {
assertWrappedConn();
return wrappedConnection.isResponseAvailable(timeout);
}
// non-javadoc, see interface HttpClientConnection
public void receiveResponseEntity(HttpResponse response)
throws HttpException, IOException {
assertWrappedConn();
wrappedConnection.receiveResponseEntity(response);
}
// non-javadoc, see interface HttpClientConnection
public HttpResponse receiveResponseHeader(HttpParams params)
throws HttpException, IOException {
assertWrappedConn();
return wrappedConnection.receiveResponseHeader(params);
}
// non-javadoc, see interface HttpClientConnection
public void sendRequestEntity(HttpEntityEnclosingRequest request)
throws HttpException, IOException {
assertWrappedConn();
wrappedConnection.sendRequestEntity(request);
}
// non-javadoc, see interface HttpClientConnection
public void sendRequestHeader(HttpRequest request)
throws HttpException, IOException {
assertWrappedConn();
wrappedConnection.sendRequestHeader(request);
}
// non-javadoc, see interface HttpInetConnection
public InetAddress getLocalAddress() {
assertWrappedConn();
return wrappedConnection.getLocalAddress();
}
// non-javadoc, see interface HttpInetConnection
public InetAddress getRemoteAddress() {
assertWrappedConn();
return wrappedConnection.getRemoteAddress();
}
// non-javadoc, see interface ManagedClientConnection
public boolean isSecure() {
assertWrappedConn();
return wrappedConnection.isSecure();
}
} // class AbstractClientConnectionAdapter

File diff suppressed because it is too large Load Diff