You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2010/08/23 14:18:14 UTC
svn commit: r988101 [1/2] - in /incubator/lcf/trunk/modules/framework:
agents/org/apache/lcf/agents/ core/org/apache/lcf/core/
pull-agent/org/apache/lcf/authorities/ pull-agent/org/apache/lcf/crawler/
Author: kwright
Date: Mon Aug 23 12:18:13 2010
New Revision: 988101
URL: http://svn.apache.org/viewvc?rev=988101&view=rev
Log:
Commit patch submitted for ticket CONNECTORS-91. This is a minor reorganization of the command classes into a class hierarchy, which allows for better reuse of the functionality.
Added:
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java (with props)
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java (with props)
Modified:
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Install.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Register.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/RegisterOutput.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeAll.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeOutputs.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegister.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAll.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAllOutputs.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterOutput.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Uninstall.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/RegisterAuthority.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/SynchronizeAuthorities.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAllAuthorities.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAuthority.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ExportConfiguration.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ImportConfiguration.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/Register.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/SynchronizeConnectors.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/UnRegister.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/UnRegisterAll.java
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java Mon Aug 23 12:18:13 2010
@@ -18,22 +18,49 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-import java.lang.reflect.*;
-public class AgentRun
+/**
+ * Main agents process class
+ */
+public class AgentRun extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
public static final String agentShutdownSignal = "_AGENTRUN_";
- private AgentRun()
+ public AgentRun()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ ILockManager lockManager = LockManagerFactory.make(tc);
+ // Clear the agents shutdown signal.
+ lockManager.clearGlobalFlag(agentShutdownSignal);
+ Logging.root.info("Running...");
+ while (true)
+ {
+ // Any shutdown signal yet?
+ if (lockManager.checkGlobalFlag(agentShutdownSignal))
+ break;
+
+ // Start whatever agents need to be started
+ LCF.startAgents(tc);
+
+ try
+ {
+ LCF.sleep(5000);
+ }
+ catch (InterruptedException e)
+ {
+ break;
+ }
+ }
+ Logging.root.info("Shutting down...");
+ }
+
public static void main(String[] args)
{
@@ -45,31 +72,9 @@ public class AgentRun
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
- ILockManager lockManager = LockManagerFactory.make(tc);
- // Clear the agents shutdown signal.
- lockManager.clearGlobalFlag(agentShutdownSignal);
System.err.println("Running...");
- while (true)
- {
- // Any shutdown signal yet?
- if (lockManager.checkGlobalFlag(agentShutdownSignal))
- break;
-
- // Start whatever agents need to be started
- LCF.startAgents(tc);
-
- try
- {
- LCF.sleep(5000);
- }
- catch (InterruptedException e)
- {
- break;
- }
- }
+ AgentRun agentRun = new AgentRun();
+ agentRun.execute();
System.err.println("Shutting down...");
}
catch (LCFException e)
@@ -79,8 +84,4 @@ public class AgentRun
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java Mon Aug 23 12:18:13 2010
@@ -18,20 +18,27 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-import java.lang.reflect.*;
-public class AgentStop
+/**
+ * Stops the running agents process
+ */
+public class AgentStop extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private AgentStop()
+ public AgentStop()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ ILockManager lockManager = LockManagerFactory.make(tc);
+ lockManager.setGlobalFlag(AgentRun.agentShutdownSignal);
+ Logging.root.info("Shutdown signal sent");
+ }
+
public static void main(String[] args)
{
@@ -43,10 +50,8 @@ public class AgentStop
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- ILockManager lockManager = LockManagerFactory.make(tc);
- lockManager.setGlobalFlag(AgentRun.agentShutdownSignal);
+ AgentStop agentStop = new AgentStop();
+ agentStop.execute();
System.err.println("Shutdown signal sent");
}
catch (LCFException e)
@@ -55,8 +60,4 @@ public class AgentStop
System.exit(1);
}
}
-
-
-
-
}
Added: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,22 @@
+package org.apache.lcf.agents;
+
+import org.apache.lcf.agents.system.LCF;
+import org.apache.lcf.core.InitializationCommand;
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.interfaces.ThreadContextFactory;
+
+/**
+ * Parent class for most Initialization commands that are related to Agents
+ */
+public abstract class BaseAgentsInitializationCommand implements InitializationCommand
+{
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ doExecute(tc);
+ }
+
+ protected abstract void doExecute(IThreadContext tc) throws LCFException;
+}
Propchange: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/BaseAgentsInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Install.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Install.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Install.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Install.java Mon Aug 23 12:18:13 2010
@@ -18,13 +18,10 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-import java.lang.reflect.*;
-public class Install
+public class Install extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
@@ -32,6 +29,11 @@ public class Install
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.installTables(tc);
+ Logging.root.info("Agent tables installed");
+ }
public static void main(String[] args)
{
@@ -43,9 +45,8 @@ public class Install
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.installTables(tc);
+ Install install = new Install();
+ install.execute();
System.err.println("Agent tables installed");
}
catch (LCFException e)
@@ -54,5 +55,4 @@ public class Install
System.exit(1);
}
}
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Register.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Register.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Register.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Register.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,30 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class Register
+/**
+ * Use to register an agent by providing its class
+ */
+public class Register extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private Register()
+ private final String className;
+
+ public Register(String className)
{
+ this.className = className;
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IAgentManager mgr = AgentManagerFactory.make(tc);
+ mgr.registerAgent(className);
+ Logging.root.info("Successfully registered agent '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -43,10 +54,8 @@ public class Register
String className = args[0];
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAgentManager mgr = AgentManagerFactory.make(tc);
- mgr.registerAgent(className);
+ Register register = new Register(className);
+ register.execute();
System.err.println("Successfully registered agent '"+className+"'");
}
catch (LCFException e)
@@ -55,8 +64,4 @@ public class Register
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/RegisterOutput.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/RegisterOutput.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/RegisterOutput.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/RegisterOutput.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,40 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class RegisterOutput
+/**
+ * Register an output connector class
+ */
+public class RegisterOutput extends TransactionalAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private RegisterOutput()
+ private final String className;
+ private final String description;
+
+ public RegisterOutput(String className, String description)
{
+
+ this.className = className;
+ this.description = description;
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+ // First, register connector
+ mgr.registerConnector(description,className);
+ // Then, signal to all jobs that might depend on this connector that they can switch state
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For all connection names, notify all agents of the registration
+ AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
+ Logging.root.info("Successfully registered output connector '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -45,41 +66,8 @@ public class RegisterOutput
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
- IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // First, register connector
- mgr.registerConnector(description,className);
- // Then, signal to all jobs that might depend on this connector that they can switch state
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For all connection names, notify all agents of the registration
- AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
- }
- catch (LCFException e)
- {
- database.signalRollback();
- throw e;
- }
- catch (Error e)
- {
- database.signalRollback();
- throw e;
- }
- finally
- {
- database.endTransaction();
- }
-
+ RegisterOutput registerOutput = new RegisterOutput(className, description);
+ registerOutput.execute();
System.err.println("Successfully registered output connector '"+className+"'");
}
catch (LCFException e)
@@ -88,8 +76,4 @@ public class RegisterOutput
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeAll.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeAll.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeAll.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeAll.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,41 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class SynchronizeAll
+/**
+ * Un-register all registered agent classes that can't be found
+ */
+public class SynchronizeAll extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private SynchronizeAll()
+ public SynchronizeAll()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IAgentManager mgr = AgentManagerFactory.make(tc);
+ String[] classnames = mgr.getAllAgents();
+ int i = 0;
+ while (i < classnames.length)
+ {
+ String classname = classnames[i++];
+ try
+ {
+ AgentFactory.make(tc,classname);
+ }
+ catch (LCFException e)
+ {
+ // Couldn't instantiate the agent: Remove from database table
+ mgr.removeAgent(classname);
+ }
+ }
+ Logging.root.info("Successfully synchronized all agents");
+ }
public static void main(String[] args)
{
@@ -42,24 +64,8 @@ public class SynchronizeAll
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAgentManager mgr = AgentManagerFactory.make(tc);
- String[] classnames = mgr.getAllAgents();
- int i = 0;
- while (i < classnames.length)
- {
- String classname = classnames[i++];
- try
- {
- AgentFactory.make(tc,classname);
- }
- catch (LCFException e)
- {
- // Couldn't instantiate the agent: Remove from database table
- mgr.removeAgent(classname);
- }
- }
+ SynchronizeAll synchronizeAll = new SynchronizeAll();
+ synchronizeAll.execute();
System.err.println("Successfully synchronized all agents");
}
catch (LCFException e)
@@ -68,8 +74,4 @@ public class SynchronizeAll
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeOutputs.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeOutputs.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeOutputs.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/SynchronizeOutputs.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,71 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class SynchronizeOutputs
+/**
+ * Un-register all registered output connector classes that can't be found
+ */
+public class SynchronizeOutputs extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private SynchronizeOutputs()
+ public SynchronizeOutputs()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IDBInterface database = DBInterfaceFactory.make(tc,
+ LCF.getMasterDatabaseName(),
+ LCF.getMasterDatabaseUsername(),
+ LCF.getMasterDatabasePassword());
+ IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+ IResultSet classNames = mgr.getConnectors();
+ int i = 0;
+ while (i < classNames.getRowCount())
+ {
+ IResultRow row = classNames.getRow(i++);
+ String className = (String)row.getValue("classname");
+ try
+ {
+ OutputConnectorFactory.getConnectorNoCheck(className);
+ }
+ catch (LCFException e)
+ {
+ // Deregistration should be done in a transaction
+ database.beginTransaction();
+ try
+ {
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For all connection names, notify all agents of the deregistration
+ AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ mgr.removeConnector(className);
+ }
+ catch (LCFException e2)
+ {
+ database.signalRollback();
+ throw e2;
+ }
+ catch (Error e2)
+ {
+ database.signalRollback();
+ throw e2;
+ }
+ finally
+ {
+ database.endTransaction();
+ }
+ }
+ }
+ Logging.root.info("Successfully synchronized all outputs");
+ }
+
public static void main(String[] args)
{
@@ -42,53 +94,8 @@ public class SynchronizeOutputs
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
- IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
- IResultSet classNames = mgr.getConnectors();
- int i = 0;
- while (i < classNames.getRowCount())
- {
- IResultRow row = classNames.getRow(i++);
- String className = (String)row.getValue("classname");
- try
- {
- OutputConnectorFactory.getConnectorNoCheck(className);
- }
- catch (LCFException e)
- {
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For all connection names, notify all agents of the deregistration
- AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
- // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
- mgr.removeConnector(className);
- }
- catch (LCFException e2)
- {
- database.signalRollback();
- throw e2;
- }
- catch (Error e2)
- {
- database.signalRollback();
- throw e2;
- }
- finally
- {
- database.endTransaction();
- }
- }
- }
+ SynchronizeOutputs synchronizeOutputs = new SynchronizeOutputs();
+ synchronizeOutputs.execute();
System.err.println("Successfully synchronized all outputs");
}
catch (LCFException e)
@@ -97,8 +104,4 @@ public class SynchronizeOutputs
System.exit(1);
}
}
-
-
-
-
}
Added: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,44 @@
+package org.apache.lcf.agents;
+
+import org.apache.lcf.agents.system.LCF;
+import org.apache.lcf.core.InitializationCommand;
+import org.apache.lcf.core.interfaces.*;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class TransactionalAgentsInitializationCommand implements InitializationCommand
+{
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ IDBInterface database = DBInterfaceFactory.make(tc,
+ org.apache.lcf.agents.system.LCF.getMasterDatabaseName(),
+ org.apache.lcf.agents.system.LCF.getMasterDatabaseUsername(),
+ org.apache.lcf.agents.system.LCF.getMasterDatabasePassword());
+
+ try
+ {
+ database.beginTransaction();
+ doExecute(tc);
+ }
+ catch (LCFException e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ catch (Error e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ finally
+ {
+ database.endTransaction();
+ }
+
+ }
+
+ protected abstract void doExecute(IThreadContext tc) throws LCFException;
+}
Propchange: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/TransactionalAgentsInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegister.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegister.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegister.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegister.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,30 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class UnRegister
+/**
+ * Use to unregister an agent by providing its class
+ */
+public class UnRegister extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private UnRegister()
+ private final String className;
+
+ public UnRegister(String className)
{
+ this.className = className;
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IAgentManager mgr = AgentManagerFactory.make(tc);
+ mgr.unregisterAgent(className);
+ Logging.root.info("Successfully unregistered agent '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -44,10 +55,8 @@ public class UnRegister
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAgentManager mgr = AgentManagerFactory.make(tc);
- mgr.unregisterAgent(className);
+ UnRegister unRegister = new UnRegister(className);
+ unRegister.execute();
System.err.println("Successfully unregistered agent '"+className+"'");
}
catch (LCFException e)
@@ -56,8 +65,4 @@ public class UnRegister
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAll.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAll.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAll.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAll.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,33 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class UnRegisterAll
+/**
+ * Un-register all current agent classes
+ */
+public class UnRegisterAll extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private UnRegisterAll()
+ public UnRegisterAll()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IAgentManager mgr = AgentManagerFactory.make(tc);
+ String[] classnames = mgr.getAllAgents();
+ int i = 0;
+ while (i < classnames.length)
+ {
+ mgr.unregisterAgent(classnames[i++]);
+ }
+ Logging.root.info("Successfully unregistered all agents");
+ }
+
public static void main(String[] args)
{
@@ -42,15 +56,8 @@ public class UnRegisterAll
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAgentManager mgr = AgentManagerFactory.make(tc);
- String[] classnames = mgr.getAllAgents();
- int i = 0;
- while (i < classnames.length)
- {
- mgr.unregisterAgent(classnames[i++]);
- }
+ UnRegisterAll unRegisterAll = new UnRegisterAll();
+ unRegisterAll.execute();
System.err.println("Successfully unregistered all agents");
}
catch (LCFException e)
@@ -59,8 +66,4 @@ public class UnRegisterAll
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAllOutputs.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAllOutputs.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAllOutputs.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterAllOutputs.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,64 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class UnRegisterAllOutputs
+/**
+ * Un-register all current output connector classes
+ */
+public class UnRegisterAllOutputs extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private UnRegisterAllOutputs()
+ public UnRegisterAllOutputs()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IDBInterface database = DBInterfaceFactory.make(tc,
+ LCF.getMasterDatabaseName(),
+ LCF.getMasterDatabaseUsername(),
+ LCF.getMasterDatabasePassword());
+ IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+ IResultSet classNames = mgr.getConnectors();
+ int i = 0;
+ while (i < classNames.getRowCount())
+ {
+ IResultRow row = classNames.getRow(i++);
+ String className = (String)row.getValue("classname");
+ // Deregistration should be done in a transaction
+ database.beginTransaction();
+ try
+ {
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For all connection names, notify all agents of the deregistration
+ AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ mgr.unregisterConnector(className);
+ }
+ catch (LCFException e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ catch (Error e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ finally
+ {
+ database.endTransaction();
+ }
+ }
+ Logging.root.info("Successfully unregistered all output connectors");
+ }
+
public static void main(String[] args)
{
@@ -42,46 +87,8 @@ public class UnRegisterAllOutputs
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
- IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
- IResultSet classNames = mgr.getConnectors();
- int i = 0;
- while (i < classNames.getRowCount())
- {
- IResultRow row = classNames.getRow(i++);
- String className = (String)row.getValue("classname");
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For all connection names, notify all agents of the deregistration
- AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
- // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
- mgr.unregisterConnector(className);
- }
- catch (LCFException e)
- {
- database.signalRollback();
- throw e;
- }
- catch (Error e)
- {
- database.signalRollback();
- throw e;
- }
- finally
- {
- database.endTransaction();
- }
- }
+ UnRegisterAllOutputs unRegisterAllOutputs = new UnRegisterAllOutputs();
+ unRegisterAllOutputs.execute();
System.err.println("Successfully unregistered all output connectors");
}
catch (LCFException e)
@@ -90,8 +97,4 @@ public class UnRegisterAllOutputs
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterOutput.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterOutput.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterOutput.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/UnRegisterOutput.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,36 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-public class UnRegisterOutput
+/**
+ * Un-register an output connector class
+ */
+public class UnRegisterOutput extends TransactionalAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private UnRegisterOutput()
+ private final String className;
+
+ public UnRegisterOutput(String className)
{
+ this.className = className;
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For all connection names, notify all agents of the deregistration
+ AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ mgr.unregisterConnector(className);
+ Logging.root.info("Successfully unregistered output connector '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -44,39 +61,8 @@ public class UnRegisterOutput
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
- IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For all connection names, notify all agents of the deregistration
- AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
- // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
- mgr.unregisterConnector(className);
- }
- catch (LCFException e)
- {
- database.signalRollback();
- throw e;
- }
- catch (Error e)
- {
- database.signalRollback();
- throw e;
- }
- finally
- {
- database.endTransaction();
- }
+ UnRegisterOutput unRegisterOutput = new UnRegisterOutput(className);
+ unRegisterOutput.execute();
System.err.println("Successfully unregistered output connector '"+className+"'");
}
catch (LCFException e)
@@ -85,8 +71,4 @@ public class UnRegisterOutput
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Uninstall.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Uninstall.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Uninstall.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/Uninstall.java Mon Aug 23 12:18:13 2010
@@ -18,20 +18,25 @@
*/
package org.apache.lcf.agents;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.agents.system.*;
-import java.lang.reflect.*;
-public class Uninstall
+/**
+ * Use to uninstall the agent. Results in cleaning up the persistent storage.
+ */
+public class Uninstall extends BaseAgentsInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private Uninstall()
+ public Uninstall()
{
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.deinstallTables(tc);
+ Logging.root.info("Agent tables uninstalled");
+ }
public static void main(String[] args)
{
@@ -43,9 +48,8 @@ public class Uninstall
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.deinstallTables(tc);
+ Uninstall uninstall = new Uninstall();
+ uninstall.execute();
System.err.println("Agent tables uninstalled");
}
catch (LCFException e)
@@ -54,5 +58,4 @@ public class Uninstall
System.exit(1);
}
}
-
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java Mon Aug 23 12:18:13 2010
@@ -1,36 +1,63 @@
/* $Id$ */
/**
-* 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.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.lcf.core;
-import java.io.*;
-import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.core.system.*;
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.system.LCF;
+import org.apache.lcf.core.system.Logging;
-public class DBCreate
+/**
+ * Create the database using the name as specified through the {@see LCF}. The username and password for the
+ * configured database need to be specified during construction.
+ */
+public class DBCreate extends DBInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private DBCreate()
+ /**
+ * The userName and password for the database to be created
+ *
+ * @param userName String containing the mandatory database username
+ * @param password String containing the mandatory database password
+ */
+ public DBCreate(String userName, String password)
{
+ super(userName, password);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.createSystemDatabase(tc, getUserName(), getPassword());
+ Logging.root.info("LCF database created");
+ }
+
+ /**
+ * Useful when running this class standalone. Provide two arguments, the first is the username, the second
+ * the password. The password is optional, an empty string is used as the default password.
+ *
+ * @param args String[] containing the arguments
+ */
public static void main(String[] args)
{
if (args.length != 1 && args.length != 2)
@@ -42,12 +69,15 @@ public class DBCreate
String userName = args[0];
String password = "";
if (args.length == 2)
+ {
password = args[1];
+ }
+
+ DBCreate dbCreate = new DBCreate(userName, password);
+
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.createSystemDatabase(tc,userName,password);
+ dbCreate.execute();
System.err.println("LCF database created");
}
catch (LCFException e)
@@ -58,6 +88,4 @@ public class DBCreate
}
-
-
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java Mon Aug 23 12:18:13 2010
@@ -1,54 +1,79 @@
/* $Id$ */
/**
-* 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.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.lcf.core;
-import java.io.*;
-import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.core.system.*;
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.system.LCF;
+import org.apache.lcf.core.system.Logging;
-public class DBDrop
+/**
+ * Drop the database using the name as specified through the {@see LCF}. The username and password for the
+ * configured database need to be specified during construction.
+ */
+public class DBDrop extends DBInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private DBDrop()
+ /**
+ * The userName and password for the database to be dropped
+ *
+ * @param userName String containing the mandatory database username
+ * @param password String containing the mandatory database password
+ */
+ public DBDrop(String userName, String password)
{
+ super(userName, password);
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.dropSystemDatabase(tc, getUserName(), getPassword());
+ Logging.root.info("LCF database dropped");
+ }
+ /**
+ * Useful when running this class standalone. Provide two arguments, the first is the username, the second
+ * the password. The password is optional, an empty string is used as the default password.
+ *
+ * @param args String[] containing the arguments
+ */
public static void main(String[] args)
{
if (args.length != 1 && args.length != 2)
{
- System.err.println("Usage: DBCreate <dbuser> [<dbpassword>]");
+ System.err.println("Usage: DBDrop <dbuser> [<dbpassword>]");
System.exit(1);
}
String userName = args[0];
String password = "";
if (args.length == 2)
+ {
password = args[1];
+ }
+
+ DBDrop dbDrop = new DBDrop(userName, password);
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.dropSystemDatabase(tc,userName,password);
+ dbDrop.execute();
System.err.println("LCF database dropped");
}
catch (LCFException e)
@@ -57,8 +82,4 @@ public class DBDrop
System.exit(1);
}
}
-
-
-
-
}
Added: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,50 @@
+package org.apache.lcf.core;
+
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.interfaces.ThreadContextFactory;
+import org.apache.lcf.core.system.LCF;
+
+/**
+ * Parent class for all database initialization related commands. This class provides methods to
+ * obtain username and password for the database.
+ *
+ * @author Jettro Coenradie
+ */
+public abstract class DBInitializationCommand implements InitializationCommand
+{
+ private final String userName;
+ private final String password;
+
+ /**
+ * The userName and password for the database on which the command needs to be performed
+ *
+ * @param userName String containing the mandatory database username
+ * @param password String containing the mandatory database password
+ */
+ public DBInitializationCommand(String userName, String password)
+ {
+ this.userName = userName;
+ this.password = password;
+ }
+
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ doExecute(tc);
+ }
+
+ protected abstract void doExecute(IThreadContext tc) throws LCFException;
+
+ protected String getPassword()
+ {
+ return password;
+ }
+
+ protected String getUserName()
+ {
+ return userName;
+ }
+
+}
Propchange: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,21 @@
+package org.apache.lcf.core;
+
+import org.apache.lcf.core.interfaces.LCFException;
+
+/**
+ * Interface for commands that initialize state of the connector framework. Among implementations available are:
+ * - Database creation
+ * - Registrations of agent
+ * - Registrations of connectors
+ *
+ * @author Jettro Coenradie
+ */
+public interface InitializationCommand
+{
+ /**
+ * Execute the command.
+ *
+ * @throws LCFException Thrown if the execution fails
+ */
+ void execute() throws LCFException;
+}
Propchange: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/InitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java Mon Aug 23 12:18:13 2010
@@ -21,70 +21,96 @@ import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.core.system.*;
-public class LockClean
+/**
+ * LCF makes use of a synchronization directory to store data about the current state of the synchronization between
+ * the repository connection and the output connection. This class is used to clear this directory.
+ */
+public class LockClean implements InitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private LockClean()
+ public LockClean()
{
}
-
- public static void main(String[] args)
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() throws LCFException
{
- if (args.length != 0)
+ LCF.initializeEnvironment();
+ String synchDir = LCF.getProperty(org.apache.lcf.core.lockmanager.LockManager.synchDirectoryProperty);
+ if (synchDir != null)
{
- System.err.println("Usage: LockClean");
- System.exit(1);
- }
-
- try
- {
- LCF.initializeEnvironment();
- String synchDir = LCF.getProperty(org.apache.lcf.core.lockmanager.LockManager.synchDirectoryProperty);
- if (synchDir != null)
+ // Recursively clean up the contents of the synch directory. But don't remove the directory itself
+ File dir = new File(synchDir);
+ if (dir.isDirectory())
{
- // Recursively clean up the contents of the synch directory.
- File dir = new File(synchDir);
- if (dir.isDirectory())
- {
- File[] files = dir.listFiles();
- int i = 0;
- while (i < files.length)
- {
- if (files[i].isDirectory())
- removeDirectory(files[i]);
- else
- files[i].delete();
- i++;
- }
- }
+ removeContentsOfDirectory(dir);
}
- System.err.println("Synchronization storage cleaned up");
- }
- catch (LCFException e)
- {
- e.printStackTrace(System.err);
- System.exit(2);
}
+ Logging.root.info("Synchronization storage cleaned up");
}
-
- protected static void removeDirectory(File directory)
+ /**
+ * Removes the contents of the directory but not the directory itself.
+ *
+ * @param directory File representing the directory to remove
+ */
+ private void removeContentsOfDirectory(File directory)
{
File[] files = directory.listFiles();
int i = 0;
while (i < files.length)
{
if (files[i].isDirectory())
+ {
removeDirectory(files[i]);
+ }
else
+ {
files[i].delete();
+ }
i++;
}
+ }
+
+ /**
+ * Removes the contents of the directory as well as the directory itself.
+ *
+ * @param directory File representing the directory to completely remove
+ */
+ private void removeDirectory(File directory)
+ {
+ removeContentsOfDirectory(directory);
// Remove the directory itself
directory.delete();
}
+ /**
+ * Useful when running this class standalone. You should not provide any arguments
+ *
+ * @param args String[] containing the arguments
+ */
+ public static void main(String[] args)
+ {
+ if (args.length != 0)
+ {
+ System.err.println("Usage: LockClean");
+ System.exit(1);
+ }
+
+ LockClean lockClean = new LockClean();
+ try
+ {
+ lockClean.execute();
+ System.err.println("Synchronization storage cleaned up");
+ }
+ catch (LCFException e)
+ {
+ e.printStackTrace(System.err);
+ System.exit(2);
+ }
+ }
}
Added: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,26 @@
+package org.apache.lcf.authorities;
+
+import org.apache.lcf.authorities.interfaces.AuthorityConnectorManagerFactory;
+import org.apache.lcf.authorities.interfaces.IAuthorityConnectorManager;
+import org.apache.lcf.authorities.system.LCF;
+import org.apache.lcf.core.InitializationCommand;
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.interfaces.ThreadContextFactory;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class BaseAuthoritiesInitializationCommand implements InitializationCommand
+{
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
+
+ doExecute(mgr);
+ }
+
+ protected abstract void doExecute(IAuthorityConnectorManager mgr) throws LCFException;
+}
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/BaseAuthoritiesInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/RegisterAuthority.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/RegisterAuthority.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/RegisterAuthority.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/RegisterAuthority.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,28 @@
*/
package org.apache.lcf.authorities;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.authorities.interfaces.*;
import org.apache.lcf.authorities.system.*;
-public class RegisterAuthority
+public class RegisterAuthority extends BaseAuthoritiesInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private RegisterAuthority()
+ private final String className;
+ private final String description;
+
+ public RegisterAuthority(String className, String description)
{
+ this.className = className;
+ this.description = description;
}
+ protected void doExecute(IAuthorityConnectorManager mgr) throws LCFException
+ {
+ mgr.registerConnector(description,className);
+ Logging.root.info("Successfully registered connector '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -45,10 +54,8 @@ public class RegisterAuthority
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
- mgr.registerConnector(description,className);
+ RegisterAuthority registerAuthority = new RegisterAuthority(className,description);
+ registerAuthority.execute();
System.err.println("Successfully registered connector '"+className+"'");
}
catch (LCFException e)
@@ -57,8 +64,4 @@ public class RegisterAuthority
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/SynchronizeAuthorities.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/SynchronizeAuthorities.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/SynchronizeAuthorities.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/SynchronizeAuthorities.java Mon Aug 23 12:18:13 2010
@@ -23,15 +23,36 @@ import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.authorities.interfaces.*;
import org.apache.lcf.authorities.system.*;
-public class SynchronizeAuthorities
+public class SynchronizeAuthorities extends BaseAuthoritiesInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private SynchronizeAuthorities()
+ public SynchronizeAuthorities()
{
}
+ protected void doExecute(IAuthorityConnectorManager mgr) throws LCFException
+ {
+ IResultSet classNames = mgr.getConnectors();
+ int i = 0;
+ while (i < classNames.getRowCount())
+ {
+ IResultRow row = classNames.getRow(i++);
+ String classname = (String)row.getValue("classname");
+ try
+ {
+ AuthorityConnectorFactory.getConnectorNoCheck(classname);
+ }
+ catch (LCFException e)
+ {
+ mgr.removeConnector(classname);
+ }
+ }
+ Logging.root.info("Successfully synchronized all authorities");
+ }
+
+
public static void main(String[] args)
{
if (args.length > 0)
@@ -43,24 +64,8 @@ public class SynchronizeAuthorities
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
- IResultSet classNames = mgr.getConnectors();
- int i = 0;
- while (i < classNames.getRowCount())
- {
- IResultRow row = classNames.getRow(i++);
- String classname = (String)row.getValue("classname");
- try
- {
- AuthorityConnectorFactory.getConnectorNoCheck(classname);
- }
- catch (LCFException e)
- {
- mgr.removeConnector(classname);
- }
- }
+ SynchronizeAuthorities synchronizeAuthorities = new SynchronizeAuthorities();
+ synchronizeAuthorities.execute();
System.err.println("Successfully synchronized all authorities");
}
catch (LCFException e)
@@ -69,8 +74,4 @@ public class SynchronizeAuthorities
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAllAuthorities.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAllAuthorities.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAllAuthorities.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAllAuthorities.java Mon Aug 23 12:18:13 2010
@@ -23,7 +23,7 @@ import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.authorities.interfaces.*;
import org.apache.lcf.authorities.system.*;
-public class UnRegisterAllAuthorities
+public class UnRegisterAllAuthorities extends BaseAuthoritiesInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
@@ -31,6 +31,18 @@ public class UnRegisterAllAuthorities
{
}
+ protected void doExecute(IAuthorityConnectorManager mgr) throws LCFException
+ {
+ IResultSet classNames = mgr.getConnectors();
+ int i = 0;
+ while (i < classNames.getRowCount())
+ {
+ IResultRow row = classNames.getRow(i++);
+ mgr.unregisterConnector((String)row.getValue("classname"));
+ }
+ Logging.root.info("Successfully unregistered all connectors");
+ }
+
public static void main(String[] args)
{
@@ -43,16 +55,8 @@ public class UnRegisterAllAuthorities
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
- IResultSet classNames = mgr.getConnectors();
- int i = 0;
- while (i < classNames.getRowCount())
- {
- IResultRow row = classNames.getRow(i++);
- mgr.unregisterConnector((String)row.getValue("classname"));
- }
+ UnRegisterAllAuthorities unRegisterAllAuthorities = new UnRegisterAllAuthorities();
+ unRegisterAllAuthorities.execute();
System.err.println("Successfully unregistered all connectors");
}
catch (LCFException e)
@@ -61,8 +65,4 @@ public class UnRegisterAllAuthorities
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAuthority.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAuthority.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAuthority.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/UnRegisterAuthority.java Mon Aug 23 12:18:13 2010
@@ -23,14 +23,22 @@ import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.authorities.interfaces.*;
import org.apache.lcf.authorities.system.*;
-public class UnRegisterAuthority
+public class UnRegisterAuthority extends BaseAuthoritiesInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private UnRegisterAuthority()
+ private final String className;
+
+ public UnRegisterAuthority(String className)
{
+ this.className = className;
}
+ protected void doExecute(IAuthorityConnectorManager mgr) throws LCFException
+ {
+ mgr.unregisterConnector(className);
+ Logging.root.info("Successfully unregistered connector '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -44,10 +52,8 @@ public class UnRegisterAuthority
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
- mgr.unregisterConnector(className);
+ UnRegisterAuthority unRegisterAuthority = new UnRegisterAuthority(className);
+ unRegisterAuthority.execute();
System.err.println("Successfully unregistered connector '"+className+"'");
}
catch (LCFException e)
@@ -56,8 +62,4 @@ public class UnRegisterAuthority
System.exit(1);
}
}
-
-
-
-
}
Added: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,23 @@
+package org.apache.lcf.crawler;
+
+import org.apache.lcf.core.InitializationCommand;
+import org.apache.lcf.core.interfaces.IThreadContext;
+import org.apache.lcf.core.interfaces.LCFException;
+import org.apache.lcf.core.interfaces.ThreadContextFactory;
+import org.apache.lcf.crawler.system.LCF;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class BaseCrawlerInitializationCommand implements InitializationCommand
+{
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ doExecute(tc);
+ }
+
+ protected abstract void doExecute(IThreadContext tc) throws LCFException;
+
+}
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/BaseCrawlerInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ExportConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ExportConfiguration.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ExportConfiguration.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ExportConfiguration.java Mon Aug 23 12:18:13 2010
@@ -18,20 +18,27 @@
*/
package org.apache.lcf.crawler;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.crawler.interfaces.*;
import org.apache.lcf.crawler.system.*;
-import java.util.*;
-/** This class provides a script hook to export the crawler configuration to a file.
-*/
-public class ExportConfiguration
+/**
+ * This class provides a script hook to export the crawler configuration to a file.
+ */
+public class ExportConfiguration extends BaseCrawlerInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private ExportConfiguration()
+ private final String exportFilename;
+
+ public ExportConfiguration(String exportFilename)
{
+ this.exportFilename = exportFilename;
+ }
+
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.exportConfiguration(tc,exportFilename);
+ Logging.root.info("Configuration exported");
}
public static void main(String[] args)
@@ -44,12 +51,10 @@ public class ExportConfiguration
String exportFilename = args[0];
-
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.exportConfiguration(tc,exportFilename);
+ ExportConfiguration exportConfiguration = new ExportConfiguration(exportFilename);
+ exportConfiguration.execute();
System.err.println("Configuration exported");
}
catch (Exception e)
@@ -58,5 +63,4 @@ public class ExportConfiguration
System.exit(2);
}
}
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ImportConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ImportConfiguration.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ImportConfiguration.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/ImportConfiguration.java Mon Aug 23 12:18:13 2010
@@ -18,20 +18,27 @@
*/
package org.apache.lcf.crawler;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
-import org.apache.lcf.crawler.interfaces.*;
import org.apache.lcf.crawler.system.*;
-import java.util.*;
-/** This class provides a script hook to allow import of crawler configuration information from a file.
-*/
-public class ImportConfiguration
+/**
+ * This class provides a script hook to allow import of crawler configuration information from a file.
+ */
+public class ImportConfiguration extends BaseCrawlerInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private ImportConfiguration()
+ private final String importFilename;
+
+ public ImportConfiguration(String importFilename)
{
+ this.importFilename = importFilename;
+ }
+
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ LCF.importConfiguration(tc,importFilename);
+ Logging.root.info("Configuration imported");
}
public static void main(String[] args)
@@ -44,12 +51,10 @@ public class ImportConfiguration
String importFilename = args[0];
-
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- LCF.importConfiguration(tc,importFilename);
+ ImportConfiguration importConfiguration = new ImportConfiguration(importFilename);
+ importConfiguration.execute();
System.err.println("Configuration imported");
}
catch (Exception e)
@@ -58,5 +63,4 @@ public class ImportConfiguration
System.exit(2);
}
}
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/Register.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/Register.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/Register.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/Register.java Mon Aug 23 12:18:13 2010
@@ -18,19 +18,41 @@
*/
package org.apache.lcf.crawler;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.crawler.interfaces.*;
import org.apache.lcf.crawler.system.*;
-public class Register
+/**
+ * Register a repository connector class
+ */
+public class Register extends TransactionalCrawlerInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private Register()
+ private final String className;
+ private final String description;
+
+ private Register(String className, String description)
{
+ this.className = className;
+ this.description = description;
}
+ protected void doExecute(IThreadContext tc) throws LCFException
+ {
+ IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+ IJobManager jobManager = JobManagerFactory.make(tc);
+ IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+ // First, register connector
+ mgr.registerConnector(description,className);
+ // Then, signal to all jobs that might depend on this connector that they can switch state
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For each connection name, modify the jobs to note that the connector is now installed
+ jobManager.noteConnectorRegistration(connectionNames);
+
+ Logging.root.info("Successfully registered connector '"+className+"'");
+ }
public static void main(String[] args)
{
@@ -45,42 +67,8 @@ public class Register
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IConnectorManager mgr = ConnectorManagerFactory.make(tc);
- IJobManager jobManager = JobManagerFactory.make(tc);
- IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // First, register connector
- mgr.registerConnector(description,className);
- // Then, signal to all jobs that might depend on this connector that they can switch state
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For each connection name, modify the jobs to note that the connector is now installed
- jobManager.noteConnectorRegistration(connectionNames);
- }
- catch (LCFException e)
- {
- database.signalRollback();
- throw e;
- }
- catch (Error e)
- {
- database.signalRollback();
- throw e;
- }
- finally
- {
- database.endTransaction();
- }
-
+ Register register = new Register(className,description);
+ register.execute();
System.err.println("Successfully registered connector '"+className+"'");
}
catch (LCFException e)
@@ -89,8 +77,4 @@ public class Register
System.exit(1);
}
}
-
-
-
-
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/SynchronizeConnectors.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/SynchronizeConnectors.java?rev=988101&r1=988100&r2=988101&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/SynchronizeConnectors.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/SynchronizeConnectors.java Mon Aug 23 12:18:13 2010
@@ -18,17 +18,72 @@
*/
package org.apache.lcf.crawler;
-import java.io.*;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.crawler.interfaces.*;
-import org.apache.lcf.crawler.system.*;
+import org.apache.lcf.crawler.system.LCF;
+import org.apache.lcf.crawler.system.Logging;
-public class SynchronizeConnectors
+
+/**
+ * Un-register all registered repository connector classes that can't be found
+ */
+public class SynchronizeConnectors extends BaseCrawlerInitializationCommand
{
public static final String _rcsid = "@(#)$Id$";
- private SynchronizeConnectors()
+ public SynchronizeConnectors()
+ {
+ }
+
+ protected void doExecute(IThreadContext tc) throws LCFException
{
+ IDBInterface database = DBInterfaceFactory.make(tc,
+ LCF.getMasterDatabaseName(),
+ LCF.getMasterDatabaseUsername(),
+ LCF.getMasterDatabasePassword());
+ IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+ IJobManager jobManager = JobManagerFactory.make(tc);
+ IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+ IResultSet classNames = mgr.getConnectors();
+ int i = 0;
+ while (i < classNames.getRowCount())
+ {
+ IResultRow row = classNames.getRow(i++);
+ String className = (String)row.getValue("classname");
+ try
+ {
+ RepositoryConnectorFactory.getConnectorNoCheck(className);
+ }
+ catch (LCFException e)
+ {
+ // Deregistration should be done in a transaction
+ database.beginTransaction();
+ try
+ {
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(className);
+ // For each connection name, modify the jobs to note that the connector is no longer installed
+ jobManager.noteConnectorDeregistration(connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ mgr.removeConnector(className);
+ }
+ catch (LCFException e2)
+ {
+ database.signalRollback();
+ throw e2;
+ }
+ catch (Error e2)
+ {
+ database.signalRollback();
+ throw e2;
+ }
+ finally
+ {
+ database.endTransaction();
+ }
+ }
+ }
+ Logging.root.info("Successfully synchronized all connectors");
}
@@ -42,54 +97,8 @@ public class SynchronizeConnectors
try
{
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
- IDBInterface database = DBInterfaceFactory.make(tc,
- LCF.getMasterDatabaseName(),
- LCF.getMasterDatabaseUsername(),
- LCF.getMasterDatabasePassword());
- IConnectorManager mgr = ConnectorManagerFactory.make(tc);
- IJobManager jobManager = JobManagerFactory.make(tc);
- IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
- IResultSet classNames = mgr.getConnectors();
- int i = 0;
- while (i < classNames.getRowCount())
- {
- IResultRow row = classNames.getRow(i++);
- String className = (String)row.getValue("classname");
- try
- {
- RepositoryConnectorFactory.getConnectorNoCheck(className);
- }
- catch (LCFException e)
- {
- // Deregistration should be done in a transaction
- database.beginTransaction();
- try
- {
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(className);
- // For each connection name, modify the jobs to note that the connector is no longer installed
- jobManager.noteConnectorDeregistration(connectionNames);
- // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
- mgr.removeConnector(className);
- }
- catch (LCFException e2)
- {
- database.signalRollback();
- throw e2;
- }
- catch (Error e2)
- {
- database.signalRollback();
- throw e2;
- }
- finally
- {
- database.endTransaction();
- }
- }
- }
+ SynchronizeConnectors synchronizeConnectors = new SynchronizeConnectors();
+ synchronizeConnectors.execute();
System.err.println("Successfully synchronized all connectors");
}
catch (LCFException e)
@@ -98,8 +107,4 @@ public class SynchronizeConnectors
System.exit(1);
}
}
-
-
-
-
}
Added: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java?rev=988101&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java (added)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java Mon Aug 23 12:18:13 2010
@@ -0,0 +1,45 @@
+package org.apache.lcf.crawler;
+
+import org.apache.lcf.core.InitializationCommand;
+import org.apache.lcf.core.interfaces.*;
+import org.apache.lcf.crawler.system.LCF;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class TransactionalCrawlerInitializationCommand implements InitializationCommand
+{
+ public void execute() throws LCFException
+ {
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+ IDBInterface database = DBInterfaceFactory.make(tc,
+ org.apache.lcf.agents.system.LCF.getMasterDatabaseName(),
+ org.apache.lcf.agents.system.LCF.getMasterDatabaseUsername(),
+ org.apache.lcf.agents.system.LCF.getMasterDatabasePassword());
+
+ try
+ {
+ database.beginTransaction();
+ doExecute(tc);
+ }
+ catch (LCFException e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ catch (Error e)
+ {
+ database.signalRollback();
+ throw e;
+ }
+ finally
+ {
+ database.endTransaction();
+ }
+
+ }
+
+ protected abstract void doExecute(IThreadContext tc) throws LCFException;
+
+}
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/TransactionalCrawlerInitializationCommand.java
------------------------------------------------------------------------------
svn:keywords = Id