Java Code Examples for javax.management.MBeanServer

The following examples show how to use javax.management.MBeanServer. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
Example 2
Source Project: openjdk-8   Source File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Full constructor
 */
public SnmpRequestHandler(SnmpAdaptorServer server, int id,
                          DatagramSocket s, DatagramPacket p,
                          SnmpMibTree tree, Vector<SnmpMibAgent> m,
                          InetAddressAcl a,
                          SnmpPduFactory factory,
                          SnmpUserDataFactory dataFactory,
                          MBeanServer f, ObjectName n)
{
    super(server, id, f, n);

    // Need a reference on SnmpAdaptorServer for getNext & getBulk,
    // in case of oid equality (mib overlapping).
    //
    adaptor = server;
    socket = s;
    packet = p;
    root= tree;
    mibs = new Vector<>(m);
    subs= new Hashtable<>(mibs.size());
    ipacl = a;
    pduFactory = factory ;
    userDataFactory = dataFactory ;
    //thread.start();
}
 
Example 3
Source Project: gemfirexd-oss   Source File: AgentImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void createRMIRegistry() throws Exception {
  if (!this.agentConfig.isRmiRegistryEnabled()) {
    return;
  }
  MBeanServer mbs = getMBeanServer();
  String host = this.agentConfig.getRmiBindAddress();
  int    port = this.agentConfig.getRmiPort();

  /* Register and start the rmi-registry naming MBean, which is
   * needed by JSR 160 RMIConnectorServer */
  ObjectName registryName = getRMIRegistryNamingName();
  try {
    RMIRegistryService registryNamingService = null;
    if (host != null && !("".equals(host.trim()))) {
      registryNamingService = new RMIRegistryService(host, port);
    } else {
      registryNamingService = new RMIRegistryService(port);
    }
    mbs.registerMBean(registryNamingService, registryName);
  } catch (javax.management.InstanceAlreadyExistsException e) {
    this.logWriter.info(LocalizedStrings.AgentImpl_0__IS_ALREADY_REGISTERED,
                        registryName);
  }
  mbs.invoke(registryName, "start", null, null);
}
 
Example 4
private static boolean test(Object mbean, boolean expectImmutable)
        throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() +
                " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
 
Example 5
Source Project: jdk8u-jdk   Source File: RandomMXBeanTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static <T> void test(MBeanServer mbs, Class<T> c) throws Exception {
    System.out.println("Testing " + c.getName());
    T merlin = c.cast(
        Proxy.newProxyInstance(c.getClassLoader(),
            new Class<?>[] {c},
            new DullInvocationHandler()));
    ObjectName merlinName = new ObjectName("a:type=" + c.getName());
    mbs.registerMBean(merlin, merlinName);
    System.out.println(mbs.getMBeanInfo(merlinName));
    T merlinProxy = JMX.newMXBeanProxy(mbs, merlinName, c);
    Method[] merlinMethods = c.getMethods();
    for (Method m : merlinMethods) {
        Class<?>[] types = m.getParameterTypes();
        Object[] params = new Object[types.length];
        for (int i = 0; i < types.length; i++)
            params[i] = DullInvocationHandler.zeroFor(types[i]);
        System.out.println("Invoking " + m.getName());
        m.invoke(merlinProxy, (Object[]) params);
    }
}
 
Example 6
private static boolean test(Object mbean, boolean expectImmutable)
        throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() +
                " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
 
Example 7
Source Project: jdk8u_jdk   Source File: MLetCommand.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (System.getSecurityManager() == null)
        throw new IllegalStateException("No security manager installed!");

    System.out.println("java.security.policy=" +
                       System.getProperty("java.security.policy"));

    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    // Register the MLetMBean
    //
    System.out.println("Create MLet MBean");
    ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean");
    mbs.createMBean("javax.management.loading.MLet", mlet);
    // Test OK!
    //
    System.out.println("Bye! Bye!");
}
 
Example 8
Source Project: glowroot   Source File: GaugeCollector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void runInternal() throws Exception {
    final List<GaugeValue> gaugeValues = Lists.newArrayList();
    if (priorRawCounterValues == null) {
        // wait to now to initialize priorGaugeValues inside of the dedicated thread
        priorRawCounterValues = Maps.newHashMap();
    }
    List<MBeanServer> mbeanServers = lazyPlatformMBeanServer.findAllMBeanServers();
    for (GaugeConfig gaugeConfig : configService.getGaugeConfigs()) {
        gaugeValues.addAll(collectGaugeValues(gaugeConfig, mbeanServers));
    }
    if (!pending.offer(gaugeValues)) {
        backPressureLogger.warn("not storing a gauge collection because of an excessive backlog"
                + " of {} gauge collections already waiting to be stored", PENDING_LIMIT);
    }
}
 
