View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package cz.cuni.amis.pogamut.base.utils.jmx;
6   
7   import cz.cuni.amis.introspection.Folder;
8   import cz.cuni.amis.introspection.jmx.FolderMBean;
9   import cz.cuni.amis.pogamut.base.agent.exceptions.CantStartJMXException;
10  import cz.cuni.amis.pogamut.base.agent.exceptions.JMXAlreadyEnabledException;
11  import cz.cuni.amis.pogamut.base.agent.jmx.AgentJMXComponents;
12  import cz.cuni.amis.pogamut.base.agent.jmx.IJMXEnabled;
13  
14  import javax.management.MBeanServer;
15  import javax.management.MalformedObjectNameException;
16  import javax.management.ObjectName;
17  
18  /**
19   * Adapter turning introspection folder into IJMXEnabled component.
20   * Only the root folder is adapted through this object.
21   * @author Ik
22   */
23  public class FolderToIJMXEnabledAdapter implements IJMXEnabled {
24  
25      
26  
27      /** Folder being adapted. */
28      Folder folder = null;
29  
30      public FolderToIJMXEnabledAdapter(Folder folder) {
31          this.folder = folder;
32      }
33  
34      @Override
35      public void enableJMX(MBeanServer mBeanServer, ObjectName parent) throws JMXAlreadyEnabledException, CantStartJMXException {
36  
37          try {
38              ObjectName newName = getFolderObjectNameForParent(parent, null);
39              FolderMBean.exportFolderHierarchy(folder, mBeanServer, newName.getDomain(), newName.getKeyProperty("type"));
40          } catch (Exception ex) {
41              throw new CantStartJMXException("Failed to export an introspection folder to JMX server.", ex);
42          }
43      }
44  
45      public static ObjectName getFolderObjectNameForParent(ObjectName parent, String folderName) throws MalformedObjectNameException {
46          return PogamutJMX.getObjectName(parent, folderName, PogamutJMX.INTROSPECTION_NAME);
47      }
48  }