javax.management.MBeanServerConnection Java Examples
The following examples show how to use
javax.management.MBeanServerConnection.
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: JBossWorkManagerUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Obtain the default JBoss JCA WorkManager through a JMX lookup * for the JBossWorkManagerMBean. * @param mbeanName the JMX object name to use * @see org.jboss.resource.work.JBossWorkManagerMBean */ public static WorkManager getWorkManager(String mbeanName) { Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty"); try { Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME); InitialContext jndiContext = new InitialContext(); MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME); ObjectName objectName = ObjectName.getInstance(mbeanName); Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false); Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance"); return (WorkManager) getInstanceMethod.invoke(workManagerMBean); } catch (Exception ex) { throw new IllegalStateException( "Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex); } }
Example #2
Source File: CARBON15928JMXDisablingTest.java From micro-integrator with Apache License 2.0 | 6 votes |
private MBeanInfo testMBeanForDatasource() throws Exception { Map<String, String[]> env = new HashMap<>(); String[] credentials = { "admin", "admin" }; env.put(JMXConnector.CREDENTIALS, credentials); try { String url = "service:jmx:rmi://localhost:12311/jndi/rmi://localhost:11199/jmxrmi"; JMXServiceURL jmxUrl = new JMXServiceURL(url); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env); MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection(); ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource"); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject); return mBeanInfo; } catch (MalformedURLException | MalformedObjectNameException | IntrospectionException | ReflectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } }
Example #3
Source File: MBeanTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private Number getAggregatedValuesForCounter(String counter, MBeanServerConnection mbeanServer) { String[] members = null; try { members = getGfxdClusterMembers(mbeanServer); } catch (Exception e) { } Number aggregatedValue = 0; for (String member : members) { String memberName = member.substring(member.indexOf('(') + 1, member.indexOf(":")); @SuppressWarnings("unchecked") String clientName = ((Map<String, String>)SQLBB.getBB().getSharedMap().get(MEMBERS_MAPPING)).get(memberName); String counterName = counter + clientName; double doubleValue = getCounterNumber(counterName).doubleValue(); aggregatedValue = aggregatedValue.doubleValue() + doubleValue; Log.getLogWriter().info(counterName + " value for member : " + member + " is " + doubleValue); } return aggregatedValue; }
Example #4
Source File: JMXAccessorTask.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Execute the specified command. This logic only performs the common * attribute validation required by all subclasses; it does not perform any * functional logic directly. * * @exception BuildException * if a validation error occurs */ @Override public void execute() throws BuildException { if (testIfCondition() && testUnlessCondition()) { try { String error = null; MBeanServerConnection jmxServerConnection = getJMXConnection(); error = jmxExecute(jmxServerConnection); if (error != null && isFailOnError()) { // exception should be thrown only if failOnError == true // or error line will be logged twice throw new BuildException(error); } } catch (Exception e) { if (isFailOnError()) { throw new BuildException(e); } else { handleErrorOutput(e.getMessage()); } } finally { closeRedirector(); } } }
Example #5
Source File: JmxRemoteLoggingBean.java From cuba with Apache License 2.0 | 6 votes |
@Override public void setLoggersLevels(JmxInstance instance, final Map<String, String> updates) throws LogControlException { withConnection(instance, new JmxAction<Void>() { @Override public Void perform(JmxInstance jmx, MBeanServerConnection connection) throws Exception { JmxLogControlMBean logControlMBean = getRemoteLogControl(connection); logControlMBean.setLoggersLevels(updates); return null; } }); for (Map.Entry<String, String> logger : updates.entrySet()) { log.info(String.format("Level for logger '%s' set to '%s' on '%s'", logger.getKey(), logger.getValue(), instance.getNodeName())); } }
Example #6
Source File: ManagementUtil.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static List<String> checkForMBeanProxies(MBeanServerConnection server,List<String> listOFNS, Map<String,String> map) throws IOException{ logInfo("Checking " + listOFNS + " names on server "+ server); try { Set<ObjectName> objectNames = server.queryNames(null, null); logFine("Mbean Set registered at platform mbean server after federation : " + objectNames); for(ObjectName n : objectNames){ for(String s : map.values()) if(n.toString().contains(s)){ listOFNS.remove(s); } } logInfo("Final count of remaining mbeans not present in Manager view : " + listOFNS.size() + " List : " + listOFNS); return listOFNS; } finally{ } }
Example #7
Source File: RMIConnector.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public synchronized MBeanServerConnection getMBeanServerConnection(Subject delegationSubject) throws IOException { if (terminated) { if (logger.traceOn()) logger.trace("getMBeanServerConnection","[" + this.toString() + "] already closed."); throw new IOException("Connection closed"); } else if (!connected) { if (logger.traceOn()) logger.trace("getMBeanServerConnection","[" + this.toString() + "] is not connected."); throw new IOException("Not connected"); } return getConnectionWithSubject(delegationSubject); }
Example #8
Source File: MBeanTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void checkMemberView(boolean expectedBeans, MBeanServerConnection mbeanServer, String memberId, String serverGroup) throws MalformedObjectNameException, IOException, TestException { Log.getLogWriter().info("Checking GFXDMemberMBean for server group " + serverGroup + " and memberId : " + memberId); String memberONstr = memberONTemplate.replace("{0}", serverGroup); memberONstr = memberONstr.replace("{1}", memberId); ObjectName memberON = new ObjectName(memberONstr); // check memberMBean Log.getLogWriter().info("Querying for member instance " + memberON); try { ObjectInstance instance = mbeanServer.getObjectInstance(memberON); Log.getLogWriter().info("Found instance " + memberON + " Expected " + expectedBeans); if (!expectedBeans && instance != null) throw new TestException("Found member instance " + memberON + " when not expected "); } catch (InstanceNotFoundException e) { if (expectedBeans) { logMBeans(MessageFormat.format(ManagementConstants.OBJECTNAME__GFXDMEMBER_MXBEAN, new Object[] {"*", "*"}), mbeanServer); throw new TestException("checkMemberViewFromManager\n" + TestHelper.getStackTrace(e)); } } }
Example #9
Source File: TestManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static void connect(String pid, String address) throws Exception { if (address == null) { throw new RuntimeException("Local connector address for " + pid + " is null"); } System.out.println("Connect to process " + pid + " via: " + address); JMXServiceURL url = new JMXServiceURL(address); JMXConnector c = JMXConnectorFactory.connect(url); MBeanServerConnection server = c.getMBeanServerConnection(); System.out.println("Connected."); RuntimeMXBean rt = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); System.out.println(rt.getName()); // close the connection c.close(); }
Example #10
Source File: JmxMemoryPoolManager.java From vjtools with Apache License 2.0 | 6 votes |
public JmxMemoryPoolManager(MBeanServerConnection connection) throws IOException { List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getPlatformMXBeans(connection, MemoryPoolMXBean.class); for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) { String name = memoryPool.getName().trim(); String lowerCaseName = name.toLowerCase(); if (lowerCaseName.contains(SURVIVOR)) { survivorMemoryPool = memoryPool; } else if (lowerCaseName.contains(EDEN)) { edenMemoryPool = memoryPool; } else if (lowerCaseName.contains(OLD) || lowerCaseName.contains(TENURED)) { oldMemoryPool = memoryPool; } else if (lowerCaseName.contains(PERM) || lowerCaseName.contains(METASPACE)) { permMemoryPool = memoryPool; } else if (lowerCaseName.contains(CODE_CACHE)) { codeCacheMemoryPool = memoryPool; } else if (lowerCaseName.contains(COMPRESSED_CLASS_SPACE)) { compressedClassSpaceMemoryPool = memoryPool; } } }
Example #11
Source File: ManagementUtil.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static List<String> getBeanProxiesForBlackboardMap(MBeanServerConnection server, Map<String,String> map) throws IOException{ String clientName = RemoteTestModule.getMyClientName(); String array[] = clientName.split("_"); logFine("clientName split Array DSName = " + HydraUtil.ObjectToString(array)); logFine("clientName split Array length = " + array.length); String dsName= null; if(array.length>=4){ //wan test assume last part if DS Name dsName = array[array.length-1]; logInfo("Considering names of clients with DSName = " + dsName); } //int count = map.size(); int count = 0; List<String> listOFNS = new ArrayList<String>(); for(String s: map.values()){ if(dsName==null || (dsName!=null&& s.contains(dsName))){ listOFNS.add(s); count++; } } logInfo("getBeanProxiesForBlackboardMap : " + listOFNS); return listOFNS; }
Example #12
Source File: TestUtils.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Transfroms a proxy implementing T in a proxy implementing T plus * NotificationEmitter * **/ public static <T> T makeNotificationEmitter(T proxy, Class<T> mbeanInterface) { if (proxy instanceof NotificationEmitter) return proxy; if (proxy == null) return null; if (!(proxy instanceof Proxy)) throw new IllegalArgumentException("not a "+Proxy.class.getName()); final Proxy p = (Proxy) proxy; final InvocationHandler handler = Proxy.getInvocationHandler(proxy); if (!(handler instanceof MBeanServerInvocationHandler)) throw new IllegalArgumentException("not a JMX Proxy"); final MBeanServerInvocationHandler h = (MBeanServerInvocationHandler)handler; final ObjectName name = h.getObjectName(); final MBeanServerConnection mbs = h.getMBeanServerConnection(); final boolean isMXBean = h.isMXBean(); final T newProxy; if (isMXBean) newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true); else newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true); return newProxy; }
Example #13
Source File: VMOptionOpenDataTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String... args) throws Exception { MBeanServerConnection msc = ManagementFactory.getPlatformMBeanServer(); HotSpotDiagnosticMXBean mxbean = ManagementFactory.getPlatformMXBean(msc, HotSpotDiagnosticMXBean.class); String[] signatures = new String[] { String.class.getName() }; Object obj = msc.invoke(mxbean.getObjectName(), "getVMOption", new String[] { "PrintVMOptions"}, signatures); CompositeData data = (CompositeData)obj; validateType(data); VMOption option = mxbean.getVMOption("PrintVMOptions"); VMOption o = VMOption.from(data); assertEquals(option, o); }
Example #14
Source File: AuthorizationTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected int doCreateRequest(MBeanServerConnection mbsc, ObjectName on, boolean expectedException) { int errorCount = 0; try { Utils.debug(Utils.DEBUG_STANDARD, "ClientSide::doCreateRequest: Create and register the MBean") ; mbsc.createMBean("Simple", on) ; if (expectedException) { System.out.println("ClientSide::doCreateRequest: " + "(ERROR) Create did not fail with expected SecurityException"); errorCount++; } else { System.out.println("ClientSide::doCreateRequest: (OK) Create succeed") ; } } catch(Exception e) { Utils.printThrowable(e, true) ; if (expectedException) { if (e instanceof java.lang.SecurityException) { System.out.println("ClientSide::doCreateRequest: " + "(OK) Create failed with expected SecurityException") ; } else { System.out.println("ClientSide::doCreateRequest: " + "(ERROR) Create failed with " + e.getClass() + " instead of expected SecurityException"); errorCount++; } } else { System.out.println("ClientSide::doCreateRequest: " + "(ERROR) Create failed"); errorCount++; } } return errorCount; }
Example #15
Source File: GroovyMBean.java From groovy with Apache License 2.0 | 5 votes |
public GroovyMBean(MBeanServerConnection server, ObjectName name, boolean ignoreErrors) throws JMException, IOException { this.server = server; this.name = name; this.ignoreErrors = ignoreErrors; this.beanInfo = server.getMBeanInfo(name); MBeanOperationInfo[] operationInfos = beanInfo.getOperations(); for (MBeanOperationInfo info : operationInfos) { String signature[] = createSignature(info); // Construct a simplistic key to support overloaded operations on the MBean. String operationKey = createOperationKey(info.getName(), signature.length); operations.put(operationKey, signature); } }
Example #16
Source File: KafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** * Get kafka version. */ public String getKafkaVersion(String host, int port, String ids, String clusterAlias) { JMXConnector connector = null; String version = "-"; String JMX = "service:jmx:rmi:///jndi/rmi://%s/jmxrmi"; try { JMXServiceURL jmxSeriverUrl = new JMXServiceURL(String.format(JMX, host + ":" + port)); connector = JMXFactoryUtils.connectWithTimeout(jmxSeriverUrl, 30, TimeUnit.SECONDS); MBeanServerConnection mbeanConnection = connector.getMBeanServerConnection(); if (CollectorType.KAFKA.equals(SystemConfigUtils.getProperty(clusterAlias + ".kafka.eagle.offset.storage"))) { version = mbeanConnection.getAttribute(new ObjectName(String.format(BrokerServer.BROKER_VERSION.getValue(), ids)), BrokerServer.BROKER_VERSION_VALUE.getValue()).toString(); } else { version = mbeanConnection.getAttribute(new ObjectName(KafkaServer8.VERSION.getValue()), KafkaServer8.VALUE.getValue()).toString(); } } catch (Exception ex) { LOG.error("Get kafka version from jmx has error, msg is " + ex.getMessage()); } finally { if (connector != null) { try { connector.close(); } catch (IOException e) { LOG.error("Close jmx connector has error, msg is " + e.getMessage()); } } } return version; }
Example #17
Source File: JMXInterpreter.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
@Override public MBeanServerConnection getConnection() { if(connection == null) { throw new IllegalStateException("not connected: " + describeConnection()); } return connection; }
Example #18
Source File: JmxClient.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the connection, but don't bother with the recovery protocol if the * connection is lost. * * @return An optional with a connection, or empty optional indicating there * is no connection. */ public synchronized Optional<MBeanServerConnection> getOptionalConnection() { if (conn_ != null && conn_.isCompletedExceptionally()) conn_ = null; if (conn_ != null && conn_.isDone() && !conn_.isCompletedExceptionally()) { try { MBeanServerConnection result = conn_.get().get().getMBeanServerConnection(); result.getMBeanCount(); return Optional.of(result); } catch (Exception ex) { conn_ = null; // Connection gone bad. } } return Optional.empty(); }
Example #19
Source File: OldMBeanServerTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public MBeanServerConnection call() { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); try { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer( url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); connector = JMXConnectorFactory.connect(addr); return connector.getMBeanServerConnection(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #20
Source File: ConcurrentModificationTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void mbeanOp(MBeanServerConnection mserver, ObjectName name, boolean adding) throws Exception { if (adding) { mserver.createMBean("javax.management.timer.Timer", name); } else { mserver.unregisterMBean(name); } }
Example #21
Source File: WebLogicDeployer.java From netbeans with Apache License 2.0 | 5 votes |
private static URL getServerUrl(MBeanServerConnection connection, ObjectName serverRuntime, String method, String protocol, String contextRoot) { try { String url = (String) connection.invoke( serverRuntime, method, new Object[]{protocol}, new String[]{"java.lang.String"}); // NOI18N if (url == null) { return null; } return new URL(url + contextRoot); } catch (InstanceNotFoundException | MBeanException | ReflectionException | IOException ex) { LOGGER.log(Level.INFO, null, ex); } return null; }
Example #22
Source File: AbstractJMXDataProviderTest.java From perfmon-agent with Apache License 2.0 | 5 votes |
/** * Test of getProvider method, of class AbstractJMXDataProvider. */ public void testGetProvider() throws Exception { System.out.println("getProvider"); MBeanServerConnection mBeanServerConn = new EmulatorMBeanServerConnection(); String params = "gc-time"; Class expResult = GCDataProvider.class; AbstractJMXDataProvider result = AbstractJMXDataProvider.getProvider(mBeanServerConn, params); assertEquals(expResult, result.getClass()); }
Example #23
Source File: JMXRemoteManagementEndpointArquillianTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test @RunAsClient public void testRemoteConnection() throws Exception { String urlString = "service:jmx:remote+http://localhost:9990"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null); MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); int count = connection.getMBeanCount(); assertThat(count).isGreaterThan(1); jmxConnector.close(); }
Example #24
Source File: MXBeanInteropTest1.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private final int doOperatingSystemMXBeanTest(MBeanServerConnection mbsc) { int errorCount = 0 ; System.out.println("---- OperatingSystemMXBean") ; try { ObjectName operationName = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME) ; MBeanInfo mbInfo = mbsc.getMBeanInfo(operationName); errorCount += checkNonEmpty(mbInfo); System.out.println("getMBeanInfo\t\t" + mbInfo); OperatingSystemMXBean operation = null ; operation = JMX.newMXBeanProxy(mbsc, operationName, OperatingSystemMXBean.class) ; System.out.println("getArch\t\t" + operation.getArch()); System.out.println("getAvailableProcessors\t\t" + operation.getAvailableProcessors()); System.out.println("getName\t\t" + operation.getName()); System.out.println("getVersion\t\t" + operation.getVersion()); System.out.println("---- OK\n") ; } catch (Exception e) { Utils.printThrowable(e, true) ; errorCount++ ; System.out.println("---- ERROR\n") ; } return errorCount ; }
Example #25
Source File: RMIConnector.java From Java8CN with Apache License 2.0 | 5 votes |
private void initTransients() { rmbscMap = new WeakHashMap<Subject, WeakReference<MBeanServerConnection>>(); connected = false; terminated = false; connectionBroadcaster = new NotificationBroadcasterSupport(); }
Example #26
Source File: OldMBeanServerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public MBeanServerConnection call() { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); try { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer( url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); connector = JMXConnectorFactory.connect(addr); return connector.getMBeanServerConnection(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #27
Source File: MXBeanInteropTest1.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) { int errorCount = 0 ; System.out.println("---- CompilationMXBean") ; try { ObjectName compilationName = new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME); if ( mbsc.isRegistered(compilationName) ) { MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName); errorCount += checkNonEmpty(mbInfo); System.out.println("getMBeanInfo\t\t" + mbInfo); CompilationMXBean compilation = null ; compilation = JMX.newMXBeanProxy(mbsc, compilationName, CompilationMXBean.class) ; System.out.println("getName\t\t" + compilation.getName()); boolean supported = compilation.isCompilationTimeMonitoringSupported() ; System.out.println("isCompilationTimeMonitoringSupported\t\t" + supported); if ( supported ) { System.out.println("getTotalCompilationTime\t\t" + compilation.getTotalCompilationTime()); } } System.out.println("---- OK\n") ; } catch (Exception e) { Utils.printThrowable(e, true) ; errorCount++ ; System.out.println("---- ERROR\n") ; } return errorCount ; }
Example #28
Source File: OldMBeanServerTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public MBeanServerConnection call() { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); try { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer( url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); connector = JMXConnectorFactory.connect(addr); return connector.getMBeanServerConnection(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #29
Source File: ModelControllerMBeanTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public void doTestMBeanServerNotification_REGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception { final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test"); final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only"); final CountDownLatch notificationEmitted = new CountDownLatch(1); final AtomicReference<Notification> notification = new AtomicReference<>(); NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN); NotificationFilterSupport filter = new NotificationFilterSupport(); filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION); connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null); // add a management resource connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()}); if (mustReceiveNotification) { Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS)); Notification notif = notification.get(); Assert.assertNotNull(notif); Assert.assertTrue(notif instanceof MBeanServerNotification); MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif; Assert.assertEquals(MBeanServerNotification.REGISTRATION_NOTIFICATION, notif.getType()); Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName()); } else { Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS)); } connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null); }
Example #30
Source File: Client.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) throws Exception { // This JMXServiceURL works only if the connector server is in-VM with // the connector. If this is not the case, set the correct host name. JMXServiceURL address = new JMXServiceURL("soap", null, 8080, "/jmxconnector"); // Connect a JSR 160 JMXConnector to the server side JMXConnector connector = JMXConnectorFactory.connect(address); // Retrieve an MBeanServerConnection that represent the MBeanServer // the remote connector server is bound to MBeanServerConnection connection = connector.getMBeanServerConnection(); // Call the server side as if it is a local MBeanServer ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true); MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy; System.out.println(delegate.getImplementationVendor() + " is cool !"); // Register an MBean, and get notifications via the SOAP protocol connection.addNotificationListener(delegateName, new NotificationListener() { public void handleNotification(Notification notification, Object handback) { System.out.println("Got the following notification: " + notification); } }, null, null); ObjectName timerName = ObjectName.getInstance("services:type=Timer"); connection.createMBean(Timer.class.getName(), timerName, null); // Unregistering the MBean to get another notification connection.unregisterMBean(timerName); // Allow the unregistration notification to arrive before killing this JVM Thread.sleep(1000); connector.close(); }