Example 9
private static void testCaseProb() throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(new CaseProbImpl(), name);
    CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class);
    try {
        CaseProb prob = proxy.getCaseProb();
        fail("No exception from proxy method getCaseProb");
    } catch (IllegalArgumentException e) {
        String messageChain = messageChain(e);
        if (messageChain.contains("URLPath")) {
            System.out.println("Message chain contains URLPath as required: "
                    + messageChain);
        } else {
            fail("Exception chain for CaseProb does not mention property" +
                    " URLPath differing only in case");
            System.out.println("Full stack trace:");
            e.printStackTrace(System.out);
        }
    }
}
 
Example 10
Source Project: commons-dbcp   Source File: TestBasicDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Make sure setting jmxName to null suppresses JMX registration of connection and statement pools.
 * JIRA: DBCP-434
 */
@Test
public void testJmxDisabled() throws Exception {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    // Unregister leftovers from other tests (TODO: worry about concurrent test execution)
    final ObjectName commons = new ObjectName("org.apache.commons.*:*");
    final Set<ObjectName> results = mbs.queryNames(commons, null);
    for (final ObjectName result : results) {
        mbs.unregisterMBean(result);
    }
    ds.setJmxName(null);  // Should disable JMX for both connection and statement pools
    ds.setPoolPreparedStatements(true);
    ds.getConnection();  // Trigger initialization
    // Nothing should be registered
    assertEquals(0, mbs.queryNames(commons, null).size());
}
 
Example 11
Source Project: brooklyn-server   Source File: PerformanceTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/** Not very fine-grained so not very useful; use {@link #getProcessCpuTime(Duration)} */ 
public static double getProcessCpuAverage() {
    try {
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName osMBeanName = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
        return (Double) mbeanServer.getAttribute(osMBeanName, "ProcessCpuLoad");
    } catch (Exception e) {
        if (!hasLoggedProcessCpuLoadUnavailable) {
            hasLoggedProcessCpuLoadUnavailable = true;
            LOG.warn("ProcessCpuLoad not available in local JVM MXBean "+ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME+" (only available in sun JVM?)");
        }
        return -1;
    }
}
 
Example 12
Source Project: tomee   Source File: EjbdJmxTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    System.setProperty("openejb.jmx.active", "true");
    final MBeanServer server = LocalMBeanServer.get();

    OpenEJB.init(new Properties());

    final Properties p = new Properties();
    p.put("server", "org.apache.openejb.server.ejbd.EjbServer");
    p.put("bind", "127.0.0.1");
    p.put("port", "0");
    p.put("disabled", "false");
    p.put("threads", "10");
    p.put("backlog", "200");
    p.put("discovery", "ejb:ejbd://{bind}:{port}");
    final ServerService service = ServiceManager.manage("ejbd", p, new EjbServer());
    service.init(p);
    service.start();

    ServiceManager.register("ejbd", service, server);

    ObjectName invocationsName = new ObjectName("openejb:type=ServerService,name=ejbd");

    MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);

    for (MBeanAttributeInfo info : beanInfo.getAttributes()) {
        System.out.println(info);
    }

    service.stop();
    OpenEJB.destroy();
}
 
Example 13
Source Project: lucene-solr   Source File: JmxMetricsReporter.java    License: Apache License 2.0 5 votes vote down vote up
private JmxListener(MBeanServer mBeanServer, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit,
                    ObjectNameFactory objectNameFactory, String tag) {
  this.mBeanServer = mBeanServer;
  this.name = name;
  this.filter = filter;
  this.rateUnit = rateUnit;
  this.durationUnit = durationUnit;
  this.registered = new ConcurrentHashMap<>();
  this.objectNameFactory = objectNameFactory;
  this.tag = tag;
  this.exp = Query.eq(Query.attr(INSTANCE_TAG), Query.value(tag));
}
 
Example 14
public MBeanServer newMBeanServer(String defaultDomain,
                                  MBeanServer outer,
                                  MBeanServerDelegate delegate) {
    final MBeanServerForwarder mbsf =
        MBeanServerForwarderInvocationHandler.newProxyInstance();

    final MBeanServer innerMBeanServer =
        inner.newMBeanServer(defaultDomain,
                             (outer == null ? mbsf : outer),
                             delegate);

    mbsf.setMBeanServer(innerMBeanServer);
    return mbsf;
}
 
Example 15
public static void main(String[] args) throws Exception {
    System.out.println("--->JRCMD MBean Test: invocation on \"help -all\" ...");

    ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
    String[] helpArgs = {"-all"};
    Object[] dcmdArgs = {helpArgs};
    String[] signature = {String[].class.getName()};

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs = null;
    JMXConnector cc = null;
    try {
        cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        cs.start();
        JMXServiceURL addr = cs.getAddress();
        cc = JMXConnectorFactory.connect(addr);
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();

        String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);
        System.out.println(result);
    } finally {
        try {
            cc.close();
            cs.stop();
        } catch (Exception e) {
        }
    }

    System.out.println("Test passed");
}
 
