]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java
Some more UI functionalities :
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / DefaultAgent.java
index e69b1cf7af749771d7fa4aaab10dc47479db24a2..7d6ff315e0df40ebc99ded44d13ddc481414b594 100644 (file)
@@ -19,25 +19,21 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
 import org.argeo.slc.execution.ExecutionModuleDescriptor;
 import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionProcess;
-import org.argeo.slc.execution.ExecutionProcessNotifier;
-import org.argeo.slc.execution.ExecutionStep;
-import org.argeo.slc.process.SlcExecution;
-import org.argeo.slc.runtime.SlcAgent;
-import org.argeo.slc.runtime.SlcAgentDescriptor;
+import org.argeo.slc.execution.SlcAgent;
+import org.argeo.slc.execution.SlcAgentDescriptor;
 
 /** Implements the base methods of an SLC agent. */
-@SuppressWarnings("deprecation")
-public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
+public class DefaultAgent implements SlcAgent {
        private final static Log log = LogFactory.getLog(DefaultAgent.class);
 
        private SlcAgentDescriptor agentDescriptor;
@@ -62,14 +58,28 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
                }
                processesThreadGroup = new ThreadGroup("SLC Processes of Agent #"
                                + agentDescriptor.getUuid());
-               modulesManager.registerProcessNotifier(this,
-                               new HashMap<String, String>());
+               // modulesManager.registerProcessNotifier(this,
+               // new HashMap<String, String>());
+
+               // final String module = System
+               // .getProperty(ExecutionModulesManager.UNIQUE_LAUNCH_MODULE_PROPERTY);
+               // final String flow = System
+               // .getProperty(ExecutionModulesManager.UNIQUE_LAUNCH_FLOW_PROPERTY);
+               // if (module != null) {
+               // // launch a flow and stops
+               // new Thread("Unique Flow") {
+               // @Override
+               // public void run() {
+               // executeFlowAndExit(module, null, flow);
+               // }
+               // }.start();
+               // }
        }
 
        /** Clean up (needs to be called by overriding method) */
        public void destroy() {
-               modulesManager.unregisterProcessNotifier(this,
-                               new HashMap<String, String>());
+//             modulesManager.unregisterProcessNotifier(this,
+//                             new HashMap<String, String>());
        }
 
        /**
@@ -80,6 +90,13 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
                return UUID.randomUUID().toString();
        }
 
+       /*
+        * UNIQUE FLOW
+        */
+       // protected void executeFlowAndExit(final String module,
+       // final String version, final String flow) {
+       // }
+
        /*
         * SLC AGENT
         */
@@ -88,7 +105,14 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
                                modulesManager, process);
                processThread.start();
                runningProcesses.put(process.getUuid(), processThread);
-               // FIXME find a way to remove them from this register
+
+               // clean up old processes
+               Iterator<ProcessThread> it = runningProcesses.values().iterator();
+               while (it.hasNext()) {
+                       ProcessThread pThread = it.next();
+                       if (!pThread.isAlive())
+                               it.remove();
+               }
        }
 
        public void kill(ExecutionProcess process) {
@@ -102,11 +126,8 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
        protected ProcessThread createProcessThread(
                        ThreadGroup processesThreadGroup,
                        ExecutionModulesManager modulesManager, ExecutionProcess process) {
-               if (!(process instanceof SlcExecution))
-                       throw new SlcException("Unsupported process type "
-                                       + process.getClass());
                ProcessThread processThread = new ProcessThread(processesThreadGroup,
-                               modulesManager, (SlcExecution) process);
+                               modulesManager, process);
                return processThread;
        }
 
@@ -126,17 +147,18 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
        /*
         * PROCESS NOTIFIER
         */
-       public void updateStatus(ExecutionProcess process, String oldStatus,
-                       String newStatus) {
-               if (newStatus.equals(ExecutionProcess.COMPLETED)
-                               || newStatus.equals(ExecutionProcess.ERROR)
-                               || newStatus.equals(ExecutionProcess.KILLED)) {
-                       runningProcesses.remove(process.getUuid());
-               }
-       }
-
-       public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
-       }
+       // public void updateStatus(ExecutionProcess process, String oldStatus,
+       // String newStatus) {
+       // if (newStatus.equals(ExecutionProcess.COMPLETED)
+       // || newStatus.equals(ExecutionProcess.ERROR)
+       // || newStatus.equals(ExecutionProcess.KILLED)) {
+       // runningProcesses.remove(process.getUuid());
+       // }
+       // }
+       //
+       // public void addSteps(ExecutionProcess process, List<ExecutionStep> steps)
+       // {
+       // }
 
        /*
         * BEAN