hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r646081 - in /httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http: conn/OperatedClientConnection.java impl/conn/DefaultClientConnection.java impl/conn/DefaultClientConnectionOperator.java
Date Tue, 08 Apr 2008 21:28:49 GMT
Author: olegk
Date: Tue Apr  8 14:28:48 2008
New Revision: 646081

URL: http://svn.apache.org/viewvc?rev=646081&view=rev
Log:
Simplified OperatedClientConnection interface 

Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java?rev=646081&r1=646080&r2=646081&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java
Tue Apr  8 14:28:48 2008
@@ -41,9 +41,8 @@
 
 
 /**
- * A client-side connection that needs to be operated.
- * It relies on outside logic to connect sockets to the appropriate hosts.
- * It can be operated directly by an application, or through an
+ * A client-side connection that relies on outside logic to connect sockets to the 
+ * appropriate hosts. It can be operated directly by an application, or through an
  * {@link ClientConnectionOperator operator}.
  *
  *
@@ -103,15 +102,12 @@
 
 
     /**
-     * Announces opening of this connection.
-     * Opening can be announced only while the connection is closed.
-     * This is an optional step, you can call {@link #open open}
-     * without an announcement.
+     * Signals that this connection is in the process of being open.
      * <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
+     * By calling this method, you can provide the connection with
+     * the unconnected socket that will be connected before
+     * {@link #openCompleted} is called. 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.
@@ -119,36 +115,32 @@
      * 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 announcing.
+     * You also must call {@link #openCompleted} in order to complete
+     * the process
      *
      * @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.
+     *                  be connected.
+     * @param target    the target host of this connection
+     * @param secure    <code>true</code> if this connection is secure, for
+     *                  example if an <code>SSLSocket</code> is used, or
+     *                  <code>false</code> if it is not secure
      */
-    void announce(Socket sock)
+    void opening(Socket sock, HttpHost target, boolean secure)
+        throws IOException
         ;
 
 
     /**
-     * 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}.
+     * Signals that the connection has been successfully open.
+     * An attempt to call this method on an open connection will cause
+     * an exception.
      *
      * @param sock      the open socket for communicating with the target host
-     * @param target    the target host of this connection
-     * @param secure    <code>true</code> if this connection is secure, for
-     *                  example if an <code>SSLSocket</code> is used, or
-     *                  <code>false</code> if it is not secure
      * @param params    parameters for this connection. The parameters will
      *                  be used when creating dependent objects, for example
      *                  to determine buffer sizes.
      */
-    void open(Socket sock, HttpHost target,
-              boolean secure, HttpParams params)
+    void openCompleted(HttpParams params)
         throws IOException
         ;
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java?rev=646081&r1=646080&r2=646081&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
Tue Apr  8 14:28:48 2008
@@ -71,8 +71,8 @@
     
     private static final Log LOG = LogFactory.getLog(DefaultClientConnection.class);
     
-    /** The unconnected socket between announce and open. */
-    private volatile Socket announcedSocket;
+    /** The unconnected socket */
+    private volatile Socket socket;
 
     /** The target host of this connection. */
     private HttpHost targetHost;
@@ -96,21 +96,28 @@
     }
 
 
-    // non-javadoc, see interface OperatedClientConnection
     @Override
     public final Socket getSocket() {
-        return super.getSocket(); // base class attribute
+        return this.socket;
     }
 
 
-    // non-javadoc, see interface OperatedClientConnection
-    public void announce(Socket sock) {
-
+    public void opening(Socket sock, HttpHost target, boolean secure) {
         assertNotOpen();
-        announcedSocket = sock;
-
-    } // prepare
+        this.socket = sock;
+        this.targetHost = target;
+        this.connSecure = secure;
+    }
 
+    
+    public void openCompleted(HttpParams params) throws IOException {
+        assertNotOpen();
+        if (params == null) {
+            throw new IllegalArgumentException
+                ("Parameters must not be null.");
+        }
+        bind(this.socket, params);
+    }
 
     /**
      * Force-closes this connection.
@@ -124,12 +131,11 @@
     public void shutdown() throws IOException {
         LOG.debug("Connection shut down");
         
-        Socket sock = announcedSocket; // copy volatile attribute
+        super.shutdown();
+        Socket sock = this.socket; // copy volatile attribute
         if (sock != null)
             sock.close();
 
-        super.shutdown();
-
     } // shutdown
 
     
@@ -184,35 +190,6 @@
 
 
     // non-javadoc, see interface OperatedClientConnection
-    public void open(Socket sock, HttpHost target,
-                     boolean secure, HttpParams params)
-        throws IOException {
-
-        assertNotOpen();
-        if (sock == null) {
-            throw new IllegalArgumentException
-                ("Socket must not be null.");
-        }
-        if (target == null) {
-            throw new IllegalArgumentException
-                ("Target host must not be null.");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException
-                ("Parameters must not be null.");
-        }
-
-        bind(sock, params);
-        
-        targetHost = target;
-        connSecure = secure;
-
-        announcedSocket = null;
-
-    } // open
-
-
-    // non-javadoc, see interface OperatedClientConnection
     public void update(Socket sock, HttpHost target,
                        boolean secure, HttpParams params)
         throws IOException {
@@ -227,8 +204,10 @@
                 ("Parameters must not be null.");
         }
 
-        if (sock != null)
+        if (sock != null) {
+            this.socket = sock;
             bind(sock, params);
+        }
         targetHost = target;
         connSecure = secure;
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=646081&r1=646080&r2=646081&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
Tue Apr  8 14:28:48 2008
@@ -128,7 +128,7 @@
         final SocketFactory sf = schm.getSocketFactory();
 
         Socket sock = sf.createSocket();
-        conn.announce(sock);
+        conn.opening(sock, target, sf.isSecure(sock));
 
         try {
             sock = sf.connectSocket(sock, target.getHostName(),
@@ -138,13 +138,7 @@
             throw new HttpHostConnectException(target, ex);
         }
         prepareSocket(sock, context, params);
-
-        final boolean secure = sf.isSecure(sock);
-
-        conn.open(sock, target, secure, params);
-        //@@@ error handling: unannounce at connection?
-        //@@@ error handling: close the created socket?
-
+        conn.openCompleted(params);
     } // openConnection
 
 



Mime
View raw message