Example 16
public static void main(String[] args) throws Exception {

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Register the MBean
        //
        System.out.println("Create a TestDynamicMBean");
        TestDynamicMBean obj = new TestDynamicMBean();
        ObjectName n = new ObjectName("d:k=v");
        System.out.println("Register a TestDynamicMBean");
        mbs.registerMBean(obj, n);
        obj.throwException = true;
        System.out.println("Unregister a TestDynamicMBean");
        try {
            mbs.unregisterMBean(n);
        } catch (Exception e) {
            throw new IllegalArgumentException("Test failed", e);
        }
        boolean isRegistered = mbs.isRegistered(n);
        System.out.println("Is MBean Registered? " + isRegistered);

        if (isRegistered) {
            throw new IllegalArgumentException(
                "Test failed: the MBean is still registered");
        } else {
            System.out.println("Test passed");
        }
    }
 
Example 17
@Test
public void testMBeanServerNotification_REGISTRATION_NOTIFICATIONUsingMsc() throws Exception {
    KernelServices kernelServices = setup(new MBeanInfoAdditionalInitialization(ProcessType.STANDALONE_SERVER, new SubystemWithSingleFixedChildExtension()));
    ServiceController<?> service = kernelServices.getContainer().getService(MBeanServerService.SERVICE_NAME);
    MBeanServer mbeanServer = MBeanServer.class.cast(service.getValue());

    doTestMBeanServerNotification_REGISTRATION_NOTIFICATION(mbeanServer, true);
}
 
Example 18
Source Project: hottub   Source File: QueryMatchTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static int query(MBeanServer mbs,
                         String pattern,
                         String[][] data) throws Exception {

    int error = 0;

    System.out.println("\nAttribute Value Pattern = " + pattern + "\n");
    for (int i = 0; i < data.length; i++) {
        ObjectName on = new ObjectName("domain:type=Simple,pattern=" +
                                       ObjectName.quote(pattern) +
                                       ",name=" + i);
        Simple s = new Simple(data[i][0]);
        mbs.registerMBean(s, on);
        QueryExp q =
            Query.match(Query.attr("StringNumber"), Query.value(pattern));
        q.setMBeanServer(mbs);
        boolean r = q.apply(on);
        System.out.print("Attribute Value = " +
            mbs.getAttribute(on, "StringNumber"));
        if (r && "OK".equals(data[i][1])) {
            System.out.println(" OK");
        } else if (!r && "KO".equals(data[i][1])) {
            System.out.println(" KO");
        } else {
            System.out.println(" Error");
            error++;
        }
    }

    return error;
}
 
Example 19
private static Class<?> load(ClassLoader without, String className)
        throws ClassNotFoundException {
    final List<MBeanServer> mbsList = MBeanServerFactory.findMBeanServer(null);

    for (MBeanServer mbs : mbsList) {
        ClassLoaderRepository clr = mbs.getClassLoaderRepository();
        try {
            return clr.loadClassWithout(without, className);
        } catch (ClassNotFoundException e) {
            // OK : Try with next one...
        }
    }
    throw new ClassNotFoundException(className);
}
 
Example 20
public ObjectName preRegister(MBeanServer server,
                              ObjectName name) throws java.lang.Exception {
    // register all internal MBeans when this MBean is instantiated
    // and to be registered in a MBeanServer.
    ManagementFactoryHelper.registerInternalMBeans(server);
    this.server = server;
    return objName;
}
 
Example 21
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
Example 22
/** Decrypt the secret using the cipherKey.
 *
 * @param secret - the encrypted secret to decrypt.
 * @return the decrypted secret
 * @throws Exception
 */
private byte[] decode64(String secret)
   throws Exception
{
   SecurityManager sm = System.getSecurityManager();
   if( sm != null )
      sm.checkPermission(decodePermission);

   MBeanServer server = MBeanServerLocator.locateJBoss();
   return (byte[]) server.invoke(serviceName, "decode64", new Object[] {secret}, 
         new String[] {String.class.getName()});
}
 
Example 23
Source Project: jdk8u-jdk   Source File: Server.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }

    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();

    return serverUrl.toString();
}
 
Example 24
Source Project: flink   Source File: MemoryLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new memory logger that logs in the given interval and lives until the
 * given termination future completes.
 *
 * @param logger The logger to use for outputting the memory statistics.
 * @param interval The interval in which the thread logs.
 * @param monitored termination future for the system to whose life the thread is bound. The thread terminates
 *                  once the system terminates.
 */
