]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/JmxExecutionModulesListeners.java
Start working on serialized JMS
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / JmxExecutionModulesListeners.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution;
18
19 import java.lang.management.ManagementFactory;
20
21 import javax.management.MBeanServer;
22 import javax.management.ObjectName;
23 import javax.management.StandardMBean;
24
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.deploy.Module;
27 import org.argeo.slc.execution.ExecutionContext;
28 import org.argeo.slc.execution.ExecutionFlow;
29 import org.argeo.slc.execution.ExecutionModulesListener;
30
31 public class JmxExecutionModulesListeners implements ExecutionModulesListener {
32 private String executionModulesPrefix = "SLCExecutionModules";
33 private MBeanServer mBeanServer = ManagementFactory
34 .getPlatformMBeanServer();
35
36 public void executionModuleAdded(Module module,
37 ExecutionContext executionContext) {
38 }
39
40 public void executionModuleRemoved(Module module,
41 ExecutionContext executionContext) {
42 }
43
44 public void executionFlowAdded(Module module, ExecutionFlow executionFlow) {
45 try {
46 StandardMBean mbean = new StandardMBean(executionFlow,
47 ExecutionFlow.class);
48 mBeanServer.registerMBean(mbean, flowName(module, executionFlow));
49 } catch (Exception e) {
50 String msg = "Cannot register execution flow " + executionFlow
51 + " as mbean";
52 throw new SlcException(msg, e);
53 }
54 }
55
56 public void executionFlowRemoved(Module module, ExecutionFlow executionFlow) {
57 try {
58 mBeanServer.unregisterMBean(flowName(module, executionFlow));
59 } catch (Exception e) {
60 String msg = "Cannot unregister execution flow " + executionFlow
61 + " as mbean";
62 throw new SlcException(msg, e);
63 }
64 }
65
66 protected ObjectName flowName(Module module, ExecutionFlow executionFlow) {
67 String path = executionFlow.getPath();
68 String name = executionModulesPrefix + ":" + "module="
69 + module.getName() + "[" + module.getVersion() + "],"
70 + (path != null ? "path=" + path + "," : "") + "name="
71 + executionFlow.getName();
72 try {
73 return new ObjectName(name);
74 } catch (Exception e) {
75 throw new SlcException("Cannot generate object name based on "
76 + name, e);
77 }
78 }
79 }