Author: kwright
Date: Wed Dec 4 23:42:37 2013
New Revision: 1547965
URL: http://svn.apache.org/r1547965
Log:
Peel out pool logic from OutputConnectorFactory and embed it locally in
OutputConnectorPool.
Modified:
manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/interfaces/OutputConnectorFactory.java
manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/outputconnectorpool/OutputConnectorPool.java
manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/editjob.jsp
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/execute.jsp
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewjob.jsp
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewoutput.jsp
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=1547965&r1=1547964&r2=1547965&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
Wed Dec 4 23:42:37 2013
@@ -135,73 +135,4 @@ public class OutputConnectorFactory exte
return thisFactory.getThisConnectorNoCheck(className);
}
- /** Get multiple output connectors, all at once. Do this in a particular
order
- * so that any connector exhaustion will not cause a deadlock.
- */
- public static IOutputConnector[] grabMultiple(IThreadContext threadContext,
- String[] orderingKeys, String[] classNames, ConfigParams[] configInfos,
int[] maxPoolSizes)
- throws ManifoldCFException
- {
- return
thisFactory.grabThisMultiple(threadContext,IOutputConnector.class,orderingKeys,classNames,configInfos,maxPoolSizes);
- }
-
- /** Get an output connector.
- * The connector is specified by its class and its parameters.
- *@param threadContext is the current thread context.
- *@param className is the name of the class to get a connector for.
- *@param configInfo are the name/value pairs constituting configuration info
- * for this class.
- */
- public static IOutputConnector grab(IThreadContext threadContext,
- String className, ConfigParams configInfo, int maxPoolSize)
- throws ManifoldCFException
- {
- return
thisFactory.grabThis(threadContext,className,configInfo,maxPoolSize);
- }
-
- /** Release multiple output connectors.
- */
- public static void releaseMultiple(IOutputConnector[] connectors)
- throws ManifoldCFException
- {
- thisFactory.releaseThisMultiple(connectors);
- }
-
- /** Release an output connector.
- *@param connector is the connector to release.
- */
- public static void release(IOutputConnector connector)
- throws ManifoldCFException
- {
- thisFactory.releaseThis(connector);
- }
-
- /** Idle notification for inactive output connector handles.
- * This method polls all inactive handles.
- */
- public static void pollAllConnectors(IThreadContext threadContext)
- throws ManifoldCFException
- {
- thisFactory.pollThisAllConnectors(threadContext);
- }
-
- /** Flush only those connector handles that are currently unused.
- */
- public static void flushUnusedConnectors(IThreadContext threadContext)
- throws ManifoldCFException
- {
- thisFactory.flushThisUnusedConnectors(threadContext);
- }
-
- /** Clean up all open output connector handles.
- * This method is called when the connector pool needs to be flushed,
- * to free resources.
- *@param threadContext is the local thread context.
- */
- public static void closeAllConnectors(IThreadContext threadContext)
- throws ManifoldCFException
- {
- thisFactory.closeThisAllConnectors(threadContext);
- }
-
}
Modified:
manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/outputconnectorpool/OutputConnectorPool.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/outputconnectorpool/OutputConnectorPool.java?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/outputconnectorpool/OutputConnectorPool.java
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/agents/src/main/java/org/apache/manifoldcf/agents/outputconnectorpool/OutputConnectorPool.java
Wed Dec 4 23:42:37 2013
@@ -32,6 +32,9 @@ public class OutputConnectorPool impleme
{
public static final String _rcsid = "@(#)$Id$";
+ /** Local connector pool */
+ protected final static LocalPool localPool = new LocalPool();
+
// This implementation is a place-holder for the real one, which will likely
fold in the pooling code
// as we strip it out of OutputConnectorFactory.
@@ -66,7 +69,7 @@ public class OutputConnectorPool impleme
configInfos[i] = outputConnections[i].getConfigParams();
maxPoolSizes[i] = outputConnections[i].getMaxConnections();
}
- return OutputConnectorFactory.grabMultiple(threadContext,
+ return localPool.grabMultiple(threadContext,
orderingKeys, classNames, configInfos, maxPoolSizes);
}
@@ -78,7 +81,7 @@ public class OutputConnectorPool impleme
public IOutputConnector grab(IOutputConnection outputConnection)
throws ManifoldCFException
{
- return OutputConnectorFactory.grab(threadContext,
outputConnection.getClassName(),
+ return localPool.grab(threadContext, outputConnection.getClassName(),
outputConnection.getConfigParams(),
outputConnection.getMaxConnections());
}
@@ -89,7 +92,7 @@ public class OutputConnectorPool impleme
public void releaseMultiple(IOutputConnector[] connectors)
throws ManifoldCFException
{
- OutputConnectorFactory.releaseMultiple(connectors);
+ localPool.releaseMultiple(connectors);
}
/** Release an output connector.
@@ -99,7 +102,7 @@ public class OutputConnectorPool impleme
public void release(IOutputConnector connector)
throws ManifoldCFException
{
- OutputConnectorFactory.release(connector);
+ localPool.release(connector);
}
/** Idle notification for inactive output connector handles.
@@ -109,7 +112,7 @@ public class OutputConnectorPool impleme
public void pollAllConnectors()
throws ManifoldCFException
{
- OutputConnectorFactory.pollAllConnectors(threadContext);
+ localPool.pollAllConnectors(threadContext);
}
/** Flush only those connector handles that are currently unused.
@@ -118,7 +121,7 @@ public class OutputConnectorPool impleme
public void flushUnusedConnectors()
throws ManifoldCFException
{
- OutputConnectorFactory.flushUnusedConnectors(threadContext);
+ localPool.flushUnusedConnectors(threadContext);
}
/** Clean up all open output connector handles.
@@ -129,7 +132,30 @@ public class OutputConnectorPool impleme
public void closeAllConnectors()
throws ManifoldCFException
{
- OutputConnectorFactory.closeAllConnectors(threadContext);
+ localPool.closeAllConnectors(threadContext);
}
+ /** Actual static output connector pool */
+ protected static class LocalPool extends
org.apache.manifoldcf.core.connectorpool.ConnectorPool<IOutputConnector>
+ {
+ public LocalPool()
+ {
+ }
+
+ @Override
+ protected boolean isInstalled(IThreadContext tc, String className)
+ throws ManifoldCFException
+ {
+ IOutputConnectorManager connectorManager =
OutputConnectorManagerFactory.make(tc);
+ return connectorManager.isInstalled(className);
+ }
+
+ public IOutputConnector[] grabMultiple(IThreadContext tc, String[]
orderingKeys, String[] classNames, ConfigParams[] configInfos, int[]
maxPoolSizes)
+ throws ManifoldCFException
+ {
+ return
grabMultiple(tc,IOutputConnector.class,orderingKeys,classNames,configInfos,maxPoolSizes);
+ }
+
+ }
+
}
Modified:
manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/connectorpool/ConnectorPool.java
Wed Dec 4 23:42:37 2013
@@ -41,11 +41,89 @@ public abstract class ConnectorPool<T ex
// Protected methods
- /** Override this method to instantiate a connector.
+ /** Override this method to hook into a connector manager.
*/
- protected abstract T createConnectorInstance(IThreadContext tc, String
className)
+ protected abstract boolean isInstalled(IThreadContext tc, String className)
throws ManifoldCFException;
+ /** Get a connector instance.
+ *@param className is the class name.
+ *@return the instance.
+ */
+ protected T createConnectorInstance(IThreadContext threadContext, String
className)
+ throws ManifoldCFException
+ {
+ if (!isInstalled(threadContext,className))
+ 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);
+ try
+ {
+ return (T)o;
+ }
+ catch (ClassCastException e)
+ {
+ throw new ManifoldCFException("Class '"+className+"' does not
implement IConnector.");
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable z = e.getTargetException();
+ if (z instanceof Error)
+ throw (Error)z;
+ else if (z instanceof RuntimeException)
+ throw (RuntimeException)z;
+ else if (z instanceof ManifoldCFException)
+ throw (ManifoldCFException)z;
+ else
+ throw new RuntimeException("Unknown exception type:
"+z.getClass().getName()+": "+z.getMessage(),z);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // Equivalent to the connector not being installed
+ return null;
+ //throw new ManifoldCFException("No connector class '"+className+"' was
found.",e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new ManifoldCFException("No appropriate constructor for IConnector
implementation '"+
+ className+"'. Need xxx(ConfigParams).",
+ e);
+ }
+ catch (SecurityException e)
+ {
+ throw new ManifoldCFException("Protected constructor for IConnector
implementation '"+className+"'",
+ e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ManifoldCFException("Unavailable constructor for IConnector
implementation '"+className+"'",
+ e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ManifoldCFException("Shouldn't happen!!!",e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new ManifoldCFException("InstantiationException for IConnector
implementation '"+className+"'",
+ e);
+ }
+ catch (ExceptionInInitializerError e)
+ {
+ throw new ManifoldCFException("ExceptionInInitializerError for
IConnector implementation '"+className+"'",
+ e);
+ }
+
+ }
+
/** Get multiple connectors, all at once. Do this in a particular order
* so that any connector exhaustion will not cause a deadlock.
*/
@@ -185,7 +263,7 @@ public abstract class ConnectorPool<T ex
/** Idle notification for inactive output connector handles.
* This method polls all inactive handles.
*/
- protected void pollAllConnectors(IThreadContext threadContext)
+ public void pollAllConnectors(IThreadContext threadContext)
throws ManifoldCFException
{
// System.out.println("Pool stats:");
@@ -205,7 +283,7 @@ public abstract class ConnectorPool<T ex
/** Flush only those connector handles that are currently unused.
*/
- protected void flushUnusedConnectors(IThreadContext threadContext)
+ public void flushUnusedConnectors(IThreadContext threadContext)
throws ManifoldCFException
{
closeAllConnectors(threadContext);
@@ -216,7 +294,7 @@ public abstract class ConnectorPool<T ex
* to free resources.
*@param threadContext is the local thread context.
*/
- protected void closeAllConnectors(IThreadContext threadContext)
+ public void closeAllConnectors(IThreadContext threadContext)
throws ManifoldCFException
{
// Go through the whole pool and clean it out
Modified:
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/editjob.jsp
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/editjob.jsp?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/editjob.jsp
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/editjob.jsp
Wed Dec 4 23:42:37 2013
@@ -36,6 +36,8 @@
IOutputConnectionManager outputMgr =
OutputConnectionManagerFactory.make(threadContext);
IOutputConnection[] outputList = outputMgr.getAllConnections();
+ IOutputConnectorPool outputConnectorPool =
OutputConnectorPoolFactory.make(threadContext);
+
// Figure out tab name
String tabName = variableContext.getParameter("tabname");
if (tabName == null || tabName.length() == 0)
@@ -404,8 +406,7 @@
<%
if (outputConnection != null)
{
- IOutputConnector outputConnector =
OutputConnectorFactory.grab(threadContext,outputConnection.getClassName(),outputConnection.getConfigParams(),
- outputConnection.getMaxConnections());
+ IOutputConnector outputConnector =
outputConnectorPool.grab(outputConnection);
if (outputConnector != null)
{
try
@@ -414,7 +415,7 @@
}
finally
{
- OutputConnectorFactory.release(outputConnector);
+ outputConnectorPool.release(outputConnector);
}
}
}
@@ -1272,8 +1273,7 @@
if (outputConnection != null)
{
- IOutputConnector outputConnector =
OutputConnectorFactory.grab(threadContext,outputConnection.getClassName(),outputConnection.getConfigParams(),
- outputConnection.getMaxConnections());
+ IOutputConnector outputConnector =
outputConnectorPool.grab(outputConnection);
if (outputConnector != null)
{
try
@@ -1282,7 +1282,7 @@
}
finally
{
- OutputConnectorFactory.release(outputConnector);
+ outputConnectorPool.release(outputConnector);
}
%>
<input type="hidden" name="outputpresent" value="true"/>
Modified:
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/execute.jsp
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/execute.jsp?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/execute.jsp
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/execute.jsp
Wed Dec 4 23:42:37 2013
@@ -51,6 +51,8 @@
IMappingConnectionManager mappingConnManager =
MappingConnectionManagerFactory.make(threadContext);
IOutputConnectionManager outputManager =
OutputConnectionManagerFactory.make(threadContext);
+ IOutputConnectorPool outputConnectorPool =
OutputConnectorPoolFactory.make(threadContext);
+
String type = variableContext.getParameter("type");
String op = variableContext.getParameter("op");
if (type != null && op != null && type.equals("connection"))
@@ -1028,8 +1030,7 @@
if (outputPresent && outputConnection
!= null)
{
- IOutputConnector
outputConnector = OutputConnectorFactory.grab(threadContext,
-
outputConnection.getClassName(),outputConnection.getConfigParams(),outputConnection.getMaxConnections());
+ IOutputConnector
outputConnector = outputConnectorPool.grab(outputConnection);
if (outputConnector != null)
{
try
@@ -1046,7 +1047,7 @@
}
finally
{
-
OutputConnectorFactory.release(outputConnector);
+
outputConnectorPool.release(outputConnector);
}
}
}
Modified:
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewjob.jsp
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewjob.jsp?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewjob.jsp
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewjob.jsp
Wed Dec 4 23:42:37 2013
@@ -70,6 +70,9 @@
IJobManager manager = JobManagerFactory.make(threadContext);
IOutputConnectionManager outputManager =
OutputConnectionManagerFactory.make(threadContext);
IRepositoryConnectionManager connManager =
RepositoryConnectionManagerFactory.make(threadContext);
+
+ IOutputConnectorPool outputConnectorPool =
OutputConnectorPoolFactory.make(threadContext);
+
String jobID = variableContext.getParameter("jobid");
IJobDescription job = manager.load(new Long(jobID));
if (job == null)
@@ -631,8 +634,7 @@
<%
if (outputConnection != null)
{
- IOutputConnector outputConnector =
OutputConnectorFactory.grab(threadContext,outputConnection.getClassName(),outputConnection.getConfigParams(),
- outputConnection.getMaxConnections());
+ IOutputConnector outputConnector =
outputConnectorPool.grab(outputConnection);
if (outputConnector != null)
{
try
@@ -641,7 +643,7 @@
}
finally
{
-
OutputConnectorFactory.release(outputConnector);
+
outputConnectorPool.release(outputConnector);
}
}
}
Modified:
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewoutput.jsp
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewoutput.jsp?rev=1547965&r1=1547964&r2=1547965&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewoutput.jsp
(original)
+++
manifoldcf/branches/CONNECTORS-781/framework/crawler-ui/src/main/webapp/viewoutput.jsp
Wed Dec 4 23:42:37 2013
@@ -78,6 +78,7 @@
IOutputConnectorManager connectorManager =
OutputConnectorManagerFactory.make(threadContext);
// Get the connection manager handle
IOutputConnectionManager connManager =
OutputConnectionManagerFactory.make(threadContext);
+ IOutputConnectorPool outputConnectorPool =
OutputConnectorPoolFactory.make(threadContext);
String connectionName = variableContext.getParameter("connname");
IOutputConnection connection = connManager.load(connectionName);
if (connection == null)
@@ -104,7 +105,7 @@
String connectionStatus;
try
{
- IOutputConnector c =
OutputConnectorFactory.grab(threadContext,className,parameters,maxCount);
+ IOutputConnector c =
outputConnectorPool.grab(connection);
if (c == null)
connectionStatus =
Messages.getString(pageContext.getRequest().getLocale(),"viewoutput.Connectorisnotinstalled");
else
@@ -115,7 +116,7 @@
}
finally
{
- OutputConnectorFactory.release(c);
+ outputConnectorPool.release(c);
}
}
}