You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/01/04 07:33:17 UTC
svn commit: r492424 - in
/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn:
UnmanagedClientConnection.java impl/DefaultClientConnection.java
impl/DefaultSocketConnectionOperator.java
Author: rolandw
Date: Wed Jan 3 22:33:16 2007
New Revision: 492424
URL: http://svn.apache.org/viewvc?view=rev&rev=492424
Log:
new connection interfaces, step 3 - HTTPCLIENT-475
Modified:
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/UnmanagedClientConnection.java
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultClientConnection.java
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultSocketConnectionOperator.java
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/UnmanagedClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/UnmanagedClientConnection.java?view=diff&rev=492424&r1=492423&r2=492424
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/UnmanagedClientConnection.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/UnmanagedClientConnection.java Wed Jan 3 22:33:16 2007
@@ -89,6 +89,37 @@
/**
+ * Prepares opening this connection.
+ * Opening can be prepared only while the connection is closed.
+ * This is an optional step, you can call {@link #open open}
+ * without preparing.
+ * <br/>
+ * By calling this method, you provide the connection with
+ * the unconnected socket that will be connected in order
+ * to call {@link #open open}. This allows the connection to
+ * close that socket if
+ * {@link org.apache.http.HttpConnection#shutdown shutdown}
+ * is called before it is open. Closing the unconnected socket
+ * will interrupt a thread that is blocked on the connect.
+ * Otherwise, that thread will either time out on the connect,
+ * or it returns successfully and then opens this connection
+ * which was just shut down.
+ * <br/>
+ * <b>Note:</b>
+ * The result of {@link #getSocket getSocket} is defined
+ * only for open connections. You MUST NOT rely on that
+ * method to return the unconnected socket after preparing.
+ *
+ * @param sock the unconnected socket which is about to
+ * be connected in order to call {@link #open open}.
+ * <code>null</code> can be passed to undo a
+ * previous call.
+ */
+ void prepare(Socket sock)
+ ;
+
+
+ /**
* Opens this connection.
* A connection can be openend only while it is closed.
* To modify a connection while it is open, use {@link #update update}.
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultClientConnection.java?view=diff&rev=492424&r1=492423&r2=492424
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultClientConnection.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultClientConnection.java Wed Jan 3 22:33:16 2007
@@ -55,6 +55,9 @@
public class DefaultClientConnection extends SocketHttpClientConnection
implements UnmanagedClientConnection {
+ /** The unconnected socket while being prepared. */
+ private volatile Socket preparedSocket;
+
/** The target host of this connection. */
private HttpHost targetHost;
@@ -85,6 +88,35 @@
// non-javadoc, see interface UnmanagedClientConnection
+ public void prepare(Socket sock) {
+
+ assertNotOpen();
+ preparedSocket = sock;
+
+ } // prepare
+
+
+ /**
+ * Force-closes this connection.
+ * If it is not yet {@link #open open} but {@link #prepare prepared},
+ * the associated socket is closed. That will interrupt a thread that
+ * is blocked on connecting the socket.
+ *
+ * @throws IOException in case of a problem
+ */
+ public void shutdown()
+ throws IOException {
+
+ Socket sock = preparedSocket; // copy volatile attribute
+ if (sock != null)
+ sock.close();
+
+ super.shutdown();
+
+ } // shutdown
+
+
+ // non-javadoc, see interface UnmanagedClientConnection
public void open(Socket sock, HttpHost target,
boolean secure, HttpParams params)
throws IOException {
@@ -106,6 +138,8 @@
bind(sock, params);
targetHost = target;
connSecure = secure;
+
+ preparedSocket = null;
} // open
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultSocketConnectionOperator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultSocketConnectionOperator.java?view=diff&rev=492424&r1=492423&r2=492424
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultSocketConnectionOperator.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/impl/DefaultSocketConnectionOperator.java Wed Jan 3 22:33:16 2007
@@ -104,18 +104,20 @@
"' in target host.");
}
final SocketFactory sf = schm.getSocketFactory();
- //@@@ create socket, register in connection, connect? (HTTPCLIENT-475)
- //@@@ Requires registration method, since conn.open(...) fails if
- //@@@ the socket is not open. Dependent objects need the streams!
- final Socket sock = sf.connectSocket
- (null, target.getHostName(), target.getPort(), local, 0, params);
+
+ Socket sock = sf.createSocket();
+ conn.prepare(sock);
+
+ sock = sf.connectSocket
+ (sock, target.getHostName(), target.getPort(), local, 0, params);
prepareSocket(sock, context, params);
//@@@ ask the factory whether the new socket is secure?
boolean secure = (sf instanceof SecureSocketFactory);
conn.open(sock, target, secure, params);
- //@@@ error handling: close the created socket in case of exception?
+ //@@@ error handling: unprepare the connection?
+ //@@@ error handling: close the created socket?
} // openConnection