/** * Get the Jolokia MBeanServer. This call is delegated to the corresponding * static utility method and will register a new MBeanServer if not already * present * * @return the Jolokia MBeanServer */ public MBeanServer getObject() { return JolokiaMBeanServerUtil.getJolokiaMBeanServer(); }
/** * Lookup the JolokiaMBean server via a JMX lookup to the Jolokia-internal MBean exposing this MBeanServer * * @return the Jolokia MBeanServer or null if not yet available present */ public static MBeanServer getJolokiaMBeanServer() { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MBeanServer jolokiaMBeanServer; try { jolokiaMBeanServer = (MBeanServer) server.getAttribute(createObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME), JOLOKIA_MBEAN_SERVER_ATTRIBUTE); } catch (InstanceNotFoundException exp) { // should be probably locked, but for simplicity reasons and because // the probability of a clash is fairly low (can happen only once), it's omitted // here. Note, that server.getAttribute() itself is threadsafe. jolokiaMBeanServer = registerJolokiaMBeanServerHolderMBean(server); } catch (JMException e) { throw new IllegalStateException("Internal: Cannot get JolokiaMBean server via JMX lookup: " + e,e); } return jolokiaMBeanServer; }
static MBeanServer registerJolokiaMBeanServerHolderMBean(MBeanServer pServer) { JolokiaMBeanServerHolder holder = new JolokiaMBeanServerHolder(); ObjectName holderName = createObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME); MBeanServer jolokiaMBeanServer; try { pServer.registerMBean(holder,holderName); jolokiaMBeanServer = holder.getJolokiaMBeanServer(); } catch (InstanceAlreadyExistsException e) { // If the instance already exist, we look it up and fetch the MBeanServerHolder from there. // Might happen in race conditions. try { jolokiaMBeanServer = (MBeanServer) pServer.getAttribute(holderName,JOLOKIA_MBEAN_SERVER_ATTRIBUTE); } catch (JMException e1) { throw new IllegalStateException("Internal: Cannot get JolokiaMBean server in fallback JMX lookup " + "while trying to register the holder MBean: " + e1,e1); } } catch (JMException e) { throw new IllegalStateException("Internal: JolokiaMBeanHolder cannot be registered to JMX: " + e,e); } return jolokiaMBeanServer; }
static MBeanServer registerJolokiaMBeanServerHolderMBean(MBeanServer pServer) { JolokiaMBeanServerHolder holder = new JolokiaMBeanServerHolder(); ObjectName holderName = createObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME); MBeanServer jolokiaMBeanServer; try { pServer.registerMBean(holder,holderName); jolokiaMBeanServer = holder.getJolokiaMBeanServer(); } catch (InstanceAlreadyExistsException e) { // If the instance already exist, we look it up and fetch the MBeanServerHolder from there. // Might happen in race conditions. try { jolokiaMBeanServer = (MBeanServer) pServer.getAttribute(holderName,JOLOKIA_MBEAN_SERVER_ATTRIBUTE); } catch (JMException e1) { throw new IllegalStateException("Internal: Cannot get JolokiaMBean server in fallback JMX lookup " + "while trying to register the holder MBean: " + e1,e1); } } catch (JMException e) { throw new IllegalStateException("Internal: JolokiaMBeanHolder cannot be registered to JMX: " + e,e); } return jolokiaMBeanServer; }
/** * Register an MBean at the JolokiaMBeanServer. This call is directly delegated * to the JolokiaMBeanServer * * @param object object to register * @param name object name under which to register the MBean * @return the object instance created * @throws InstanceAlreadyExistsException * @throws MBeanRegistrationException * @throws NotCompliantMBeanException */ public static ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { return getJolokiaMBeanServer().registerMBean(object, name); }
/** * Lookup the JolokiaMBean server via a JMX lookup to the Jolokia-internal MBean exposing this MBeanServer * * @return the Jolokia MBeanServer or null if not yet available present */ public static MBeanServer getJolokiaMBeanServer() { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MBeanServer jolokiaMBeanServer; try { jolokiaMBeanServer = (MBeanServer) server.getAttribute(createObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME), JOLOKIA_MBEAN_SERVER_ATTRIBUTE); } catch (InstanceNotFoundException exp) { // should be probably locked, but for simplicity reasons and because // the probability of a clash is fairly low (can happen only once), it's omitted // here. Note, that server.getAttribute() itself is threadsafe. jolokiaMBeanServer = registerJolokiaMBeanServerHolderMBean(server); } catch (JMException e) { throw new IllegalStateException("Internal: Cannot get JolokiaMBean server via JMX lookup: " + e,e); } return jolokiaMBeanServer; }
/** * Unregister an MBean at the JolokiaMBeanServer. This call is directly delegated * to the JolokiaMBeanServer * * @param name objectname of the MBean to unregister * @throws InstanceNotFoundException * @throws MBeanRegistrationException */ public static void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException { getJolokiaMBeanServer().unregisterMBean(name); }
public MBeanServer getJolokiaMBeanServer() { try { if (this.getClass("org.jolokia.jmx.JolokiaMBeanServerUtil") != null || Class.forName("org.jolokia.jmx.JolokiaMBeanServerUtil") != null) { return JolokiaMBeanServerUtil.getJolokiaMBeanServer(); } } catch (RuntimeException e) { System.out.println("No JolokiaServer found: " + e); e.printStackTrace(); return null; } catch (ClassNotFoundException e) { } System.out.println("No JolokiaServer found, ignoring certain tests ..."); return null; } }
/** * Get the Jolokia MBeanServer. This call is delegated to the corresponding * static utility method and will register a new MBeanServer if not already * present * * @return the Jolokia MBeanServer */ public MBeanServer getObject() { return JolokiaMBeanServerUtil.getJolokiaMBeanServer(); }
/** * Unregister an MBean at the JolokiaMBeanServer. This call is directly delegated * to the JolokiaMBeanServer * * @param name objectname of the MBean to unregister * @throws InstanceNotFoundException * @throws MBeanRegistrationException */ public static void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException { getJolokiaMBeanServer().unregisterMBean(name); }
/** * Register an MBean at the JolokiaMBeanServer. This call is directly delegated * to the JolokiaMBeanServer * * @param object object to register * @param name object name under which to register the MBean * @return the object instance created * @throws InstanceAlreadyExistsException * @throws MBeanRegistrationException * @throws NotCompliantMBeanException */ public static ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { return getJolokiaMBeanServer().registerMBean(object, name); }
private synchronized MBeanServer getMBeanServer() { if (mBeanServer == null) { // return platform mbean server if the option is specified. if (configuration.isUsePlatformMBeanServer()) { mBeanServer = ManagementFactory.getPlatformMBeanServer(); } else { mBeanServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer(); } } return mBeanServer; } }