Author: painter
Date: Wed Jan 16 19:14:15 2019
New Revision: 1851478

URL: http://svn.apache.org/viewvc?rev=1851478&view=rev
Log:
Add cookie parser to the pool, required by turbine

Added:
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserFactory.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserPool.java
Modified:
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/CookieParser.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultCookieParser.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java

Modified: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/CookieParser.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/CookieParser.java?rev=1851478&r1=1851477&r2=1851478&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/CookieParser.java
 (original)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/CookieParser.java
 Wed Jan 16 19:14:15 2019
@@ -100,4 +100,6 @@ public interface CookieParser
      * @param name the name of the cooking to unset
      */
     void unset (String name);
+
+       boolean isValid();
 }

Modified: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultCookieParser.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultCookieParser.java?rev=1851478&r1=1851477&r2=1851478&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultCookieParser.java
 (original)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultCookieParser.java
 Wed Jan 16 19:14:15 2019
@@ -154,5 +154,10 @@ public class DefaultCookieParser
     {
         set (name, " ", AGE_DELETE);
     }
+    
+    public boolean isValid() 
+    {
+       return true;
+    }
 
 }

Modified: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java?rev=1851478&r1=1851477&r2=1851478&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
 (original)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
 Wed Jan 16 19:14:15 2019
@@ -40,6 +40,8 @@ import org.apache.commons.pool2.impl.Gen
 import org.apache.fulcrum.parser.ValueParser.URLCaseFolding;
 import org.apache.fulcrum.parser.pool.BaseValueParserFactory;
 import org.apache.fulcrum.parser.pool.BaseValueParserPool;
+import org.apache.fulcrum.parser.pool.CookieParserFactory;
+import org.apache.fulcrum.parser.pool.CookieParserPool;
 import org.apache.fulcrum.parser.pool.DefaultParameterParserFactory;
 import org.apache.fulcrum.parser.pool.DefaultParameterParserPool;
 
@@ -81,11 +83,16 @@ public class DefaultParserService
      * Use commons pool to manage parameter parsers 
      */
     private DefaultParameterParserPool parameterParserPool;
-       
+
+    /** 
+     * Use commons pool to manage cookie parsers 
+     */
+    private CookieParserPool cookieParserPool;
+
     public DefaultParserService() 
     {
                // Define the default configuration
-               GenericObjectPoolConfig config = new 
GenericObjectPoolConfig<>();
+               GenericObjectPoolConfig config = new GenericObjectPoolConfig();
                config.setMaxIdle(1);
            config.setMaxTotal(DEFAULT_POOL_CAPACITY);
 
@@ -96,9 +103,13 @@ public class DefaultParserService
            // init the pool
            parameterParserPool 
                = new DefaultParameterParserPool(new 
DefaultParameterParserFactory(), config);
+           
+           // init the pool
+           cookieParserPool 
+               = new CookieParserPool(new CookieParserFactory(), config);
     }
     
-    public DefaultParserService(GenericObjectPoolConfig config) 
+    public DefaultParserService(GenericObjectPoolConfig<?> config) 
     {
            // init the pool
            valueParserPool 
@@ -271,6 +282,17 @@ public class DefaultParserService
                                }
             }
             
+            if ( ppClass.equals(DefaultCookieParser.class) )
+            {
+                               try {
+                                       DefaultCookieParser parserInstance = 
cookieParserPool.borrowObject();
+                       vp = (P) parserInstance;
+                               } catch (Exception e) {
+                               }
+            }
+            
+            
+            
             ((ParserServiceSupport)vp).setParserService(this);
             
((LogEnabled)vp).enableLogging(getLogger().getChildLogger(ppClass.getSimpleName()));
         }

Added: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserFactory.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserFactory.java?rev=1851478&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserFactory.java
 (added)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserFactory.java
 Wed Jan 16 19:14:15 2019
@@ -0,0 +1,76 @@
+package org.apache.fulcrum.parser.pool;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.pool2.BasePooledObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.fulcrum.parser.CookieParser;
+import org.apache.fulcrum.parser.DefaultCookieParser;
+
+
+/**
+ * Factory to create {@link org.apache.fulcrum.parser.CookieParser} objects
+ *
+ * @author <a href="mailto:pain...@apache.org";>Jeffery Painter</a>
+ * @version $Id: CookieParserFactory.java 1851080 2019-01-16 12:07:00Z painter 
$
+ */
+public class CookieParserFactory
+       extends BasePooledObjectFactory<DefaultCookieParser>
+{
+
+       /* (non-Javadoc)
+        * @see org.apache.commons.pool2.BasePooledObjectFactory#create()
+        */
+       @Override
+       public DefaultCookieParser create() throws Exception 
+       {
+               return new  DefaultCookieParser();
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.apache.commons.pool2.BasePooledObjectFactory#wrap(java.lang.Object)
+        */
+       @Override
+       public PooledObject<DefaultCookieParser> wrap(DefaultCookieParser obj) 
+       {
+               return new DefaultPooledObject<DefaultCookieParser>(obj);
+       }
+       
+   /**
+     * When an object is returned to the pool, clear the buffer.
+     */
+    @Override
+    public void passivateObject(PooledObject<DefaultCookieParser> 
pooledObject) 
+    {
+        pooledObject.getObject().clear();
+    }
+    
+    /* (non-Javadoc)
+     * @see 
org.apache.commons.pool2.BasePooledObjectFactory#validateObject(org.apache.commons.pool2.PooledObject)
+     */
+    @Override
+    public boolean validateObject(PooledObject<DefaultCookieParser> parser) 
+    {
+        return parser.getObject().isValid();
+    }
+    
+    
+}

Added: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserPool.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserPool.java?rev=1851478&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserPool.java
 (added)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/CookieParserPool.java
 Wed Jan 16 19:14:15 2019
@@ -0,0 +1,60 @@
+package org.apache.fulcrum.parser.pool;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.fulcrum.parser.DefaultCookieParser;
+
+/**
+ * Pool manager for {@link org.apache.fulcrum.parser.BaseValueParser} objects
+ *
+ * @author <a href="mailto:pain...@apache.org";>Jeffery Painter</a>
+ * @version $Id: CookieParserPool.java 1851080 2019-01-16 12:07:00Z painter $
+ */
+public class CookieParserPool extends GenericObjectPool<DefaultCookieParser> 
+{
+
+       /**
+        * Constructor.
+        * 
+        * @param factory the factory
+        */
+       public CookieParserPool(PooledObjectFactory<DefaultCookieParser> 
factory) 
+       {
+               super(factory);
+       }
+
+       /**
+        * Constructor.
+        * 
+        * This can be used to have full control over the pool using 
configuration
+        * object.
+        * 
+        * @param factory the factory
+        * @param config user defined configuration
+        */
+       public CookieParserPool(PooledObjectFactory<DefaultCookieParser> 
factory, GenericObjectPoolConfig config) 
+       {
+               super(factory, config);
+       }
+
+}


Reply via email to