Java Code Examples for javax.management.modelmbean.RequiredModelMBean#setManagedResource()

The following examples show how to use javax.management.modelmbean.RequiredModelMBean#setManagedResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmxMbeanHelper.java    From iaf with Apache License 2.0 6 votes vote down vote up
/**
 * Hooks an {@link nl.nn.adapterframework.core.Adapter Adapter} to the MBean server
 */
public static void hookupAdapter(IAdapter adapter) throws ConfigurationException {
    MBeanServer server = getMBeanServer();
    if (server != null) {
    	synchronized(registeredAdapters) {
  	try {
          ObjectName objectName = getObjectName(adapter);
		
          RequiredModelMBean modelMbean =
                  new RequiredModelMBean(createMBeanInfo(adapter));
          modelMbean.setManagedResource(adapter, "ObjectReference");
          LOG.debug("modelMBean generated for object " + objectName);
          ObjectInstance objectInstance = registerMBean(server, objectName, modelMbean);
          if (objectInstance!=null) {
          	registeredAdapters.put(adapter, objectInstance.getObjectName());
          }
      } catch (Exception e) {
          throw new ConfigurationException(e);
      }
    	}
    } else {
        LOG.warn("No MBean server found");
    }
}
 
Example 2
Source File: RequiredModelMBeanBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // 获取当前平台 MBean Server
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    RequiredModelMBean modelMBean = new RequiredModelMBean();
    modelMBean.setManagedResource(new User(), "objectReference");
    // 创建 RequiredModelMBean 的 ObjectName
    ObjectName objectName = new ObjectName("thinking.in.spring.boot.samples.production.ready.jmx:type=User");
    mBeanServer.registerMBean(modelMBean, objectName);
    System.out.printf("MBean (ObjectName[%s])已注册到平台 MBean Server...\n", objectName);
    System.out.println("按任意键结束...");
    System.in.read();
}
 
Example 3
Source File: DefaultManagementMBeanAssembler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
  ModelMBeanInfo mbi = null;

  // use the default provided mbean which has been annotated with JMX
  // annotations
  LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
  mbi = assembler.getMBeanInfo(obj, null, name.toString());

  if (mbi == null) {
    return null;
  }

  RequiredModelMBean mbean = new RequiredModelMBean(mbi);

  try {
    mbean.setManagedResource(obj, "ObjectReference");
  } catch (InvalidTargetObjectTypeException e) {
    throw new JMException(e.getMessage());
  }

  // Allows the managed object to send notifications
  if (obj instanceof NotificationSenderAware) {
    ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
  }

  return mbean;
}
 
Example 4
Source File: DefaultManagementMBeanAssembler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;

    // use the default provided mbean which has been annotated with JMX annotations
    LOGGER.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
    mbi = assembler.getMBeanInfo(obj, null, name.toString());

    if (mbi == null) {
        return null;
    }

    RequiredModelMBean mbean = new RequiredModelMBean(mbi);

    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }

    // Allows the managed object to send notifications
    if (obj instanceof NotificationSenderAware) {
        ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
    }

    return mbean;
}
 
Example 5
Source File: RMEndpoint.java    From cxf with Apache License 2.0 5 votes vote down vote up
void initialise(RMConfiguration config, Conduit c, EndpointReferenceType r,
    org.apache.cxf.transport.Destination d,
    Message message) {
    configuration = config;
    conduit = c;
    replyTo = r;
    createServices();
    createEndpoints(d);
    setPolicies(message);
    if (manager != null && manager.getBus() != null) {
        managedEndpoint = new ManagedRMEndpoint(this);
        instrumentationManager = manager.getBus().getExtension(InstrumentationManager.class);
        if (instrumentationManager != null) {
            ModelMBeanAssembler assembler = new ModelMBeanAssembler();
            ModelMBeanInfo mbi = assembler.getModelMbeanInfo(managedEndpoint.getClass());
            MBeanServer mbs = instrumentationManager.getMBeanServer();
            if (mbs == null) {
                LOG.log(Level.WARNING, "MBeanServer not available.");
            } else {
                try {
                    RequiredModelMBean rtMBean =
                        (RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
                    rtMBean.setModelMBeanInfo(mbi);
                    try {
                        rtMBean.setManagedResource(managedEndpoint, "ObjectReference");
                    } catch (InvalidTargetObjectTypeException itotex) {
                        throw new JMException(itotex.getMessage());
                    }
                    ObjectName name = managedEndpoint.getObjectName();
                    instrumentationManager.register(rtMBean, name);
                    modelMBean = rtMBean;
                } catch (JMException jmex) {
                    LOG.log(Level.WARNING, "Registering ManagedRMEndpoint failed.", jmex);
                }
            }
        }
    }
}
 
Example 6
Source File: InstrumentationManagerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean forceRegistration)
    throws JMException {
    RequiredModelMBean rtMBean =
        (RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
    rtMBean.setModelMBeanInfo(mbi);
    try {
        rtMBean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException itotex) {
        throw new JMException(itotex.getMessage());
    }
    registerMBeanWithServer(rtMBean, persist(name), forceRegistration);
}