Author: painter
Date: Wed Jan 16 17:16:28 2019
New Revision: 1851472

URL: http://svn.apache.org/viewvc?rev=1851472&view=rev
Log:
Replace fulcrum-pool with commons-pool2 instead

Added:
    turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserFactory.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserPool.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserFactory.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserPool.java
Modified:
    turbine/fulcrum/trunk/parser/pom.xml
    turbine/fulcrum/trunk/parser/src/changes/changes.xml
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/BaseValueParser.java
    
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
    turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml

Modified: turbine/fulcrum/trunk/parser/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/pom.xml?rev=1851472&r1=1851471&r2=1851472&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/pom.xml (original)
+++ turbine/fulcrum/trunk/parser/pom.xml Wed Jan 16 17:16:28 2019
@@ -90,11 +90,11 @@
       <artifactId>commons-lang3</artifactId>
       <version>3.8.1</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.fulcrum</groupId>
-      <artifactId>fulcrum-pool</artifactId>
-      <version>1.0.5</version>
-    </dependency>
+       <dependency>
+           <groupId>org.apache.commons</groupId>
+           <artifactId>commons-pool2</artifactId>
+           <version>2.6.0</version>
+       </dependency>
 
     <!-- testing dependencies -->
     <dependency>

Modified: turbine/fulcrum/trunk/parser/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/changes/changes.xml?rev=1851472&r1=1851471&r2=1851472&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/changes/changes.xml (original)
+++ turbine/fulcrum/trunk/parser/src/changes/changes.xml Wed Jan 16 17:16:28 
2019
@@ -23,6 +23,9 @@
 
     <body>
         <release version="2.0.0" date="in SVN">
+          <action dev="painter" type="update">
+            Remove dependency on fulcrum-pool and use commons-pool2 v2.6.0 
instead
+          </action>
           <action dev="gk" type="update">
             Added tests for getParts()
           </action>

Modified: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/BaseValueParser.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/BaseValueParser.java?rev=1851472&r1=1851471&r2=1851472&view=diff
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/BaseValueParser.java
 (original)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/BaseValueParser.java
 Wed Jan 16 17:16:28 2019
@@ -39,7 +39,6 @@ import org.apache.avalon.framework.logge
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.fulcrum.pool.Recyclable;
 
 /**
  * BaseValueParser is a base class for classes that need to parse
@@ -73,7 +72,7 @@ import org.apache.fulcrum.pool.Recyclabl
  */
 public class BaseValueParser
     implements ValueParser,
