+ private ThreadGroup processesThreadGroup;
+ private Map<String, ProcessThread> runningProcesses = Collections
+ .synchronizedMap(new HashMap<String, ProcessThread>());
+
+ /*
+ * LIFECYCLE
+ */
+ /** Initialization */
+ public void init() {
+ try {
+ agentDescriptor = new SlcAgentDescriptor();
+ agentDescriptor.setUuid(initAgentUuid());
+ agentDescriptor.setHost(InetAddress.getLocalHost().getHostName());
+ } catch (UnknownHostException e) {
+ throw new SlcException("Unable to create agent descriptor.", e);
+ }
+ 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;