hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r439818 - in /jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async: HttpDispatcherParams.java impl/SimpleHttpDispatcher.java
Date Sun, 03 Sep 2006 18:21:11 GMT
Author: rolandw
Date: Sun Sep  3 11:21:11 2006
New Revision: 439818

URL: http://svn.apache.org/viewvc?view=rev&rev=439818
Log:
preprocessing switchable to background thread

Added:
    jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
  (with props)
Modified:
    jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java

Added: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java?view=auto&rev=439818
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
(added)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
Sun Sep  3 11:21:11 2006
@@ -0,0 +1,127 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed 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.async;
+
+
+import org.apache.http.params.HttpParams;
+
+
+
+/**
+ * Provides easy access to parameters for dispatchers.
+ * All methods are static. This class can not be instantiated.
+ * However, it can be subclassed to add implementation specific parameters.
+ * 
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
+ * @version $Revision$
+ * 
+ * @since 1.0
+ */
+public class HttpDispatcherParams {
+
+    /**
+     * Whether to preprocess in an application or background thread.
+     * <code>true</code> for background thread,
+     * <code>false</code> for application thread.
+     */
+    public final static String PREPROCESS_BACKGROUND =
+        "http.dispatcher.preprocess.background";
+
+    /**
+     * The default for {@link #PREPROCESS_BACKGROUND PREPROCESS_BACKGROUND}.
+     */
+    public final static boolean PREPROCESS_BACKGROUND_DEFAULT = false;
+
+
+    /**
+     * Restricted default constructor.
+     * This class can not be instantiated.
+     *
+     * @throws UnsupportedOperationException    always
+     */
+    protected HttpDispatcherParams()
+        throws UnsupportedOperationException {
+
+        throw new UnsupportedOperationException
+            ("This class can not be instantiated.");
+    }
+
+
+    /**
+     * Asserts that the <code>params</code> argument is not <code>null</code>.
+     *
+     * @param params    the parameters to check for existence
+     *
+     * @throws IllegalArgumentException
+     *          iff the <code>params</code> argument is <code>null</code>
+     */
+    public final static void assertParams(final HttpParams params)
+        throws IllegalArgumentException {
+
+        if (params == null)
+            throw new IllegalArgumentException
+                ("HTTP parameters must not be null.");
+    }
+
+
+    /**
+     * Obtains {@link #PREPROCESS_BACKGROUND PREPROCESS_BACKGROUND}.
+     *
+     * @param params    the parameters from which to obtain
+     *
+     * @return  the value from the parameters, or the default
+     */
+    public final static
+        boolean getPreprocessBackground(final HttpParams params) {
+
+        assertParams(params);
+        return params.getBooleanParameter(PREPROCESS_BACKGROUND,
+                                          PREPROCESS_BACKGROUND_DEFAULT);
+    }
+
+
+    /**
+     * Specifies {@link #PREPROCESS_BACKGROUND PREPROCESS_BACKGROUND}.
+     *
+     * @param params    the parameters to update
+     * @param value     the value for the parameters
+     */
+    public final static
+        void setPreprocessBackground(HttpParams params, boolean value) {
+
+        assertParams(params);
+        params.setBooleanParameter(PREPROCESS_BACKGROUND, value);
+    }
+
+
+} // class HttpDispatcherParams

Propchange: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcherParams.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java?view=diff&rev=439818&r1=439817&r2=439818
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
(original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
Sun Sep  3 11:21:11 2006
@@ -42,9 +42,11 @@
 import org.apache.http.HttpClientConnection;
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpException;
+import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.async.HttpHandle;
 import org.apache.http.async.HttpDispatcher;
+import org.apache.http.async.HttpDispatcherParams;
 import org.apache.http.async.AsyncHttpProcessor;
 import org.apache.http.async.AbstractHttpHandle;
 import org.apache.http.async.AbstractHttpDispatcher;
@@ -177,11 +179,16 @@
         //@@@ check whether target is suitable:
         //@@@ - for now: no proxy (how to indicate proxy in the first place?)
 
+        //@@@ setting default parameters is also part of "prepareRequest",
+        //@@@ but we need the params below to decide when to preprocess
+        HttpParams params = request.getParams();
+        params.setDefaults(async_processor.getParams());
+
         HttpContext ctxt = prepareContext(async_processor, target, context);
         SimpleHttpHandle hdl = new SimpleHttpHandle(this, request, ctxt);
 
-        //@@@ check with params whether to preprocess here or later
-        prepareRequest(async_processor, request, ctxt);
+        if (!HttpDispatcherParams.getPreprocessBackground(params))
+            prepareRequest(async_processor, request, ctxt);
 
         // linked handles need to be tracked for abortAll()
         synchronized (linked_handle_monitor) {
@@ -383,6 +390,16 @@
                                 continue; // while (background_thread)
 
                             response_handles.add(handle);
+                        }
+
+                        // check whether preprocessing is required
+                        if (!Boolean.TRUE.equals
+                            (handle.getContext().getAttribute
+                             (CTXT_REQUEST_PREPROCESSED))) {
+
+                            prepareRequest(async_processor,
+                                           handle.getRequest(),
+                                           handle.getContext());
                         }
 
                         //@@@ TODO: retry handling!



Mime
View raw message