2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.core
.execution
;
19 import java
.lang
.management
.ManagementFactory
;
21 import javax
.management
.MBeanServer
;
22 import javax
.management
.ObjectName
;
23 import javax
.management
.StandardMBean
;
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
;
31 public class JmxExecutionModulesListeners
implements ExecutionModulesListener
{
32 private String executionModulesPrefix
= "SLCExecutionModules";
33 private MBeanServer mBeanServer
= ManagementFactory
34 .getPlatformMBeanServer();
36 public void executionModuleAdded(Module module
,
37 ExecutionContext executionContext
) {
40 public void executionModuleRemoved(Module module
,
41 ExecutionContext executionContext
) {
44 public void executionFlowAdded(Module module
, ExecutionFlow executionFlow
) {
46 StandardMBean mbean
= new StandardMBean(executionFlow
,
48 mBeanServer
.registerMBean(mbean
, flowName(module
, executionFlow
));
49 } catch (Exception e
) {
50 String msg
= "Cannot register execution flow " + executionFlow
52 throw new SlcException(msg
, e
);
56 public void executionFlowRemoved(Module module
, ExecutionFlow executionFlow
) {
58 mBeanServer
.unregisterMBean(flowName(module
, executionFlow
));
59 } catch (Exception e
) {
60 String msg
= "Cannot unregister execution flow " + executionFlow
62 throw new SlcException(msg
, e
);
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();
73 return new ObjectName(name
);
74 } catch (Exception e
) {
75 throw new SlcException("Cannot generate object name based on "