Exemple #1
0
  /** Registers the Dynamic Mbean. */
  public void start() {
    // create the corresponding MBean
    if (m_registerCallbacks) {
      m_MBean =
          new DynamicMBeanWRegisterImpl(
              m_jmxConfigFieldMap,
              m_instanceManager,
              m_preRegisterMeth,
              m_postRegisterMeth,
              m_preDeregisterMeth,
              m_postDeregisterMeth);
    } else {
      m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager);
    }

    if (m_usesMOSGi) {
      // use whiteboard pattern to register MBean

      if (m_serviceRegistration != null) {
        m_serviceRegistration.unregister();
      }

      // Register the ManagedService
      BundleContext bundleContext = m_instanceManager.getContext();
      Properties properties = new Properties();
      try {
        m_objectName = new ObjectName(getObjectNameString());

        properties.put("jmxagent.objectName", m_objectName.toString());

        m_serviceRegistration =
            bundleContext.registerService(
                javax.management.DynamicMBean.class.getName(), m_MBean, properties);

        m_registered = true;
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      try {
        m_objectName = new ObjectName(getObjectNameString());
        ObjectInstance instance =
            ManagementFactory.getPlatformMBeanServer().registerMBean(m_MBean, m_objectName);

        // we must retrieve object name used to register the MBean.
        // It can have been changed by preRegister method of
        // MBeanRegistration interface.
        if (m_registerCallbacks) {
          m_objectName = instance.getObjectName();
        }

        m_registered = true;
      } catch (Exception e) {
        error("Registration of MBean failed.", e);
      }
    }
  }
Exemple #2
0
  /**
   * Returns true if the MOSGi framework is present on the OSGi platform.
   *
   * @return {@code true} if the MOSGi framework is present on the OSGi platform, false otherwise.
   */
  public boolean isMOSGiExists() {
    for (Bundle bundle : m_instanceManager.getContext().getBundles()) {
      String symbolicName = bundle.getSymbolicName();
      if ("org.apache.felix.mosgi.jmx.agent".equals(symbolicName)) {
        return true;
      }
    }

    return false;
  }