From f3e477b3048c639451df616cfa61564eae11efbb Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 17 Apr 2011 07:59:36 +0000 Subject: [PATCH] Flows automatically registered in JCR NEW - bug 17: Generalize agent management and registration beyond JMS https://bugzilla.argeo.org/show_bug.cgi?id=17 git-svn-id: https://svn.argeo.org/slc/trunk@4444 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- demo/log4j.properties | 17 +- demo/slc_demo_rcp.properties | 1 + .../META-INF/spring/agent.xml | 1 - .../META-INF/spring/osgi.xml | 25 ++- .../META-INF/MANIFEST.MF | 4 + .../META-INF/spring/jcr-osgi.xml | 35 ++-- .../META-INF/spring/jcr.xml | 125 ++++++------- .../AbstractExecutionModulesManager.java | 11 -- .../slc/core/execution/ExecutionAspect.java | 15 +- .../slc/core/execution/ProcessThread.java | 5 +- .../argeo/slc/execution/ExecutionFlow.java | 18 +- .../execution/ExecutionFlowDescriptor.java | 12 +- .../JcrExecutionModulesListener.java | 166 ++++++++++++++++++ .../slc/osgi/OsgiExecutionModulesManager.java | 159 ++++++++++------- 14 files changed, 401 insertions(+), 193 deletions(-) create mode 100644 runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java diff --git a/demo/log4j.properties b/demo/log4j.properties index d56398aad..7fe0f0cba 100644 --- a/demo/log4j.properties +++ b/demo/log4j.properties @@ -3,18 +3,7 @@ log4j.rootLogger=WARN, development ## Levels log4j.logger.org.argeo=DEBUG -log4j.logger.org.argeo.slc.execution.ExecutionParameterPostProcessor=TRACE -log4j.logger.org.argeo.slc.execution.ExecutionContext=DEBUG -log4j.logger.org.argeo.slc.execution.SimpleExecutionSpec=DEBUG -log4j.logger.org.argeo.security.mvc.ArgeoRememberMeServices=WARN -log4j.logger.org.argeo.server.jackrabbit.webdav.ExtendedDispatcherServlet=WARN -#log4j.logger.org.argeo.server.jcr.mvc.OpenSessionInViewJcrInterceptor=TRACE - -log4j.logger.org.argeo.slc.client.ui.views.ExecutionModulesContentProvider=TRACE - -#log4j.logger.org.argeo.slc.web.mvc=TRACE -#log4j.logger.org.argeo.slc.jms=TRACE -#log4j.logger.org.argeo.server.json=TRACE +log4j.logger.org.argeo.slc.osgi.OsgiExecutionModulesManager=TRACE log4j.logger.org.eclipse.rap=INFO @@ -22,10 +11,6 @@ log4j.logger.org.hibernate=WARN log4j.logger.org.springframework=WARN #log4j.logger.org.springframework.web=DEBUG -#log4j.logger.org.springframework.jms=WARN -#log4j.logger.org.springframework.security=DEBUG -#log4j.logger.org.springframework.ldap=TRACE -#log4j.logger.org.springframework.osgi=INFO log4j.logger.org.apache.activemq=INFO #log4j.logger.org.apache.activemq.transport=WARN diff --git a/demo/slc_demo_rcp.properties b/demo/slc_demo_rcp.properties index c3b5c3e19..247b07ec6 100644 --- a/demo/slc_demo_rcp.properties +++ b/demo/slc_demo_rcp.properties @@ -1,6 +1,7 @@ argeo.osgi.start=\ org.springframework.osgi.extender,\ org.argeo.slc.client.rcp,\ +org.argeo.slc.server.jcr,\ org.argeo.slc.demo.ant,\ org.argeo.slc.demo.basic,\ diff --git a/modules/agent/org.argeo.slc.agent/META-INF/spring/agent.xml b/modules/agent/org.argeo.slc.agent/META-INF/spring/agent.xml index a6e5f00e5..1125ab80a 100644 --- a/modules/agent/org.argeo.slc.agent/META-INF/spring/agent.xml +++ b/modules/agent/org.argeo.slc.agent/META-INF/spring/agent.xml @@ -7,7 +7,6 @@ - diff --git a/modules/agent/org.argeo.slc.agent/META-INF/spring/osgi.xml b/modules/agent/org.argeo.slc.agent/META-INF/spring/osgi.xml index df4759d8b..873f6f242 100644 --- a/modules/agent/org.argeo.slc.agent/META-INF/spring/osgi.xml +++ b/modules/agent/org.argeo.slc.agent/META-INF/spring/osgi.xml @@ -8,11 +8,30 @@ - + + + + + + + + - + + + + + + + + \ No newline at end of file diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF b/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF index e7a1cf6ee..e0cdde8c1 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/MANIFEST.MF @@ -5,6 +5,9 @@ Bundle-Name: Server JCR Import-Package: javax.jcr, org.argeo.jcr, org.argeo.jcr.mvc, + org.argeo.jcr.spring, + org.argeo.security, + org.argeo.security.jcr, org.argeo.slc.core.attachment, org.argeo.slc.core.execution, org.argeo.slc.core.structure, @@ -17,6 +20,7 @@ Import-Package: javax.jcr, org.argeo.slc.dao.test.tree, org.argeo.slc.execution, org.argeo.slc.jcr.dao, + org.argeo.slc.jcr.execution, org.argeo.slc.process, org.argeo.slc.runtime, org.argeo.slc.test, diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml index ccb910c93..d1a550c18 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr-osgi.xml @@ -6,20 +6,27 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + + + - - - - - + + - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml index 3286d73ca..4d9983cfd 100644 --- a/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml +++ b/modules/server/org.argeo.slc.server.jcr/META-INF/spring/jcr.xml @@ -3,79 +3,80 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - - - - + + + + + + + - - - + + - - - + + + - - - - + + + + + - - - - + + + + + - - - - + + + + + - - - - + + + + + - - - + + + + + - - - - - - + + + + + - - - + + + + - - - - + + + + + + - - - - --> - - - + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java index 4e9856fe6..e16ad65f7 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java @@ -26,7 +26,6 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionFlowDescriptorConverter; -import org.argeo.slc.execution.ExecutionModulesListener; import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.process.SlcExecution; @@ -40,7 +39,6 @@ public abstract class AbstractExecutionModulesManager implements .getLog(AbstractExecutionModulesManager.class); private List slcExecutionNotifiers = new ArrayList(); - private List executionModulesListeners = new ArrayList(); private ThreadGroup processesThreadGroup = new ThreadGroup("Processes"); @@ -114,13 +112,4 @@ public abstract class AbstractExecutionModulesManager implements return processesThreadGroup; } - protected List getExecutionModulesListeners() { - return executionModulesListeners; - } - - public void setExecutionModulesListeners( - List executionModulesListeners) { - this.executionModulesListeners = executionModulesListeners; - } - } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionAspect.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionAspect.java index e9e5b4cdd..cdafe446d 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionAspect.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionAspect.java @@ -27,6 +27,7 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect +/** Aspect intercepting calls on execution flows and contexts. */ public class ExecutionAspect { private final static Log log = LogFactory.getLog(ExecutionAspect.class); @@ -60,16 +61,6 @@ public class ExecutionAspect { } } - @Around("runnableExecution()") - public void aroundRunnable(ProceedingJoinPoint pjp) throws Throwable { - ExecutionFlow executionFlow = (ExecutionFlow) pjp.getTarget(); - Runnable runnable = (Runnable) pjp.getArgs()[0]; - if (log.isDebugEnabled()) - logRunnableExecution(executionFlow, runnable); - // Actually execute the runnable - pjp.proceed(); - } - @Around("getVariable()") public Object aroundGetVariable(ProceedingJoinPoint pjp) throws Throwable { Object obj = pjp.proceed(); @@ -86,10 +77,6 @@ public class ExecutionAspect { public void flowExecution() { } - @Pointcut("execution(void org.argeo.slc.execution.ExecutionFlow.doExecuteRunnable(..))") - public void runnableExecution() { - } - @Pointcut("execution(* org.argeo.slc.execution.ExecutionContext.getVariable(..))") public void getVariable() { } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java index 7c0e7b10d..5af3262d5 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java @@ -47,7 +47,8 @@ public class ProcessThread extends Thread { } public void run() { - log.info("\n##\n## SLC Process " + slcProcess + " STARTED\n##"); + log.info("\n##\n## SLC Process #" + slcProcess.getUuid() + + " STARTED\n##\n"); slcProcess.setStatus(SlcExecution.STATUS_RUNNING); executionModulesManager.dispatchUpdateStatus(slcProcess, @@ -83,7 +84,7 @@ public class ProcessThread extends Thread { executionModulesManager.dispatchUpdateStatus(slcProcess, SlcExecution.STATUS_RUNNING, slcProcess.getStatus()); - log.info("## SLC Process " + slcProcess + " COMPLETED"); + log.info("\n## SLC Process #" + slcProcess.getUuid() + " COMPLETED\n"); } public void notifyError() { diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java index b27f4efc1..992a97486 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java @@ -16,22 +16,26 @@ package org.argeo.slc.execution; +/** Abstraction of an execution that can be identified and configured. */ public interface ExecutionFlow extends Runnable { + /** Retrieve an immutable parameter */ public Object getParameter(String key); + /** Whether this immutable parameter is set */ public Boolean isSetAsParameter(String key); + /** The specifications of the execution flow. */ public ExecutionSpec getExecutionSpec(); + /** + * The name of this execution flow. Can contains '/' which will be + * interpreted by UIs as a hierarchy; + */ public String getName(); - public String getPath(); - /** - * Actually performs the execution of the Runnable. This method should never - * be called directly. The implementation should provide a reasonable - * default, but it is meant to be intercepted either to analyze what is run - * or to override the default behavior. + * @deprecated will be removed in SLC 2.0, the path should be the part of + * the name with '/' */ - public void doExecuteRunnable(Runnable runnable); + public String getPath(); } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java index f43293099..77cc26816 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java @@ -39,10 +39,6 @@ import java.util.Map; * * Generally, values object are either a PrimitiveAccessor or a * RefValue but can be other objects. - * - * @author bsinou - * - * */ public class ExecutionFlowDescriptor implements Serializable { private static final long serialVersionUID = 7101944857038041216L; @@ -66,10 +62,18 @@ public class ExecutionFlowDescriptor implements Serializable { return name; } + /** + * @deprecated will be removed in SLC 2.0, the path should be the part of + * the name with '/' + */ public String getPath() { return path; } + /** + * @deprecated will be removed in SLC 2.0, the path should be the part of + * the name with '/' + */ public void setPath(String path) { this.path = path; } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java new file mode 100644 index 000000000..dd91d5dee --- /dev/null +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -0,0 +1,166 @@ +package org.argeo.slc.jcr.execution; + +import java.util.Arrays; +import java.util.Iterator; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.deploy.Module; +import org.argeo.slc.execution.ExecutionContext; +import org.argeo.slc.execution.ExecutionFlow; +import org.argeo.slc.execution.ExecutionModulesListener; + +/** + * Synchronizes the execution runtime with JCR. For the time being the state is + * completely reset from one start to another. + */ +public class JcrExecutionModulesListener implements ExecutionModulesListener { + private final static Log log = LogFactory + .getLog(JcrExecutionModulesListener.class); + + private String modulesPath = "/slc/modules"; + + private Session session; + + public void init() { + try { + // clean up previous state + if (session.nodeExists(modulesPath)) + session.getNode(modulesPath).remove(); + JcrUtils.mkdirs(session, modulesPath); + session.save(); + } catch (RepositoryException e) { + throw new SlcException( + "Cannot initialize JCR execution module listener", e); + } finally { + JcrUtils.discardQuietly(session); + } + } + + public void dispose() { + try { + // clean up previous state + if (session.nodeExists(modulesPath)) + session.getNode(modulesPath).remove(); + session.save(); + } catch (RepositoryException e) { + throw new SlcException( + "Cannot dispose JCR execution module listener", e); + } finally { + JcrUtils.discardQuietly(session); + } + } + + public void executionModuleAdded(Module module, + ExecutionContext executionContext) { + try { + Node base = session.getNode(modulesPath); + Node moduleName = base.hasNode(module.getName()) ? base + .getNode(module.getName()) : base.addNode(module.getName()); + Node moduleVersion = moduleName.hasNode(module.getVersion()) ? moduleName + .getNode(module.getVersion()) : moduleName.addNode(module + .getVersion()); + session.save(); + } catch (RepositoryException e) { + throw new SlcException("Cannot add module " + module, e); + } + + } + + public void executionModuleRemoved(Module module, + ExecutionContext executionContext) { + try { + Node base = session.getNode(modulesPath); + if (base.hasNode(module.getName())) { + Node moduleName = base.getNode(module.getName()); + if (moduleName.hasNode(module.getVersion())) + moduleName.getNode(module.getVersion()).remove(); + if (!moduleName.hasNodes()) + moduleName.remove(); + session.save(); + } + } catch (RepositoryException e) { + throw new SlcException("Cannot remove module " + module, e); + } + } + + public void executionFlowAdded(Module module, ExecutionFlow executionFlow) { + String path = getExecutionFlowPath(module, executionFlow); + log.debug("path=" + path); + try { + Node flowNode; + if (!session.nodeExists(path)) { + Node base = session.getNode(modulesPath); + Node moduleNode = base.getNode(module.getName() + '/' + + module.getVersion()); + String relativePath = getExecutionFlowRelativePath(executionFlow); + log.debug("relativePath='" + relativePath + "'"); + Iterator names = Arrays.asList(relativePath.split("/")) + .iterator(); + Node currNode = moduleNode; + while (names.hasNext()) { + String name = names.next(); + if (currNode.hasNode(name)) + currNode = currNode.getNode(name); + else { + if (names.hasNext()) + currNode = currNode.addNode(name); + else + flowNode = currNode.addNode(name); + } + } + session.save(); + } else { + flowNode = session.getNode(path); + } + } catch (RepositoryException e) { + throw new SlcException("Cannot add flow " + executionFlow + + " from module " + module, e); + } + + } + + public void executionFlowRemoved(Module module, ExecutionFlow executionFlow) { + String path = getExecutionFlowPath(module, executionFlow); + try { + if (session.nodeExists(path)) { + Node flowNode = session.getNode(path); + flowNode.remove(); + session.save(); + } + } catch (RepositoryException e) { + throw new SlcException("Cannot remove flow " + executionFlow + + " from module " + module, e); + } + } + + protected String getExecutionFlowPath(Module module, + ExecutionFlow executionFlow) { + String relativePath = getExecutionFlowRelativePath(executionFlow); + return modulesPath + '/' + module.getName() + '/' + module.getVersion() + + '/' + relativePath; + } + + /** @return the relative path, never starts with '/' */ + @SuppressWarnings("deprecation") + protected String getExecutionFlowRelativePath(ExecutionFlow executionFlow) { + String relativePath = executionFlow.getPath() == null ? executionFlow + .getName() : executionFlow.getPath() + '/' + + executionFlow.getName(); + // we assume that it is more than one char long + if (relativePath.charAt(0) == '/') + relativePath = relativePath.substring(1); + return relativePath; + } + + public void setSession(Session session) { + this.session = session; + } + +} diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java index fe311c8dd..45a65eae2 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java @@ -43,6 +43,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; +/** Execution modules manager implementation based on an OSGi runtime. */ public class OsgiExecutionModulesManager extends AbstractExecutionModulesManager implements OsgiServiceLifecycleListener { @@ -55,6 +56,8 @@ public class OsgiExecutionModulesManager extends private Map> executionFlows = new HashMap>(); private ExecutionFlowDescriptorConverter defaultDescriptorConverter = new DefaultExecutionFlowDescriptorConverter(); + private List executionModulesListeners = new ArrayList(); + public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version) { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); @@ -137,10 +140,6 @@ public class OsgiExecutionModulesManager extends ExecutionFlowDescriptorConverter.class, filter); } - public void setBundlesManager(BundlesManager bundlesManager) { - this.bundlesManager = bundlesManager; - } - /** * Builds a minimal realized flow, based on the provided information * (typically from the command line). @@ -247,36 +246,102 @@ public class OsgiExecutionModulesManager extends return obj.toString(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - public synchronized void bind(Object service, Map properties) - throws Exception { - if (service instanceof ExecutionContext) { - ExecutionContext executionContext = (ExecutionContext) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle); - osgiBundle.setLabel(getHeaderSafe(bundle, Constants.BUNDLE_NAME)); - osgiBundle.setDescription(getHeaderSafe(bundle, - Constants.BUNDLE_DESCRIPTION)); - executionContexts.put(osgiBundle, executionContext); + /* + * REGISTRATION + */ + + /** Registers an execution context. */ + public synchronized void register(ExecutionContext executionContext, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle); + osgiBundle.setLabel(getHeaderSafe(bundle, Constants.BUNDLE_NAME)); + osgiBundle.setDescription(getHeaderSafe(bundle, + Constants.BUNDLE_DESCRIPTION)); + executionContexts.put(osgiBundle, executionContext); + if (log.isTraceEnabled()) + log.trace("Registered execution context from " + osgiBundle); + // Notify + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionModuleAdded(osgiBundle, executionContext); + } + + /** Unregisters an execution context. */ + public synchronized void unregister(ExecutionContext executionContext, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (executionContexts.containsKey(osgiBundle)) { + executionContexts.remove(osgiBundle); if (log.isTraceEnabled()) - log.debug("Registered execution context from " + osgiBundle); + log.trace("Removed execution context from " + osgiBundle); // Notify - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionModuleAdded(osgiBundle, executionContext); + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionModuleRemoved(osgiBundle, executionContext); + } + } - } else if (service instanceof ExecutionFlow) { - ExecutionFlow executionFlow = (ExecutionFlow) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (!executionFlows.containsKey(osgiBundle)) { - executionFlows.put(osgiBundle, new HashSet()); - } - executionFlows.get(osgiBundle).add(executionFlow); + /** Registers an execution flow. */ + public synchronized void register(ExecutionFlow executionFlow, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (!executionFlows.containsKey(osgiBundle)) { + executionFlows.put(osgiBundle, new HashSet()); + } + executionFlows.get(osgiBundle).add(executionFlow); + if (log.isTraceEnabled()) + log.trace("Registered " + executionFlow + " from " + osgiBundle); + + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionFlowAdded(osgiBundle, executionFlow); + } + + /** Unregisters an execution flow. */ + public synchronized void unregister(ExecutionFlow executionFlow, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (executionFlows.containsKey(osgiBundle)) { + Set flows = executionFlows.get(osgiBundle); + flows.remove(executionFlow); if (log.isTraceEnabled()) - log.debug("Registered " + executionFlow + " from " + osgiBundle); - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionFlowAdded(osgiBundle, executionFlow); + log.debug("Removed " + executionFlow + " from " + osgiBundle); + if (flows.size() == 0) { + executionFlows.remove(osgiBundle); + if (log.isTraceEnabled()) + log.trace("Removed flows set from " + osgiBundle); + } + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionFlowRemoved(osgiBundle, executionFlow); + } + } + + /** Registers an execution module listener. */ + public synchronized void register( + ExecutionModulesListener executionModulesListener, + Map properties) { + // sync with current state + for (OsgiBundle osgiBundle : executionContexts.keySet()) { + executionModulesListener.executionModuleAdded(osgiBundle, + executionContexts.get(osgiBundle)); + } + for (OsgiBundle osgiBundle : executionFlows.keySet()) { + for (ExecutionFlow executionFlow : executionFlows.get(osgiBundle)) + executionModulesListener.executionFlowAdded(osgiBundle, + executionFlow); + } + executionModulesListeners.add(executionModulesListener); + } - } else if (service instanceof ExecutionFlowDescriptorConverter) { + /** Unregisters an execution module listener. */ + public synchronized void unregister( + ExecutionModulesListener executionModulesListener, + Map properties) { + executionModulesListeners.remove(executionModulesListener); + } + + @SuppressWarnings({ "rawtypes" }) + public synchronized void bind(Object service, Map properties) + throws Exception { + if (service instanceof ExecutionFlowDescriptorConverter) { ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = (ExecutionFlowDescriptorConverter) service; OsgiBundle osgiBundle = asOsgiBundle(properties); executionFlowDescriptorConverters.put(osgiBundle, @@ -292,36 +357,7 @@ public class OsgiExecutionModulesManager extends @SuppressWarnings("rawtypes") public synchronized void unbind(Object service, Map properties) throws Exception { - if (service instanceof ExecutionContext) { - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (executionContexts.containsKey(osgiBundle)) { - ExecutionContext executionContext = executionContexts - .remove(osgiBundle); - if (log.isTraceEnabled()) - log.debug("Removed execution context from " + osgiBundle); - // Notify - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionModuleRemoved(osgiBundle, - executionContext); - } - } else if (service instanceof ExecutionFlow) { - ExecutionFlow executionFlow = (ExecutionFlow) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (executionFlows.containsKey(osgiBundle)) { - Set flows = executionFlows.get(osgiBundle); - flows.remove(executionFlow); - if (log.isTraceEnabled()) - log.debug("Removed " + executionFlow + " from " - + osgiBundle); - if (flows.size() == 0) { - executionFlows.remove(osgiBundle); - if (log.isTraceEnabled()) - log.debug("Removed flows set from " + osgiBundle); - } - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionFlowRemoved(osgiBundle, executionFlow); - } - } else if (service instanceof ExecutionFlowDescriptorConverter) { + if (service instanceof ExecutionFlowDescriptorConverter) { OsgiBundle osgiBundle = asOsgiBundle(properties); if (executionFlowDescriptorConverters.containsKey(osgiBundle)) { executionFlowDescriptorConverters.remove(osgiBundle); @@ -350,8 +386,13 @@ public class OsgiExecutionModulesManager extends return properties.get(key).toString(); } + public void setBundlesManager(BundlesManager bundlesManager) { + this.bundlesManager = bundlesManager; + } + public void setDefaultDescriptorConverter( ExecutionFlowDescriptorConverter defaultDescriptorConverter) { this.defaultDescriptorConverter = defaultDescriptorConverter; } + } -- 2.39.2