]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Move default agent to execution package
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 25 Feb 2013 10:24:55 +0000 (10:24 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 25 Feb 2013 10:24:55 +0000 (10:24 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6084 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java [new file with mode: 0644]
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java [deleted file]
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrAgent.java

diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java
new file mode 100644 (file)
index 0000000..e69b1cf
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed 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.argeo.slc.core.execution;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collections;
+import java.util.HashMap;
+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;
+
+/** Implements the base methods of an SLC agent. */
+@SuppressWarnings("deprecation")
+public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
+       private final static Log log = LogFactory.getLog(DefaultAgent.class);
+
+       private SlcAgentDescriptor agentDescriptor;
+       private ExecutionModulesManager modulesManager;
+
+       private ThreadGroup processesThreadGroup;
+       private Map<String, ProcessThread> runningProcesses = Collections
+                       .synchronizedMap(new HashMap<String, ProcessThread>());
+
+       /*
+        * LIFECYCLE
+        */
+       /** Initialization */
+       public void init() {
+               agentDescriptor = new SlcAgentDescriptor();
+               agentDescriptor.setUuid(initAgentUuid());
+               try {
+                       agentDescriptor.setHost(InetAddress.getLocalHost().getHostName());
+               } catch (UnknownHostException e) {
+                       log.error("Cannot resolve localhost host name: " + e.getMessage());
+                       agentDescriptor.setHost("localhost");
+               }
+               processesThreadGroup = new ThreadGroup("SLC Processes of Agent #"
+                               + agentDescriptor.getUuid());
+               modulesManager.registerProcessNotifier(this,
+                               new HashMap<String, String>());
+       }
+
+       /** Clean up (needs to be called by overriding method) */
+       public void destroy() {
+               modulesManager.unregisterProcessNotifier(this,
+                               new HashMap<String, String>());
+       }
+
+       /**
+        * Called during initialization in order to determines the agent UUID. To be
+        * overridden. By default creates a new one per instance.
+        */
+       protected String initAgentUuid() {
+               return UUID.randomUUID().toString();
+       }
+
+       /*
+        * SLC AGENT
+        */
+       public void process(ExecutionProcess process) {
+               ProcessThread processThread = createProcessThread(processesThreadGroup,
+                               modulesManager, process);
+               processThread.start();
+               runningProcesses.put(process.getUuid(), processThread);
+               // FIXME find a way to remove them from this register
+       }
+
+       public void kill(ExecutionProcess process) {
+               String processUuid = process.getUuid();
+               if (runningProcesses.containsKey(processUuid)) {
+                       runningProcesses.get(processUuid).interrupt();
+               }
+       }
+
+       /** Creates the thread which will coordinate the execution for this agent. */
+       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);
+               return processThread;
+       }
+
+       public ExecutionModuleDescriptor getExecutionModuleDescriptor(
+                       String moduleName, String version) {
+               return modulesManager.getExecutionModuleDescriptor(moduleName, version);
+       }
+
+       public List<ExecutionModuleDescriptor> listExecutionModuleDescriptors() {
+               return modulesManager.listExecutionModules();
+       }
+
+       public boolean ping() {
+               return true;
+       }
+
+       /*
+        * 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) {
+       }
+
+       /*
+        * BEAN
+        */
+       public void setModulesManager(ExecutionModulesManager modulesManager) {
+               this.modulesManager = modulesManager;
+       }
+
+       protected SlcAgentDescriptor getAgentDescriptor() {
+               return agentDescriptor;
+       }
+
+       public String getAgentUuid() {
+               return agentDescriptor.getUuid();
+       }
+
+       @Override
+       public String toString() {
+               return agentDescriptor.toString();
+       }
+}
diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/runtime/DefaultAgent.java
deleted file mode 100644 (file)
index 4af24ae..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed 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.argeo.slc.core.runtime;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Collections;
-import java.util.HashMap;
-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.core.execution.ProcessThread;
-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;
-
-/** Implements the base methods of an SLC agent. */
-@SuppressWarnings("deprecation")
-public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier {
-       private final static Log log = LogFactory.getLog(DefaultAgent.class);
-
-       private SlcAgentDescriptor agentDescriptor;
-       private ExecutionModulesManager modulesManager;
-
-       private ThreadGroup processesThreadGroup;
-       private Map<String, ProcessThread> runningProcesses = Collections
-                       .synchronizedMap(new HashMap<String, ProcessThread>());
-
-       /*
-        * LIFECYCLE
-        */
-       /** Initialization */
-       public void init() {
-               agentDescriptor = new SlcAgentDescriptor();
-               agentDescriptor.setUuid(initAgentUuid());
-               try {
-                       agentDescriptor.setHost(InetAddress.getLocalHost().getHostName());
-               } catch (UnknownHostException e) {
-                       log.error("Cannot resolve localhost host name: " + e.getMessage());
-                       agentDescriptor.setHost("localhost");
-               }
-               processesThreadGroup = new ThreadGroup("SLC Processes of Agent #"
-                               + agentDescriptor.getUuid());
-               modulesManager.registerProcessNotifier(this,
-                               new HashMap<String, String>());
-       }
-
-       /** Clean up (needs to be called by overriding method) */
-       public void destroy() {
-               modulesManager.unregisterProcessNotifier(this,
-                               new HashMap<String, String>());
-       }
-
-       /**
-        * Called during initialization in order to determines the agent UUID. To be
-        * overridden. By default creates a new one per instance.
-        */
-       protected String initAgentUuid() {
-               return UUID.randomUUID().toString();
-       }
-
-       /*
-        * SLC AGENT
-        */
-       public void process(ExecutionProcess process) {
-               ProcessThread processThread = createProcessThread(processesThreadGroup,
-                               modulesManager, process);
-               processThread.start();
-               runningProcesses.put(process.getUuid(), processThread);
-               // FIXME find a way to remove them from this register
-       }
-
-       public void kill(ExecutionProcess process) {
-               String processUuid = process.getUuid();
-               if (runningProcesses.containsKey(processUuid)) {
-                       runningProcesses.get(processUuid).interrupt();
-               }
-       }
-
-       /** Creates the thread which will coordinate the execution for this agent. */
-       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);
-               return processThread;
-       }
-
-       public ExecutionModuleDescriptor getExecutionModuleDescriptor(
-                       String moduleName, String version) {
-               return modulesManager.getExecutionModuleDescriptor(moduleName, version);
-       }
-
-       public List<ExecutionModuleDescriptor> listExecutionModuleDescriptors() {
-               return modulesManager.listExecutionModules();
-       }
-
-       public boolean ping() {
-               return true;
-       }
-
-       /*
-        * 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) {
-       }
-
-       /*
-        * BEAN
-        */
-       public void setModulesManager(ExecutionModulesManager modulesManager) {
-               this.modulesManager = modulesManager;
-       }
-
-       protected SlcAgentDescriptor getAgentDescriptor() {
-               return agentDescriptor;
-       }
-
-       public String getAgentUuid() {
-               return agentDescriptor.getUuid();
-       }
-
-       @Override
-       public String toString() {
-               return agentDescriptor.toString();
-       }
-}
index c0fce506debfaa2774d083cf6ccb506d1b01497c..751d8a97d2db20e82e567c6fb4a1a403d1285966 100644 (file)
@@ -25,8 +25,8 @@ import javax.jcr.Session;
 
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.core.execution.DefaultAgent;
 import org.argeo.slc.core.execution.ProcessThread;
-import org.argeo.slc.core.runtime.DefaultAgent;
 import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionProcess;
 import org.argeo.slc.jcr.SlcJcrConstants;