incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shinich...@apache.org
Subject svn commit: r1144179 - in /incubator/lcf/trunk: CHANGES.txt framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java
Date Fri, 08 Jul 2011 07:11:33 GMT
Author: shinichiro
Date: Fri Jul  8 07:11:32 2011
New Revision: 1144179

URL: http://svn.apache.org/viewvc?rev=1144179&view=rev
Log:
Fix for CONNECTORS-217

Modified:
    incubator/lcf/trunk/CHANGES.txt
    incubator/lcf/trunk/framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java

Modified: incubator/lcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/CHANGES.txt?rev=1144179&r1=1144178&r2=1144179&view=diff
==============================================================================
--- incubator/lcf/trunk/CHANGES.txt (original)
+++ incubator/lcf/trunk/CHANGES.txt Fri Jul  8 07:11:32 2011
@@ -3,6 +3,9 @@ $Id$
 
 ======================= 0.3-dev =========================
 
+CONNECTORS-217: Check running more than one of instance of agent. 
+(Shinichiro Abe)
+
 CONNECTORS-218: LockClean supports relative path 
 to the synchronization directory. 
 (Shinichiro Abe)

Modified: incubator/lcf/trunk/framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java?rev=1144179&r1=1144178&r2=1144179&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java
(original)
+++ incubator/lcf/trunk/framework/agents/src/main/java/org/apache/manifoldcf/agents/AgentRun.java
Fri Jul  8 07:11:32 2011
@@ -28,6 +28,7 @@ public class AgentRun extends BaseAgents
 {
   public static final String _rcsid = "@(#)$Id: AgentRun.java 988245 2010-08-23 18:39:35Z
kwright $";
 
+  public static final String agentInUseSignal = "_AGENTINUSE_";
   public static final String agentShutdownSignal = "_AGENTRUN_";
   
   public AgentRun()
@@ -37,28 +38,48 @@ public class AgentRun extends BaseAgents
   protected void doExecute(IThreadContext tc) throws ManifoldCFException
   {
     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
-      ManifoldCF.startAgents(tc);
-
-      try
-      {
-        ManifoldCF.sleep(5000);
-      }
-      catch (InterruptedException e)
+    // Agent already in use?
+    if (lockManager.checkGlobalFlag(agentInUseSignal))
+    {
+      System.err.println("Agent already in use");
+      System.exit(1);
+    }
+    // Set the agents in use signal.
+    lockManager.setGlobalFlag(agentInUseSignal);    
+    try
+    {
+      // Clear the agents shutdown signal.
+      lockManager.clearGlobalFlag(agentShutdownSignal);
+      Logging.root.info("Running...");
+      while (true)
       {
-        break;
+        // Any shutdown signal yet?
+        if (lockManager.checkGlobalFlag(agentShutdownSignal))
+          break;
+
+        // Start whatever agents need to be started
+        ManifoldCF.startAgents(tc);
+
+        try
+        {
+          ManifoldCF.sleep(5000);
+        }
+        catch (InterruptedException e)
+        {
+          break;
+        }
       }
+      Logging.root.info("Shutting down...");
+    }
+    catch (ManifoldCFException e)
+    {
+      Logging.root.error("Exception: "+e.getMessage(),e);
+      e.printStackTrace(System.err);
+    }
+    finally
+    {
+      lockManager.clearGlobalFlag(agentInUseSignal);
     }
-    Logging.root.info("Shutting down...");
   }
 
 



Mime
View raw message