-               Recyclable, ParserServiceSupport, LogEnabled
+               ParserServiceSupport, LogEnabled
 {
     /** The ParserService instance to query for conversion and configuration */
     protected ParserService parserService;
@@ -168,7 +167,6 @@ public class BaseValueParser
     /**
      * Recycles the parser.
      */
-    @Override
     public void recycle()
     {
         recycle(DEFAULT_CHARACTER_ENCODING);
@@ -187,7 +185,6 @@ public class BaseValueParser
     /**
      * Disposes the parser.
      */
-    @Override
     public void dispose()
     {
         clear();
@@ -1622,7 +1619,6 @@ public class BaseValueParser
      *
      * @return true, if the object is disposed.
      */
-    @Override
     public boolean isDisposed()
     {
         return disposed;
@@ -1683,4 +1679,11 @@ public class BaseValueParser
     {
         return parserService.getUrlFolding();
     }
+
+       public boolean isValid() 
+       {
+               if ( this.characterEncoding != null && this.locale != null )
+                       return true;
+               return false;
+       }
 }

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=1851472&r1=1851471&r2=1851472&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 17:16:28 2019
@@ -37,8 +37,10 @@ import org.apache.avalon.framework.servi
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.fulcrum.parser.ValueParser.URLCaseFolding;
-import org.apache.fulcrum.pool.PoolException;
-import org.apache.fulcrum.pool.PoolService;
+import org.apache.fulcrum.parser.pool.BaseValueParserFactory;
+import org.apache.fulcrum.parser.pool.BaseValueParserPool;
+import org.apache.fulcrum.parser.pool.DefaultParameterParserFactory;
+import org.apache.fulcrum.parser.pool.DefaultParameterParserPool;
 
 
 /**
@@ -64,10 +66,17 @@ public class DefaultParserService
      */
     private String parameterEncoding = PARAMETER_ENCODING_DEFAULT;
 
-    /**
-     * The pool service component to use
+    /** 
+     * Use commons pool to manage value parsers 
+     */
+    private BaseValueParserPool valueParserPool 
+       = new BaseValueParserPool(new BaseValueParserFactory());
+
+    /** 
+     * Use commons pool to manage parameter parsers 
      */
-    private PoolService poolService = null;
+    private DefaultParameterParserPool parameterParserPool 
+       = new DefaultParameterParserPool(new DefaultParameterParserFactory());
 
     /**
      * Get the character encoding that will be used by this ValueParser.
@@ -203,30 +212,35 @@ public class DefaultParserService
      *
      * @throws InstantiationException if the instance could not be created
      */
-    @Override
+    @SuppressWarnings("unchecked")
+       @Override
     public <P extends ValueParser> P getParser(Class<P> ppClass) throws 
InstantiationException
     {
         P vp = null;
 
         try
         {
-            @SuppressWarnings("unchecked") // Until PoolService is generified
-            P parserInstance = (P) poolService.getInstance(ppClass);
-            vp = parserInstance;
-
-            if (vp instanceof ParserServiceSupport)
+            if ( ppClass.equals(BaseValueParser.class) )
             {
-                ((ParserServiceSupport)vp).setParserService(this);
+               BaseValueParser parserInstance;
+                               try {
+                                       parserInstance = 
valueParserPool.borrowObject();
+                                       vp = (P) parserInstance;
+                               } catch (Exception e) {
+                               }
             }
 
-            if (vp instanceof LogEnabled)
+            if ( ppClass.equals(DefaultParameterParser.class) )
             {
-                
((LogEnabled)vp).enableLogging(getLogger().getChildLogger(ppClass.getSimpleName()));
+                               try {
+                       DefaultParameterParser parserInstance = 
parameterParserPool.borrowObject();
+                       vp = (P) parserInstance;
+                               } catch (Exception e) {
+                               }
             }
-        }
-        catch (PoolException pe)
-        {
-            throw new InstantiationException("Parser class '" + ppClass + "' 
is illegal. " + pe.getMessage());
+            
+            ((ParserServiceSupport)vp).setParserService(this);
+            
((LogEnabled)vp).enableLogging(getLogger().getChildLogger(ppClass.getSimpleName()));
         }
         catch (ClassCastException x)
         {
@@ -247,7 +261,17 @@ public class DefaultParserService
     public void putParser(ValueParser parser)
     {
         parser.clear();
-        poolService.putInstance(parser);
+        
+        if ( parser.getClass().isInstance(BaseValueParser.class) )
+        {
+                       valueParserPool.returnObject( (BaseValueParser) parser 
);
+        }
+
+        if ( parser.getClass().isInstance(DefaultParameterParser.class) )
+        {
+               parameterParserPool.returnObject( (DefaultParameterParser) 
parser );
+        }
+
     }
 
     /**
@@ -296,15 +320,15 @@ public class DefaultParserService
     @Override
     public void service(ServiceManager manager) throws ServiceException
     {
-        if (manager.hasService(PoolService.ROLE))
-        {
-            poolService = (PoolService)manager.lookup(PoolService.ROLE);
-        }
-        else
-        {
-            throw new ServiceException(ParserService.ROLE,
-                    "Service requires " +
-                    PoolService.ROLE + " to be available");
-        }
+//        if (manager.hasService(PoolService.ROLE))
+//        {
+//            poolService = (PoolService)manager.lookup(PoolService.ROLE);
+//        }
+//        else
+//        {
+//            throw new ServiceException(ParserService.ROLE,
+//                    "Service requires " +
+//                    PoolService.ROLE + " to be available");
+//        }
     }
 }

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

Added: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserPool.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserPool.java?rev=1851472&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserPool.java
 (added)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/BaseValueParserPool.java
 Wed Jan 16 17:16:28 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.BaseValueParser;
+
+/**
+ * Pool manager for {@link org.apache.fulcrum.parser.BaseValueParser} objects
+ *
+ * @author <a href="mailto:pain...@apache.org";>Jeffery Painter</a>
+ * @version $Id: BaseValueParserPool.java 1851080 2019-01-16 12:07:00Z painter 
$
+ */
+public class BaseValueParserPool extends GenericObjectPool<BaseValueParser> 
+{
+
+       /**
+        * Constructor.
+        * 
+        * @param factory the factory
+        */
+       public BaseValueParserPool(PooledObjectFactory<BaseValueParser> 
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 BaseValueParserPool(PooledObjectFactory<BaseValueParser> 
factory, GenericObjectPoolConfig config) 
+       {
+               super(factory, config);
+       }
+
+}

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

Added: 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserPool.java
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserPool.java?rev=1851472&view=auto
==============================================================================
--- 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserPool.java
 (added)
+++ 
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/pool/DefaultParameterParserPool.java
 Wed Jan 16 17:16:28 2019
@@ -0,0 +1,61 @@
+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.DefaultParameterParser;
+
+
+/**
+ * Pool manager for {@link org.apache.fulcrum.parser.DefaultParameterParser} 
objects
+ *
+ * @author <a href="mailto:pain...@apache.org";>Jeffery Painter</a>
+ * @version $Id: DefaultParameterParserPool.java 1851080 2019-01-16 12:07:00Z 
painter $
+ */
+public class DefaultParameterParserPool 
+       extends GenericObjectPool<DefaultParameterParser>  
+{
+
+       /**
+        * Constructor.
+        * 
+        * @param factory the factory
+        */
+       public 
DefaultParameterParserPool(PooledObjectFactory<DefaultParameterParser> 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 
DefaultParameterParserPool(PooledObjectFactory<DefaultParameterParser> factory, 
GenericObjectPoolConfig config) 
+       {
+               super(factory, config);
+       }
+}

Modified: turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml
URL: 
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml?rev=1851472&r1=1851471&r2=1851472&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml Wed Jan 16 
17:16:28 2019
@@ -20,16 +20,6 @@
 <!-- This configuration file for Avalon components is used for testing the 
TestComponent -->
 <role-list>
     <role
-        name="org.apache.fulcrum.pool.PoolService"
-        shorthand="parser"
-        default-class="org.apache.fulcrum.pool.DefaultPoolService"
-    />
-    <role
-        name="org.apache.fulcrum.factory.FactoryService"
-        shorthand="parser"
-        default-class="org.apache.fulcrum.factory.DefaultFactoryService"
-    />
-    <role
         name="org.apache.fulcrum.parser.ParserService"
         shorthand="parser"
         default-class="org.apache.fulcrum.parser.DefaultParserService"


Reply via email to