mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r548686 - in /mina/trunk/core/src/main/java/org/apache/mina/filter/reqres: RequestResponseFilter.java ResponseInspectorFactory.java
Date Tue, 19 Jun 2007 10:40:49 GMT
Author: trustin
Date: Tue Jun 19 03:40:48 2007
New Revision: 548686

URL: http://svn.apache.org/viewvc?view=rev&rev=548686
Log:
Added ResponseInspectorFactory in case a RequestResponseFilter instance is shared among multiple
sessions

Added:
    mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
  (with props)
Modified:
    mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/RequestResponseFilter.java

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/RequestResponseFilter.java?view=diff&rev=548686&r1=548685&r2=548686
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/RequestResponseFilter.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/RequestResponseFilter.java
Tue Jun 19 03:40:48 2007
@@ -44,24 +44,37 @@
  */
 public class RequestResponseFilter extends IoFilterAdapter {
 
+    private static final String RESPONSE_INSPECTOR = RequestResponseFilter.class.getName()
+ ".responseInspector";
     private static final String REQUEST_STORE = RequestResponseFilter.class.getName() + ".requestStore";
     private static final String UNFINISHED_TASKS = RequestResponseFilter.class.getName()
+ ".unfinishedTasks";
 
     private static int timerId = 0;
     
-    private final ResponseInspector responseInspector;
+    private final ResponseInspectorFactory responseInspectorFactory;
     private final Timer timer = new Timer("RequestTimer-" + (timerId++), true);
     
-    public RequestResponseFilter(ResponseInspector responseInspector) {
+    public RequestResponseFilter(final ResponseInspector responseInspector) {
         if (responseInspector == null) {
             throw new NullPointerException("responseInspector");
         }
-        this.responseInspector = responseInspector;
+        this.responseInspectorFactory = new ResponseInspectorFactory() {
+            public ResponseInspector getResponseInspector() {
+                return responseInspector;
+            }
+        };
+    }
+    
+    public RequestResponseFilter(ResponseInspectorFactory responseInspectorFactory) {
+        if (responseInspectorFactory == null) {
+            throw new NullPointerException("responseInspectorFactory");
+        }
+        this.responseInspectorFactory = responseInspectorFactory;
     }
     
     @Override
     public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws
Exception {
         IoSession session = parent.getSession();
+        session.setAttribute(RESPONSE_INSPECTOR, responseInspectorFactory.getResponseInspector());
         session.setAttribute(REQUEST_STORE, new ConcurrentHashMap<Object, Request>());
         session.setAttribute(UNFINISHED_TASKS, new LinkedHashSet<TimerTask>());
     }
@@ -83,6 +96,7 @@
 
     @Override
     public void messageReceived(NextFilter nextFilter, IoSession session, Object message)
throws Exception {
+        ResponseInspector responseInspector = (ResponseInspector) session.getAttribute(RESPONSE_INSPECTOR);
         Object requestId = responseInspector.getRequestId(message);
         if (requestId == null) {
             // Not a response message.  Ignore.

Added: mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java?view=auto&rev=548686
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
(added)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
Tue Jun 19 03:40:48 2007
@@ -0,0 +1,32 @@
+/*
+ *  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. 
+ *  
+ */
+package org.apache.mina.filter.reqres;
+
+/**
+ * 
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ResponseInspectorFactory {
+    /**
+     * Returns a {@link ResponseInspector}.
+     */
+    ResponseInspector getResponseInspector();
+}

Propchange: mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/ResponseInspectorFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message