public MemoryLogger(Logger logger, long interval, CompletableFuture<Void> monitored) {
	super("Memory Logger");
	setDaemon(true);
	setPriority(Thread.MIN_PRIORITY);
	
	this.logger = logger;
	this.interval = interval;
	this.monitored = monitored;

	this.memoryBean = ManagementFactory.getMemoryMXBean();
	this.poolBeans = ManagementFactory.getMemoryPoolMXBeans();
	this.gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

	// The direct buffer pool bean needs to be accessed via the bean server
	MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
	BufferPoolMXBean directBufferBean = null;
	try {
		directBufferBean = ManagementFactory.newPlatformMXBeanProxy(
				beanServer,
				"java.nio:type=BufferPool,name=direct",
				BufferPoolMXBean.class);
	}
	catch (Exception e) {
		logger.warn("Failed to initialize direct buffer pool bean.", e);
	}
	finally {
		this.directBufferBean = directBufferBean;
	}
}
 
Example 25
Source Project: hadoop   Source File: MBeans.java    License: Apache License 2.0 5 votes vote down vote up
static public void unregister(ObjectName mbeanName) {
  LOG.debug("Unregistering "+ mbeanName);
  final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  if (mbeanName == null) {
    LOG.debug("Stacktrace: ", new Throwable());
    return;
  }
  try {
    mbs.unregisterMBean(mbeanName);
  } catch (Exception e) {
    LOG.warn("Error unregistering "+ mbeanName, e);
  }
  DefaultMetricsSystem.removeMBeanName(mbeanName);
}
 
Example 26
public static void check(String attr, MBeanServer server, ObjectName mon,
        ObjectName mbean, long start) throws Exception {
    final Object obj = server.getAttribute(mon, "DerivedGauge");
    final long now = System.currentTimeMillis();
    final long gran = (Long)server.getAttribute(mon, "GranularityPeriod");
    if (now > start +2*gran) {
        throw new Exception(attr+": Can't verify test case: " +
                "granularity period expired!");
    }
    check(attr,server,mon,mbean,obj);
}
 
Example 27
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();

    // Get the JMX implementation version from the MBeanServerDelegateMBean
    //
    System.out.println("Get the JMX implementation version");
    ObjectName mbsdName =
        new ObjectName("JMImplementation:type=MBeanServerDelegate");
    String mbsdAttribute = "ImplementationVersion";
    String mbsdVersion = (String) mbs.getAttribute(mbsdName, mbsdAttribute);

    // Display JMX implementation version and JVM implementation version
    //
    System.out.println("JMX implementation version          = " +
                       mbsdVersion);
    System.out.println("Java Runtime implementation version = " +
                       args[0]);

    // Check JMX implementation version vs. JVM implementation version
    //
    if (Boolean.valueOf(args[1]).booleanValue()) {
        if (!mbsdVersion.equals(args[0]))
            throw new IllegalArgumentException(
              "JMX and Java Runtime implementation versions do not match!");
        // Test OK!
        //
        System.out.println("JMX and Java Runtime implementation " +
                           "versions match!");
    } else {
        // Test OK!
        //
        System.out.println("JMX and Java Runtime implementation " +
                           "versions do not match because the test " +
                           "is using an unbundled version of JMX!");
    }
    System.out.println("Bye! Bye!");
}
 
Example 28
Source Project: stratio-cassandra   Source File: EndpointSnitchInfo.java    License: Apache License 2.0 5 votes vote down vote up
public static void create()
{
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try
    {
        mbs.registerMBean(new EndpointSnitchInfo(), new ObjectName("org.apache.cassandra.db:type=EndpointSnitchInfo"));
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 29
Source Project: activemq-artemis   Source File: ActiveMQServerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setMBeanServer(MBeanServer mbeanServer) {
   if (state == SERVER_STATE.STARTING || state == SERVER_STATE.STARTED) {
      throw ActiveMQMessageBundle.BUNDLE.cannotSetMBeanserver();
   }
   this.mbeanServer = mbeanServer;
}
 
Example 30
Source Project: tomcatsrc   Source File: JmxPasswordTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPassword() throws Exception {
    Assert.assertEquals("Passwords should match when not using JMX.",password,datasource.getPoolProperties().getPassword());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ConnectionPoolMBean mbean = JMX.newMBeanProxy(mbs, oname, ConnectionPoolMBean.class);
    String jmxPassword = mbean.getPassword();
    Properties jmxProperties = mbean.getDbProperties();
    Assert.assertFalse("Passwords should not match.", password.equals(jmxPassword));
    Assert.assertFalse("Password property should be missing", jmxProperties.containsKey(PoolUtilities.PROP_PASSWORD));
}