manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1547500 - in /manifoldcf/branches/CONNECTORS-781/framework: agents/src/main/java/org/apache/manifoldcf/agents/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf...
Date Tue, 03 Dec 2013 17:59:52 GMT
Author: kwright
Date: Tue Dec  3 17:59:52 2013
New Revision: 1547500

URL: http://svn.apache.org/r1547500
Log:
Convert the remaining connectors.  Only problem now is that the tests hang.

Modified:
    manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java
    manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java
    manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/MappingConnectorFactory.java
    manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java

Modified: manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java?rev=1547500&r1=1547499&r2=1547500&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java (original)
+++ manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java Tue Dec  3 17:59:52 2013
@@ -32,12 +32,13 @@ public class OutputConnectorFactory exte
   public static final String _rcsid = "@(#)$Id: OutputConnectorFactory.java 988245 2010-08-23 18:39:35Z kwright $";
 
   // Static factory
-  protected static OutputConnectorFactory thisFactory = new OutputConnectorFactory();
+  protected final static OutputConnectorFactory thisFactory = new OutputConnectorFactory();
 
   protected OutputConnectorFactory()
   {
   }
 
+  @Override
   protected boolean isInstalled(IThreadContext tc, String className)
     throws ManifoldCFException
   {

Modified: manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java?rev=1547500&r1=1547499&r2=1547500&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java (original)
+++ manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/AuthorityConnectorFactory.java Tue Dec  3 17:59:52 2013
@@ -26,14 +26,32 @@ import java.lang.reflect.*;
 
 /** This class manages a pool of authority connectors.
 */
-public class AuthorityConnectorFactory
+public class AuthorityConnectorFactory extends ConnectorFactory<IAuthorityConnector>
 {
-  // Pool hash table.
-  // Keyed by PoolKey; value is Pool
-  protected static Map poolHash = new HashMap();
+  // Static factory
+  protected final static AuthorityConnectorFactory thisFactory = new AuthorityConnectorFactory();
+  
+  protected AuthorityConnectorFactory()
+  {
+  }
 
-  private AuthorityConnectorFactory()
+  @Override
+  protected boolean isInstalled(IThreadContext tc, String className)
+    throws ManifoldCFException
   {
+    IAuthorityConnectorManager connMgr = AuthorityConnectorManagerFactory.make(tc);
+    return connMgr.isInstalled(className);
+  }
+
+  /** Get the default response from a connector.  Called if the connection attempt fails.
+  */
+  public AuthorizationResponse getThisDefaultAuthorizationResponse(IThreadContext threadContext, String className, String userName)
+    throws ManifoldCFException
+  {
+    IAuthorityConnector connector = getThisConnector(threadContext,className);
+    if (connector == null)
+      return null;
+    return connector.getDefaultAuthorizationResponse(userName);
   }
 
   /** Install connector.
@@ -42,8 +60,7 @@ public class AuthorityConnectorFactory
   public static void install(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IAuthorityConnector connector = getConnectorNoCheck(className);
-    connector.install(threadContext);
+    thisFactory.installThis(threadContext,className);
   }
 
   /** Uninstall connector.
@@ -52,8 +69,7 @@ public class AuthorityConnectorFactory
   public static void deinstall(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IAuthorityConnector connector = getConnectorNoCheck(className);
-    connector.deinstall(threadContext);
+    thisFactory.deinstallThis(threadContext,className);
   }
 
   /** Get the default response from a connector.  Called if the connection attempt fails.
@@ -61,10 +77,7 @@ public class AuthorityConnectorFactory
   public static AuthorizationResponse getDefaultAuthorizationResponse(IThreadContext threadContext, String className, String userName)
     throws ManifoldCFException
   {
-    IAuthorityConnector connector = getConnector(threadContext,className);
-    if (connector == null)
-      return null;
-    return connector.getDefaultAuthorizationResponse(userName);
+    return thisFactory.getThisDefaultAuthorizationResponse(threadContext,className,userName);
   }
 
   /** Output the configuration header section.
@@ -72,10 +85,7 @@ public class AuthorityConnectorFactory
   public static void outputConfigurationHeader(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, ArrayList tabsArray)
     throws ManifoldCFException, IOException
   {
-    IAuthorityConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationHeader(threadContext,out,locale,parameters,tabsArray);
+    thisFactory.outputThisConfigurationHeader(threadContext,className,out,locale,parameters,tabsArray);
   }
 
   /** Output the configuration body section.
@@ -83,10 +93,7 @@ public class AuthorityConnectorFactory
   public static void outputConfigurationBody(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
     throws ManifoldCFException, IOException
   {
-    IAuthorityConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationBody(threadContext,out,locale,parameters,tabName);
+    thisFactory.outputThisConfigurationBody(threadContext,className,out,locale,parameters,tabName);
   }
 
   /** Process configuration post data for a connector.
@@ -94,10 +101,7 @@ public class AuthorityConnectorFactory
   public static String processConfigurationPost(IThreadContext threadContext, String className, IPostParameters variableContext, Locale locale, ConfigParams configParams)
     throws ManifoldCFException
   {
-    IAuthorityConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return null;
-    return connector.processConfigurationPost(threadContext,variableContext,locale,configParams);
+    return thisFactory.processThisConfigurationPost(threadContext,className,variableContext,locale,configParams);
   }
   
   /** View connector configuration.
@@ -105,11 +109,7 @@ public class AuthorityConnectorFactory
   public static void viewConfiguration(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams configParams)
     throws ManifoldCFException, IOException
   {
-    IAuthorityConnector connector = getConnector(threadContext, className);
-    // We want to be able to view connections even if they have unregistered connectors.
-    if (connector == null)
-      return;
-    connector.viewConfiguration(threadContext,out,locale,configParams);
+    thisFactory.viewThisConfiguration(threadContext,className,out,locale,configParams);
   }
 
   /** Get a repository connector instance, but do NOT check if class is installed first!
@@ -119,139 +119,7 @@ public class AuthorityConnectorFactory
   public static IAuthorityConnector getConnectorNoCheck(String className)
     throws ManifoldCFException
   {
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IAuthorityConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IAuthorityConnector.");
-      return (IAuthorityConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      throw new ManifoldCFException("No authority connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IAuthorityConnector implementation '"+
-        className+"'.  Need xxx().",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-
-  }
-
-  /** Get a repository connector instance.
-  *@param className is the class name.
-  *@return the instance.
-  */
-  protected static IAuthorityConnector getConnector(IThreadContext threadContext, String className)
-    throws ManifoldCFException
-  {
-    IAuthorityConnectorManager connMgr = AuthorityConnectorManagerFactory.make(threadContext);
-    if (connMgr.isInstalled(className) == false)
-      return null;
-
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IAuthorityConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IAuthorityConnector.");
-      return (IAuthorityConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      // If we get this exception, it may mean that the authority is not registered.
-      if (connMgr.isInstalled(className) == false)
-        return null;
-
-      throw new ManifoldCFException("No authority connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IAuthorityConnector implementation '"+
-        className+"'.  Need xxx().",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IAuthorityConnector implementation '"+className+"'",
-        e);
-    }
-
+    return thisFactory.getThisConnectorNoCheck(className);
   }
 
   /** Get a repository connector.
@@ -265,29 +133,7 @@ public class AuthorityConnectorFactory
     String className, ConfigParams configInfo, int maxPoolSize)
     throws ManifoldCFException
   {
-    // System.out.println("In AuthorityConnectorManager.grab()");
-
-    // We want to get handles off the pool and use them.  But the
-    // handles we fetch have to have the right config information.
-
-    // Use the classname and config info to build a pool key
-    PoolKey pk = new PoolKey(className,configInfo);
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-      if (p == null)
-      {
-        // Build it again, this time making a copy
-        pk = new PoolKey(className,configInfo.duplicate());
-        p = new Pool(pk,maxPoolSize);
-        poolHash.put(pk,p);
-      }
-    }
-
-    IAuthorityConnector rval = p.getConnector(threadContext);
-    // System.out.println("Leaving AuthorityConnectorManager.grab()");
-    return rval;
+    return thisFactory.grabThis(threadContext,className,configInfo,maxPoolSize);
   }
 
   /** Release a repository connector.
@@ -296,20 +142,7 @@ public class AuthorityConnectorFactory
   public static void release(IAuthorityConnector connector)
     throws ManifoldCFException
   {
-    if (connector == null)
-      return;
-
-    // System.out.println("Releasing an authority connector");
-    // Figure out which pool this goes on, and put it there
-    PoolKey pk = new PoolKey(connector.getClass().getName(),connector.getConfiguration());
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-    }
-
-    p.releaseConnector(connector);
-    // System.out.println("Done releasing");
+    thisFactory.releaseThis(connector);
   }
 
   /** Idle notification for inactive authority connector handles.
@@ -318,17 +151,7 @@ public class AuthorityConnectorFactory
   public static void pollAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // Go through the whole pool and notify everyone
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.pollAll(threadContext);
-      }
-    }
-
+    thisFactory.pollThisAllConnectors(threadContext);
   }
 
   /** Clean up all open authority connector handles.
@@ -339,257 +162,8 @@ public class AuthorityConnectorFactory
   public static void closeAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // Go through the whole pool and clean it out
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.releaseAll(threadContext);
-      }
-    }
-  }
-
-  /** This is an immutable pool key class, which describes a pool in terms of two independent keys.
-  */
-  public static class PoolKey
-  {
-    protected String className;
-    protected ConfigParams configInfo;
-
-    /** Constructor.
-    */
-    public PoolKey(String className, Map configInfo)
-    {
-      this.className = className;
-      this.configInfo = new ConfigParams(configInfo);
-    }
-
-    public PoolKey(String className, ConfigParams configInfo)
-    {
-      this.className = className;
-      this.configInfo = configInfo;
-    }
-
-    /** Get the class name.
-    *@return the class name.
-    */
-    public String getClassName()
-    {
-      return className;
-    }
-
-    /** Get the config info.
-    *@return the params
-    */
-    public ConfigParams getParams()
-    {
-      return configInfo;
-    }
-
-    /** Hash code.
-    */
-    public int hashCode()
-    {
-      return className.hashCode() + configInfo.hashCode();
-    }
-
-    /** Equals operator.
-    */
-    public boolean equals(Object o)
-    {
-      if (!(o instanceof PoolKey))
-        return false;
-
-      PoolKey pk = (PoolKey)o;
-      return pk.className.equals(className) && pk.configInfo.equals(configInfo);
-    }
-
-  }
-
-  /** This class represents a value in the pool hash, which corresponds to a given key.
-  */
-  public static class Pool
-  {
-    protected ArrayList stack = new ArrayList();
-    protected PoolKey key;
-    protected int numFree;
-
-    /** Constructor
-    */
-    public Pool(PoolKey pk, int maxCount)
-    {
-      key = pk;
-      numFree = maxCount;
-    }
-
-    /** Grab a repository connector.
-    * If none exists, construct it using the information in the pool key.
-    *@return the connector.
-    */
-    public synchronized IAuthorityConnector getConnector(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (numFree == 0)
-      {
-        try
-        {
-          wait();
-        }
-        catch (InterruptedException e)
-        {
-          throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-        }
-      }
-
-      if (stack.size() == 0)
-      {
-        String className = key.getClassName();
-        ConfigParams configParams = key.getParams();
-
-        IAuthorityConnectorManager connMgr = AuthorityConnectorManagerFactory.make(threadContext);
-        if (connMgr.isInstalled(className) == false)
-          return null;
-
-        try
-        {
-          Class theClass = ManifoldCF.findClass(className);
-          Class[] argumentClasses = new Class[0];
-          // Look for a constructor
-          Constructor c = theClass.getConstructor(argumentClasses);
-          Object[] arguments = new Object[0];
-          Object o = c.newInstance(arguments);
-          if (!(o instanceof IAuthorityConnector))
-            throw new ManifoldCFException("Class '"+className+"' does not implement IAuthorityConnector.");
-          IAuthorityConnector newrc = (IAuthorityConnector)o;
-          newrc.connect(configParams);
-	  stack.add(newrc);
-        }
-        catch (InvocationTargetException e)
-        {
-          Throwable z = e.getTargetException();
-          if (z instanceof Error)
-            throw (Error)z;
-          else if (z instanceof RuntimeException)
-            throw (RuntimeException)z;
-          else
-            throw (ManifoldCFException)z;
-        }
-        catch (ClassNotFoundException e)
-        {
-          // If we get this exception, it may mean that the authority is not registered.
-          if (connMgr.isInstalled(className) == false)
-            return null;
-
-          throw new ManifoldCFException("No authority connector class '"+className+"' was found.",
-            e);
-        }
-        catch (NoSuchMethodException e)
-        {
-          throw new ManifoldCFException("No appropriate constructor for IAuthorityConnector implementation '"+
-            className+"'.  Need xxx(ConfigParams).",
-            e);
-        }
-        catch (SecurityException e)
-        {
-          throw new ManifoldCFException("Protected constructor for IAuthorityConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalAccessException e)
-        {
-          throw new ManifoldCFException("Unavailable constructor for IAuthorityConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalArgumentException e)
-        {
-          throw new ManifoldCFException("Shouldn't happen!!!",e);
-        }
-        catch (InstantiationException e)
-        {
-          throw new ManifoldCFException("InstantiationException for IAuthorityConnector implementation '"+className+"'",
-            e);
-        }
-        catch (ExceptionInInitializerError e)
-        {
-          throw new ManifoldCFException("ExceptionInInitializerError for IAuthorityConnector implementation '"+className+"'",
-            e);
-        }
-      }
-      
-      // Since thread context set can fail, do that before we remove it from the pool.
-      IAuthorityConnector rc = (IAuthorityConnector)stack.get(stack.size()-1);
-      rc.setThreadContext(threadContext);
-      stack.remove(stack.size()-1);
-      numFree--;
-
-      return rc;
-    }
-
-    /** Release a repository connector to the pool.
-    *@param connector is the connector.
-    */
-    public synchronized void releaseConnector(IAuthorityConnector connector)
-      throws ManifoldCFException
-    {
-      if (connector == null)
-        return;
-
-      // Make sure connector knows it's released
-      connector.clearThreadContext();
-      // Append
-      stack.add(connector);
-      numFree++;
-      notifyAll();
-    }
-
-    /** Notify all free connectors.
-    */
-    public synchronized void pollAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      int i = 0;
-      while (i < stack.size())
-      {
-        IConnector rc = (IConnector)stack.get(i++);
-        // Notify
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.poll();
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
-    /** Release all free connectors.
-    */
-    public synchronized void releaseAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (stack.size() > 0)
-      {
-        // Disconnect
-        IConnector rc = (IConnector)stack.get(stack.size()-1);
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.disconnect();
-          stack.remove(stack.size()-1);
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
+    thisFactory.closeThisAllConnectors(threadContext);
   }
 
-
-
 }
 

Modified: manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/MappingConnectorFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/MappingConnectorFactory.java?rev=1547500&r1=1547499&r2=1547500&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/MappingConnectorFactory.java (original)
+++ manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/MappingConnectorFactory.java Tue Dec  3 17:59:52 2013
@@ -26,14 +26,22 @@ import java.lang.reflect.*;
 
 /** This class manages a pool of mapping connectors.
 */
-public class MappingConnectorFactory
+public class MappingConnectorFactory extends ConnectorFactory<IMappingConnector>
 {
-  // Pool hash table.
-  // Keyed by PoolKey; value is Pool
-  protected static Map poolHash = new HashMap();
 
-  private MappingConnectorFactory()
+  // Static factory
+  protected final static MappingConnectorFactory thisFactory = new MappingConnectorFactory();
+
+  protected MappingConnectorFactory()
+  {
+  }
+
+  @Override
+  protected boolean isInstalled(IThreadContext tc, String className)
+    throws ManifoldCFException
   {
+    IMappingConnectorManager connMgr = MappingConnectorManagerFactory.make(tc);
+    return connMgr.isInstalled(className);
   }
 
   /** Install connector.
@@ -42,8 +50,7 @@ public class MappingConnectorFactory
   public static void install(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IMappingConnector connector = getConnectorNoCheck(className);
-    connector.install(threadContext);
+    thisFactory.installThis(threadContext,className);
   }
 
   /** Uninstall connector.
@@ -52,8 +59,7 @@ public class MappingConnectorFactory
   public static void deinstall(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IMappingConnector connector = getConnectorNoCheck(className);
-    connector.deinstall(threadContext);
+    thisFactory.deinstallThis(threadContext,className);
   }
 
   /** Output the configuration header section.
@@ -61,10 +67,7 @@ public class MappingConnectorFactory
   public static void outputConfigurationHeader(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, ArrayList tabsArray)
     throws ManifoldCFException, IOException
   {
-    IMappingConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationHeader(threadContext,out,locale,parameters,tabsArray);
+    thisFactory.outputThisConfigurationHeader(threadContext,className,out,locale,parameters,tabsArray);
   }
 
   /** Output the configuration body section.
@@ -72,10 +75,7 @@ public class MappingConnectorFactory
   public static void outputConfigurationBody(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
     throws ManifoldCFException, IOException
   {
-    IMappingConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationBody(threadContext,out,locale,parameters,tabName);
+    thisFactory.outputThisConfigurationBody(threadContext,className,out,locale,parameters,tabName);
   }
 
   /** Process configuration post data for a connector.
@@ -83,10 +83,7 @@ public class MappingConnectorFactory
   public static String processConfigurationPost(IThreadContext threadContext, String className, IPostParameters variableContext, Locale locale, ConfigParams configParams)
     throws ManifoldCFException
   {
-    IMappingConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return null;
-    return connector.processConfigurationPost(threadContext,variableContext,locale,configParams);
+    return thisFactory.processThisConfigurationPost(threadContext,className,variableContext,locale,configParams);
   }
   
   /** View connector configuration.
@@ -94,11 +91,7 @@ public class MappingConnectorFactory
   public static void viewConfiguration(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams configParams)
     throws ManifoldCFException, IOException
   {
-    IMappingConnector connector = getConnector(threadContext, className);
-    // We want to be able to view connections even if they have unregistered connectors.
-    if (connector == null)
-      return;
-    connector.viewConfiguration(threadContext,out,locale,configParams);
+    thisFactory.viewThisConfiguration(threadContext,className,out,locale,configParams);
   }
 
   /** Get a mapping connector instance, but do NOT check if class is installed first!
@@ -108,139 +101,7 @@ public class MappingConnectorFactory
   public static IMappingConnector getConnectorNoCheck(String className)
     throws ManifoldCFException
   {
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IMappingConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IMappingConnector.");
-      return (IMappingConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      throw new ManifoldCFException("No mapping connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IMappingConnector implementation '"+
-        className+"'.  Need xxx().",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-
-  }
-
-  /** Get a mapping connector instance.
-  *@param className is the class name.
-  *@return the instance.
-  */
-  protected static IMappingConnector getConnector(IThreadContext threadContext, String className)
-    throws ManifoldCFException
-  {
-    IMappingConnectorManager connMgr = MappingConnectorManagerFactory.make(threadContext);
-    if (connMgr.isInstalled(className) == false)
-      return null;
-
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IMappingConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IMappingConnector.");
-      return (IMappingConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      // If we get this exception, it may mean that the mapping is not registered.
-      if (connMgr.isInstalled(className) == false)
-        return null;
-
-      throw new ManifoldCFException("No mapping connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IMappingConnector implementation '"+
-        className+"'.  Need xxx().",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IMappingConnector implementation '"+className+"'",
-        e);
-    }
-
+    return thisFactory.getThisConnectorNoCheck(className);
   }
 
   /** Get a mapping connector.
@@ -254,26 +115,7 @@ public class MappingConnectorFactory
     String className, ConfigParams configInfo, int maxPoolSize)
     throws ManifoldCFException
   {
-    // We want to get handles off the pool and use them.  But the
-    // handles we fetch have to have the right config information.
-
-    // Use the classname and config info to build a pool key
-    PoolKey pk = new PoolKey(className,configInfo);
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-      if (p == null)
-      {
-        // Build it again, this time making a copy
-        pk = new PoolKey(className,configInfo.duplicate());
-        p = new Pool(pk,maxPoolSize);
-        poolHash.put(pk,p);
-      }
-    }
-
-    IMappingConnector rval = p.getConnector(threadContext);
-    return rval;
+    return thisFactory.grabThis(threadContext,className,configInfo,maxPoolSize);
   }
 
   /** Release a repository connector.
@@ -282,19 +124,7 @@ public class MappingConnectorFactory
   public static void release(IMappingConnector connector)
     throws ManifoldCFException
   {
-    if (connector == null)
-      return;
-
-    // Figure out which pool this goes on, and put it there
-    PoolKey pk = new PoolKey(connector.getClass().getName(),connector.getConfiguration());
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-    }
-
-    p.releaseConnector(connector);
-    // System.out.println("Done releasing");
+    thisFactory.releaseThis(connector);
   }
 
   /** Idle notification for inactive mapping connector handles.
@@ -303,17 +133,7 @@ public class MappingConnectorFactory
   public static void pollAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // Go through the whole pool and notify everyone
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.pollAll(threadContext);
-      }
-    }
-
+    thisFactory.pollThisAllConnectors(threadContext);
   }
 
   /** Clean up all open mapping connector handles.
@@ -324,257 +144,9 @@ public class MappingConnectorFactory
   public static void closeAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // Go through the whole pool and clean it out
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.releaseAll(threadContext);
-      }
-    }
-  }
-
-  /** This is an immutable pool key class, which describes a pool in terms of two independent keys.
-  */
-  public static class PoolKey
-  {
-    protected String className;
-    protected ConfigParams configInfo;
-
-    /** Constructor.
-    */
-    public PoolKey(String className, Map configInfo)
-    {
-      this.className = className;
-      this.configInfo = new ConfigParams(configInfo);
-    }
-
-    public PoolKey(String className, ConfigParams configInfo)
-    {
-      this.className = className;
-      this.configInfo = configInfo;
-    }
-
-    /** Get the class name.
-    *@return the class name.
-    */
-    public String getClassName()
-    {
-      return className;
-    }
-
-    /** Get the config info.
-    *@return the params
-    */
-    public ConfigParams getParams()
-    {
-      return configInfo;
-    }
-
-    /** Hash code.
-    */
-    public int hashCode()
-    {
-      return className.hashCode() + configInfo.hashCode();
-    }
-
-    /** Equals operator.
-    */
-    public boolean equals(Object o)
-    {
-      if (!(o instanceof PoolKey))
-        return false;
-
-      PoolKey pk = (PoolKey)o;
-      return pk.className.equals(className) && pk.configInfo.equals(configInfo);
-    }
-
-  }
-
-  /** This class represents a value in the pool hash, which corresponds to a given key.
-  */
-  public static class Pool
-  {
-    protected ArrayList stack = new ArrayList();
-    protected PoolKey key;
-    protected int numFree;
-
-    /** Constructor
-    */
-    public Pool(PoolKey pk, int maxCount)
-    {
-      key = pk;
-      numFree = maxCount;
-    }
-
-    /** Grab a mapping connector.
-    * If none exists, construct it using the information in the pool key.
-    *@return the connector.
-    */
-    public synchronized IMappingConnector getConnector(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (numFree == 0)
-      {
-        try
-        {
-          wait();
-        }
-        catch (InterruptedException e)
-        {
-          throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-        }
-      }
-
-      if (stack.size() == 0)
-      {
-        String className = key.getClassName();
-        ConfigParams configParams = key.getParams();
-
-        IMappingConnectorManager connMgr = MappingConnectorManagerFactory.make(threadContext);
-        if (connMgr.isInstalled(className) == false)
-          return null;
-
-        try
-        {
-          Class theClass = ManifoldCF.findClass(className);
-          Class[] argumentClasses = new Class[0];
-          // Look for a constructor
-          Constructor c = theClass.getConstructor(argumentClasses);
-          Object[] arguments = new Object[0];
-          Object o = c.newInstance(arguments);
-          if (!(o instanceof IMappingConnector))
-            throw new ManifoldCFException("Class '"+className+"' does not implement IMappingConnector.");
-          IMappingConnector newrc = (IMappingConnector)o;
-          newrc.connect(configParams);
-	  stack.add(newrc);
-        }
-        catch (InvocationTargetException e)
-        {
-          Throwable z = e.getTargetException();
-          if (z instanceof Error)
-            throw (Error)z;
-          else if (z instanceof RuntimeException)
-            throw (RuntimeException)z;
-          else
-            throw (ManifoldCFException)z;
-        }
-        catch (ClassNotFoundException e)
-        {
-          // If we get this exception, it may mean that the mapping is not registered.
-          if (connMgr.isInstalled(className) == false)
-            return null;
-
-          throw new ManifoldCFException("No mapping connector class '"+className+"' was found.",
-            e);
-        }
-        catch (NoSuchMethodException e)
-        {
-          throw new ManifoldCFException("No appropriate constructor for IMappingConnector implementation '"+
-            className+"'.  Need xxx(ConfigParams).",
-            e);
-        }
-        catch (SecurityException e)
-        {
-          throw new ManifoldCFException("Protected constructor for IMappingConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalAccessException e)
-        {
-          throw new ManifoldCFException("Unavailable constructor for IMappingConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalArgumentException e)
-        {
-          throw new ManifoldCFException("Shouldn't happen!!!",e);
-        }
-        catch (InstantiationException e)
-        {
-          throw new ManifoldCFException("InstantiationException for IMappingConnector implementation '"+className+"'",
-            e);
-        }
-        catch (ExceptionInInitializerError e)
-        {
-          throw new ManifoldCFException("ExceptionInInitializerError for IMappingConnector implementation '"+className+"'",
-            e);
-        }
-      }
-      
-      // Since thread context set can fail, do that before we remove it from the pool.
-      IMappingConnector rc = (IMappingConnector)stack.get(stack.size()-1);
-      rc.setThreadContext(threadContext);
-      stack.remove(stack.size()-1);
-      numFree--;
-
-      return rc;
-    }
-
-    /** Release a repository connector to the pool.
-    *@param connector is the connector.
-    */
-    public synchronized void releaseConnector(IMappingConnector connector)
-      throws ManifoldCFException
-    {
-      if (connector == null)
-        return;
-
-      // Make sure connector knows it's released
-      connector.clearThreadContext();
-      // Append
-      stack.add(connector);
-      numFree++;
-      notifyAll();
-    }
-
-    /** Notify all free connectors.
-    */
-    public synchronized void pollAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      int i = 0;
-      while (i < stack.size())
-      {
-        IConnector rc = (IConnector)stack.get(i++);
-        // Notify
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.poll();
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
-    /** Release all free connectors.
-    */
-    public synchronized void releaseAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (stack.size() > 0)
-      {
-        // Disconnect
-        IConnector rc = (IConnector)stack.get(stack.size()-1);
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.disconnect();
-          stack.remove(stack.size()-1);
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
+    thisFactory.closeThisAllConnectors(threadContext);
   }
 
 
-
 }
 

Modified: manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java?rev=1547500&r1=1547499&r2=1547500&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java (original)
+++ manifoldcf/branches/CONNECTORS-781/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/RepositoryConnectorFactory.java Tue Dec  3 17:59:52 2013
@@ -29,28 +29,75 @@ import java.lang.reflect.*;
 
 /** This is the factory class for IRepositoryConnector objects.
 */
-public class RepositoryConnectorFactory
+public class RepositoryConnectorFactory extends ConnectorFactory<IRepositoryConnector>
 {
   public static final String _rcsid = "@(#)$Id: RepositoryConnectorFactory.java 988245 2010-08-23 18:39:35Z kwright $";
 
-  // Pool hash table.
-  // Keyed by PoolKey; value is Pool
-  protected static Map poolHash = new HashMap();
-
-  // private static HashMap checkedOutConnectors = new HashMap();
+  // Static factory
+  protected final static RepositoryConnectorFactory thisFactory = new RepositoryConnectorFactory();
 
   private RepositoryConnectorFactory()
   {
   }
 
+  @Override
+  protected boolean isInstalled(IThreadContext tc, String className)
+    throws ManifoldCFException
+  {
+    IConnectorManager connMgr = ConnectorManagerFactory.make(tc);
+    return connMgr.isInstalled(className);
+  }
+
+  /** Get the activities supported by this connector.
+  *@param className is the class name.
+  *@return the list of activities.
+  */
+  protected String[] getThisActivitiesList(IThreadContext threadContext, String className)
+    throws ManifoldCFException
+  {
+    IRepositoryConnector connector = getThisConnector(threadContext, className);
+    if (connector == null)
+      return null;
+    String[] values = connector.getActivitiesList();
+    java.util.Arrays.sort(values);
+    return values;
+  }
+
+  /** Get the link types logged by this connector.
+  *@param className is the class name.
+  *@return the list of link types, in sorted order.
+  */
+  protected String[] getThisRelationshipTypes(IThreadContext threadContext, String className)
+    throws ManifoldCFException
+  {
+    IRepositoryConnector connector = getThisConnector(threadContext, className);
+    if (connector == null)
+      return null;
+    String[] values = connector.getRelationshipTypes();
+    java.util.Arrays.sort(values);
+    return values;
+  }
+
+  /** Get the operating mode for a connector.
+  *@param className is the class name.
+  *@return the connector operating model, as specified in IRepositoryConnector.
+  */
+  protected int getThisConnectorModel(IThreadContext threadContext, String className)
+    throws ManifoldCFException
+  {
+    IRepositoryConnector connector = getThisConnector(threadContext, className);
+    if (connector == null)
+      return -1;
+    return connector.getConnectorModel();
+  }
+
   /** Install connector.
   *@param className is the class name.
   */
   public static void install(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnectorNoCheck(className);
-    connector.install(threadContext);
+    thisFactory.installThis(threadContext,className);
   }
 
   /** Uninstall connector.
@@ -59,8 +106,7 @@ public class RepositoryConnectorFactory
   public static void deinstall(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnectorNoCheck(className);
-    connector.deinstall(threadContext);
+    thisFactory.deinstallThis(threadContext,className);
   }
 
   /** Get the activities supported by this connector.
@@ -70,12 +116,7 @@ public class RepositoryConnectorFactory
   public static String[] getActivitiesList(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return null;
-    String[] values = connector.getActivitiesList();
-    java.util.Arrays.sort(values);
-    return values;
+    return thisFactory.getThisActivitiesList(threadContext,className);
   }
 
   /** Get the link types logged by this connector.
@@ -85,12 +126,7 @@ public class RepositoryConnectorFactory
   public static String[] getRelationshipTypes(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return null;
-    String[] values = connector.getRelationshipTypes();
-    java.util.Arrays.sort(values);
-    return values;
+    return thisFactory.getThisRelationshipTypes(threadContext,className);
   }
 
   /** Get the operating mode for a connector.
@@ -100,10 +136,7 @@ public class RepositoryConnectorFactory
   public static int getConnectorModel(IThreadContext threadContext, String className)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return -1;
-    return connector.getConnectorModel();
+    return thisFactory.getThisConnectorModel(threadContext,className);
   }
 
   /** Output the configuration header section.
@@ -111,10 +144,7 @@ public class RepositoryConnectorFactory
   public static void outputConfigurationHeader(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, ArrayList tabsArray)
     throws ManifoldCFException, IOException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationHeader(threadContext,out,locale,parameters,tabsArray);
+    thisFactory.outputThisConfigurationHeader(threadContext,className,out,locale,parameters,tabsArray);
   }
 
   /** Output the configuration body section.
@@ -122,10 +152,7 @@ public class RepositoryConnectorFactory
   public static void outputConfigurationBody(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams parameters, String tabName)
     throws ManifoldCFException, IOException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return;
-    connector.outputConfigurationBody(threadContext,out,locale,parameters,tabName);
+    thisFactory.outputThisConfigurationBody(threadContext,className,out,locale,parameters,tabName);
   }
 
   /** Process configuration post data for a connector.
@@ -133,10 +160,7 @@ public class RepositoryConnectorFactory
   public static String processConfigurationPost(IThreadContext threadContext, String className, IPostParameters variableContext, Locale locale, ConfigParams configParams)
     throws ManifoldCFException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    if (connector == null)
-      return null;
-    return connector.processConfigurationPost(threadContext,variableContext,locale,configParams);
+    return thisFactory.processThisConfigurationPost(threadContext,className,variableContext,locale,configParams);
   }
   
   /** View connector configuration.
@@ -144,11 +168,7 @@ public class RepositoryConnectorFactory
   public static void viewConfiguration(IThreadContext threadContext, String className, IHTTPOutput out, Locale locale, ConfigParams configParams)
     throws ManifoldCFException, IOException
   {
-    IRepositoryConnector connector = getConnector(threadContext, className);
-    // We want to be able to view connections even if they have unregistered connectors.
-    if (connector == null)
-      return;
-    connector.viewConfiguration(threadContext,out,locale,configParams);
+    thisFactory.viewThisConfiguration(threadContext,className,out,locale,configParams);
   }
 
   /** Get a repository connector instance, without checking for installed connector.
@@ -158,140 +178,7 @@ public class RepositoryConnectorFactory
   public static IRepositoryConnector getConnectorNoCheck(String className)
     throws ManifoldCFException
   {
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IRepositoryConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IRepositoryConnector.");
-      return (IRepositoryConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      throw new ManifoldCFException("No repository connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IRepositoryConnector implementation '"+
-        className+"'.  Need xxx(ConfigParams).",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-
-  }
-
-  /** Get a repository connector instance.
-  *@param className is the class name.
-  *@return the instance.
-  */
-  protected static IRepositoryConnector getConnector(IThreadContext threadContext, String className)
-    throws ManifoldCFException
-  {
-    IConnectorManager connMgr = ConnectorManagerFactory.make(threadContext);
-    if (connMgr.isInstalled(className) == false)
-      return null;
-
-    try
-    {
-      Class theClass = ManifoldCF.findClass(className);
-      Class[] argumentClasses = new Class[0];
-      // Look for a constructor
-      Constructor c = theClass.getConstructor(argumentClasses);
-      Object[] arguments = new Object[0];
-      Object o = c.newInstance(arguments);
-      if (!(o instanceof IRepositoryConnector))
-        throw new ManifoldCFException("Class '"+className+"' does not implement IRepositoryConnector.");
-      return (IRepositoryConnector)o;
-    }
-    catch (InvocationTargetException e)
-    {
-      Throwable z = e.getTargetException();
-      if (z instanceof Error)
-        throw (Error)z;
-      else if (z instanceof RuntimeException)
-        throw (RuntimeException)z;
-      else
-        throw (ManifoldCFException)z;
-    }
-    catch (ClassNotFoundException e)
-    {
-      // This MAY mean that an existing connector has been uninstalled; check out this possibility!
-      // We return null because that is the signal that we cannot get a connector instance for that reason.
-      if (connMgr.isInstalled(className) == false)
-        return null;
-
-      throw new ManifoldCFException("No repository connector class '"+className+"' was found.",
-        e);
-    }
-    catch (NoSuchMethodException e)
-    {
-      throw new ManifoldCFException("No appropriate constructor for IRepositoryConnector implementation '"+
-        className+"'.  Need xxx(ConfigParams).",
-        e);
-    }
-    catch (SecurityException e)
-    {
-      throw new ManifoldCFException("Protected constructor for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalAccessException e)
-    {
-      throw new ManifoldCFException("Unavailable constructor for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new ManifoldCFException("Shouldn't happen!!!",e);
-    }
-    catch (InstantiationException e)
-    {
-      throw new ManifoldCFException("InstantiationException for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-    catch (ExceptionInInitializerError e)
-    {
-      throw new ManifoldCFException("ExceptionInInitializerError for IRepositoryConnector implementation '"+className+"'",
-        e);
-    }
-
+    return thisFactory.getThisConnectorNoCheck(className);
   }
 
   /** Get multiple repository connectors, all at once.  Do this in a particular order
@@ -301,54 +188,7 @@ public class RepositoryConnectorFactory
     String[] orderingKeys, String[] classNames, ConfigParams[] configInfos, int[] maxPoolSizes)
     throws ManifoldCFException
   {
-    IRepositoryConnector[] rval = new IRepositoryConnector[classNames.length];
-    HashMap orderMap = new HashMap();
-    int i = 0;
-    while (i < orderingKeys.length)
-    {
-      if (orderMap.get(orderingKeys[i]) != null)
-        throw new ManifoldCFException("Found duplicate order key");
-      orderMap.put(orderingKeys[i],new Integer(i));
-      i++;
-    }
-    java.util.Arrays.sort(orderingKeys);
-    i = 0;
-    while (i < orderingKeys.length)
-    {
-      String orderingKey = orderingKeys[i];
-      int index = ((Integer)orderMap.get(orderingKey)).intValue();
-      String className = classNames[index];
-      ConfigParams cp = configInfos[index];
-      int maxPoolSize = maxPoolSizes[index];
-      try
-      {
-        IRepositoryConnector connector = grab(threadContext,className,cp,maxPoolSize);
-        rval[index] = connector;
-      }
-      catch (Throwable e)
-      {
-        while (i > 0)
-        {
-          i--;
-          orderingKey = orderingKeys[i];
-          index = ((Integer)orderMap.get(orderingKey)).intValue();
-          try
-          {
-            release(rval[index]);
-          }
-          catch (ManifoldCFException e2)
-          {
-          }
-        }
-        if (e instanceof ManifoldCFException)
-          throw (ManifoldCFException)e;
-	else if (e instanceof RuntimeException)
-          throw (RuntimeException)e;
-        throw (Error)e;
-      }
-      i++;
-    }
-    return rval;
+    return thisFactory.grabThisMultiple(threadContext,orderingKeys,classNames,configInfos,maxPoolSizes);
   }
 
   /** Get a repository connector.
@@ -362,35 +202,7 @@ public class RepositoryConnectorFactory
     String className, ConfigParams configInfo, int maxPoolSize)
     throws ManifoldCFException
   {
-    // We want to get handles off the pool and use them.  But the
-    // handles we fetch have to have the right config information.
-
-    // Use the classname and config info to build a pool key.  This
-    // key will be discarded if we actually have to save a key persistently,
-    // since we avoid copying the configInfo unnecessarily.
-    PoolKey pk = new PoolKey(className,configInfo);
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-      if (p == null)
-      {
-        pk = new PoolKey(className,configInfo.duplicate());
-        p = new Pool(pk,maxPoolSize);
-        poolHash.put(pk,p);
-      }
-    }
-
-    IRepositoryConnector rval = p.getConnector(threadContext);
-
-    // Enter it in the pool so we can figure out whether it closed
-    // synchronized (checkedOutConnectors)
-    // {
-    //      checkedOutConnectors.put(rval.toString(),new ConnectorTracker(rval));
-    // }
-
-    return rval;
-
+    return thisFactory.grabThis(threadContext,className,configInfo,maxPoolSize);
   }
 
   /** Release multiple repository connectors.
@@ -398,23 +210,7 @@ public class RepositoryConnectorFactory
   public static void releaseMultiple(IRepositoryConnector[] connectors)
     throws ManifoldCFException
   {
-    int i = 0;
-    ManifoldCFException currentException = null;
-    while (i < connectors.length)
-    {
-      IRepositoryConnector c = connectors[i++];
-      try
-      {
-        release(c);
-      }
-      catch (ManifoldCFException e)
-      {
-        if (currentException == null)
-          currentException = e;
-      }
-    }
-    if (currentException != null)
-      throw currentException;
+    thisFactory.releaseThisMultiple(connectors);
   }
 
   /** Release a repository connector.
@@ -423,25 +219,7 @@ public class RepositoryConnectorFactory
   public static void release(IRepositoryConnector connector)
     throws ManifoldCFException
   {
-    // If the connector is null, skip the release, because we never really got the connector in the first place.
-    if (connector == null)
-      return;
-
-    // Figure out which pool this goes on, and put it there
-    PoolKey pk = new PoolKey(connector.getClass().getName(),connector.getConfiguration());
-    Pool p;
-    synchronized (poolHash)
-    {
-      p = (Pool)poolHash.get(pk);
-    }
-
-    p.releaseConnector(connector);
-
-    // synchronized (checkedOutConnectors)
-    // {
-    //      checkedOutConnectors.remove(connector.toString());
-    // }
-
+    thisFactory.releaseThis(connector);
   }
 
   /** Idle notification for inactive repository connector handles.
@@ -450,22 +228,7 @@ public class RepositoryConnectorFactory
   public static void pollAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // System.out.println("Pool stats:");
-
-    // Go through the whole pool and notify everyone
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.pollAll(threadContext);
-        //p.printStats();
-      }
-    }
-
-    // System.out.println("About to check if any repository connector instances have been abandoned...");
-    // checkConnectors(System.currentTimeMillis());
+    thisFactory.pollThisAllConnectors(threadContext);
   }
 
   /** Clean up all open repository connector handles.
@@ -476,301 +239,7 @@ public class RepositoryConnectorFactory
   public static void closeAllConnectors(IThreadContext threadContext)
     throws ManifoldCFException
   {
-    // Go through the whole pool and clean it out
-    synchronized (poolHash)
-    {
-      Iterator iter = poolHash.values().iterator();
-      while (iter.hasNext())
-      {
-        Pool p = (Pool)iter.next();
-        p.releaseAll(threadContext);
-      }
-    }
-  }
-
-  /** Track connection allocation */
-  // public static void checkConnectors(long currentTime)
-  // {
-  //      synchronized (checkedOutConnectors)
-  //      {
-  //              Iterator iter = checkedOutConnectors.keySet().iterator();
-  //              while (iter.hasNext())
-  //              {
-  //                      Object key = iter.next();
-  //                      ConnectorTracker ct = (ConnectorTracker)checkedOutConnectors.get(key);
-  //                      if (ct.hasExpired(currentTime))
-  //                              ct.printDetails();
-  //              }
-  //      }
-  // }
-
-  /** This is an immutable pool key class, which describes a pool in terms of two independent keys.
-  */
-  public static class PoolKey
-  {
-    protected String className;
-    protected ConfigParams configInfo;
-
-    /** Constructor.
-    */
-    public PoolKey(String className, Map configInfo)
-    {
-      this.className = className;
-      this.configInfo = new ConfigParams(configInfo);
-    }
-
-    public PoolKey(String className, ConfigParams configInfo)
-    {
-      this.className = className;
-      this.configInfo = configInfo;
-    }
-
-    /** Get the class name.
-    *@return the class name.
-    */
-    public String getClassName()
-    {
-      return className;
-    }
-
-    /** Get the config info.
-    *@return the params
-    */
-    public ConfigParams getParams()
-    {
-      return configInfo;
-    }
-
-    /** Hash code.
-    */
-    public int hashCode()
-    {
-      return className.hashCode() + configInfo.hashCode();
-    }
-
-    /** Equals operator.
-    */
-    public boolean equals(Object o)
-    {
-      if (!(o instanceof PoolKey))
-        return false;
-
-      PoolKey pk = (PoolKey)o;
-      return pk.className.equals(className) && pk.configInfo.equals(configInfo);
-    }
-
-  }
-
-  /** This class represents a value in the pool hash, which corresponds to a given key.
-  */
-  public static class Pool
-  {
-    protected ArrayList stack = new ArrayList();
-    protected PoolKey key;
-    protected int numFree;
-
-    /** Constructor
-    */
-    public Pool(PoolKey pk, int maxCount)
-    {
-      key = pk;
-      numFree = maxCount;
-    }
-
-    /** Grab a repository connector.
-    * If none exists, construct it using the information in the pool key.
-    *@return the connector, or null if no connector could be connected.
-    */
-    public synchronized IRepositoryConnector getConnector(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (numFree == 0)
-      {
-        try
-        {
-          wait();
-        }
-        catch (InterruptedException e)
-        {
-          throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-        }
-      }
-
-      if (stack.size() == 0)
-      {
-        String className = key.getClassName();
-        ConfigParams configParams = key.getParams();
-
-        IConnectorManager connMgr = ConnectorManagerFactory.make(threadContext);
-        if (connMgr.isInstalled(className) == false)
-          return null;
-
-        try
-        {
-          Class theClass = ManifoldCF.findClass(className);
-          Class[] argumentClasses = new Class[0];
-          // Look for a constructor
-          Constructor c = theClass.getConstructor(argumentClasses);
-          Object[] arguments = new Object[0];
-          Object o = c.newInstance(arguments);
-          if (!(o instanceof IRepositoryConnector))
-            throw new ManifoldCFException("Class '"+className+"' does not implement IRepositoryConnector.");
-          IRepositoryConnector newrc = (IRepositoryConnector)o;
-          newrc.connect(configParams);
-          stack.add(newrc);
-        }
-        catch (InvocationTargetException e)
-        {
-          Throwable z = e.getTargetException();
-          if (z instanceof Error)
-            throw (Error)z;
-          else if (z instanceof RuntimeException)
-            throw (RuntimeException)z;
-          else
-            throw (ManifoldCFException)z;
-        }
-        catch (ClassNotFoundException e)
-        {
-          // If we see this exception, it COULD mean that the connector was uninstalled, and we happened to get here
-          // after that occurred.
-          // We return null because that is the signal that we cannot get a connector instance for that reason.
-          if (connMgr.isInstalled(className) == false)
-            return null;
-
-          throw new ManifoldCFException("No repository connector class '"+className+"' was found.",
-            e);
-        }
-        catch (NoSuchMethodException e)
-        {
-          throw new ManifoldCFException("No appropriate constructor for IRepositoryConnector implementation '"+
-            className+"'.  Need xxx(ConfigParams).",
-            e);
-        }
-        catch (SecurityException e)
-        {
-          throw new ManifoldCFException("Protected constructor for IRepositoryConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalAccessException e)
-        {
-          throw new ManifoldCFException("Unavailable constructor for IRepositoryConnector implementation '"+className+"'",
-            e);
-        }
-        catch (IllegalArgumentException e)
-        {
-          throw new ManifoldCFException("Shouldn't happen!!!",e);
-        }
-        catch (InstantiationException e)
-        {
-          throw new ManifoldCFException("InstantiationException for IRepositoryConnector implementation '"+className+"'",
-            e);
-        }
-        catch (ExceptionInInitializerError e)
-        {
-          throw new ManifoldCFException("ExceptionInInitializerError for IRepositoryConnector implementation '"+className+"'",
-            e);
-        }
-      }
-
-      // Since thread context set can fail, do that before we remove it from the pool.
-      IRepositoryConnector rc = (IRepositoryConnector)stack.get(stack.size()-1);
-      rc.setThreadContext(threadContext);
-      stack.remove(stack.size()-1);
-      numFree--;
-
-      return rc;
-    }
-
-    /** Release a repository connector to the pool.
-    *@param connector is the connector.
-    */
-    public synchronized void releaseConnector(IRepositoryConnector connector)
-      throws ManifoldCFException
-    {
-      if (connector == null)
-        return;
-
-      // Make sure connector knows it's released
-      connector.clearThreadContext();
-      // Append
-      stack.add(connector);
-      numFree++;
-      notifyAll();
-    }
-
-    /** Notify all free connectors.
-    */
-    public synchronized void pollAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      int i = 0;
-      while (i < stack.size())
-      {
-        IConnector rc = (IConnector)stack.get(i++);
-        // Notify
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.poll();
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
-    /** Release all free connectors.
-    */
-    public synchronized void releaseAll(IThreadContext threadContext)
-      throws ManifoldCFException
-    {
-      while (stack.size() > 0)
-      {
-        // Disconnect
-        IConnector rc = (IConnector)stack.get(stack.size()-1);
-        rc.setThreadContext(threadContext);
-        try
-        {
-          rc.disconnect();
-          stack.remove(stack.size()-1);
-        }
-        finally
-        {
-          rc.clearThreadContext();
-        }
-      }
-    }
-
-    /** Print pool stats */
-    public synchronized void printStats()
-    {
-      System.out.println(" Class name = "+key.getClassName()+"; Number free = "+Integer.toString(numFree));
-    }
-  }
-
-
-  protected static class ConnectorTracker
-  {
-    protected IRepositoryConnector theConnector;
-    protected long checkoutTime;
-    protected Exception theTrace;
-
-    public ConnectorTracker(IRepositoryConnector theConnector)
-    {
-      this.theConnector = theConnector;
-      this.checkoutTime = System.currentTimeMillis();
-      this.theTrace = new Exception("Stack trace");
-    }
-
-    public boolean hasExpired(long currentTime)
-    {
-      return (checkoutTime + 300000L < currentTime);
-    }
-
-    public void printDetails()
-    {
-      Logging.threads.error("Connector instance may have been abandoned: "+theConnector.toString(),theTrace);
-    }
+    thisFactory.closeThisAllConnectors(threadContext);
   }
+
 }



Mime
View raw message