Java Code Examples for javax.management.ObjectName#getInstance()
The following examples show how to use
javax.management.ObjectName#getInstance() .
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: NotificationListenerTests.java From java-technology-stack with MIT License | 6 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testRegisterNotificationListenerForMBean() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); JmxTestBean bean = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); Map notificationListeners = new HashMap(); notificationListeners.put(objectName, listener); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); exporter.setNotificationListenerMappings(notificationListeners); start(exporter); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); }
Example 3
Source File: ApplyWildcardTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static int runPositiveTests() { int error = 0; for (int i = 0; i < positiveTests.length; i++) { System.out.println("----------------------------------------------"); try { ObjectName on1 = ObjectName.getInstance(positiveTests[i][0]); ObjectName on2 = ObjectName.getInstance(positiveTests[i][1]); System.out.println("\"" + on1 + "\".apply(\"" + on2 + "\")"); boolean result = on1.apply(on2); System.out.println("Result = " + result); if (result == false) { error++; System.out.println("Test failed!"); } else { System.out.println("Test passed!"); } } catch (Exception e) { error++; System.out.println("Got Unexpected Exception = " + e.toString()); System.out.println("Test failed!"); } System.out.println("----------------------------------------------"); } return error; }
Example 4
Source File: ApplyWildcardTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static int runNegativeTests() { int error = 0; for (int i = 0; i < negativeTests.length; i++) { System.out.println("----------------------------------------------"); try { ObjectName on1 = ObjectName.getInstance(negativeTests[i][0]); ObjectName on2 = ObjectName.getInstance(negativeTests[i][1]); System.out.println("\"" + on1 + "\".apply(\"" + on2 + "\")"); boolean result = on1.apply(on2); System.out.println("Result = " + result); if (result == true) { error++; System.out.println("Test failed!"); } else { System.out.println("Test passed!"); } } catch (Exception e) { error++; System.out.println("Got Unexpected Exception = " + e.toString()); System.out.println("Test failed!"); } System.out.println("----------------------------------------------"); } return error; }
Example 5
Source File: ReflectionExceptionTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Test the monitor notifications. */ public int monitorNotifications() throws Exception { server = MBeanServerFactory.newMBeanServer(); MBeanServerForwarderInvocationHandler mbsfih = (MBeanServerForwarderInvocationHandler) Proxy.getInvocationHandler(server); mbsfih.setGetAttributeException( new ReflectionException(new RuntimeException(), "Test ReflectionException")); domain = server.getDefaultDomain(); obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject"); server.registerMBean(new ObservedObject(), obsObjName); echo(">>> ----------------------------------------"); int error = counterMonitorNotification(); echo(">>> ----------------------------------------"); error += gaugeMonitorNotification(); echo(">>> ----------------------------------------"); error += stringMonitorNotification(); echo(">>> ----------------------------------------"); return error; }
Example 6
Source File: RelationNotification.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private ObjectName safeGetObjectName(ObjectName src){ ObjectName dest = null; if (src != null) { dest = ObjectName.getInstance(src); } return dest; }
Example 7
Source File: Util.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static ObjectName newObjectName(String name) { try { return ObjectName.getInstance(name); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } }
Example 8
Source File: Server.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void main(String[] args) throws Exception { prepareUsersFile(); // The address of the connector server JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx"); // Specify the authenticator in the environment Map, using the // standard property JMXConnector.AUTHENTICATOR Map environment = new HashMap(); JMXAuthenticator authenticator = new PasswordAuthenticator(new File(PASSWORD_FILE)); environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator); // Create and register the connector server JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, null); ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol()); MBeanServer server = MBeanServerFactory.createMBeanServer("remote.security.example"); server.registerMBean(cntorServer, cntorServerName); // Setup the rmiregistry to bind in JNDI the RMIConnectorServer stub. NamingService naming = new NamingService(); ObjectName namingName = ObjectName.getInstance(":service=" + NamingService.class.getName()); server.registerMBean(naming, namingName); naming.start(); // Setup the interception SubjectTrackingMBeanServer interceptor = new SubjectTrackingMBeanServer(); cntorServer.setMBeanServerForwarder(interceptor); // Start the connector server cntorServer.start(); System.out.println("Server up and running"); }
Example 9
Source File: MonitoringRegionCacheListener.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void afterUpdate(EntryEvent<String, Object> event) { ObjectName objectName = null; try { if (!service.isStartedAndOpen() || !service.isManager()) { // NO OP return; No work for Non Manager Nodes return; } objectName = ObjectName.getInstance(event.getKey()); FederationComponent oldObject = (FederationComponent) event.getOldValue(); FederationComponent newObject = (FederationComponent) event.getNewValue(); String className = newObject.getMBeanInterfaceClass(); Class interfaceClass; if (classRef.get(className) != null) { interfaceClass = classRef.get(className); } else { interfaceClass = ClassLoadUtil.classFromName(className); classRef.put(className, interfaceClass); } service.afterUpdateProxy(objectName, interfaceClass, null, newObject, oldObject); } catch (Exception e) { if (logger.fineEnabled()) { logger.fine(THIS_COMPONENT + ": Aggregation Failed failed for " + objectName + "With Exception " + e); } } }
Example 10
Source File: JmxMBeanServer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Clone object name. */ private ObjectName cloneObjectName(ObjectName name) { if (name != null) { return ObjectName.getInstance(name); } return name; }
Example 11
Source File: Util.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static ObjectName newObjectName(String name) { try { return ObjectName.getInstance(name); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } }
Example 12
Source File: JmxMBeanServer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Clone object name. */ private ObjectName cloneObjectName(ObjectName name) { if (name != null) { return ObjectName.getInstance(name); } return name; }
Example 13
Source File: LauncherLifecycleCommands.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
protected MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException { assertState(isConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean."); MemberMXBean memberBean = null; try { String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX; objectNamePattern += (StringUtils.isBlank(serviceName) ? StringUtils.EMPTY_STRING : "service=" + serviceName + StringUtils.COMMA_DELIMITER); objectNamePattern += "type=Member,*"; // NOTE throws a MalformedObjectNameException, however, this should not happen since the ObjectName is constructed // here in a conforming pattern final ObjectName objectName = ObjectName.getInstance(objectNamePattern); final QueryExp query = Query.or( Query.eq(Query.attr("Name"), Query.value(member)), Query.eq(Query.attr("Id"), Query.value(member)) ); final Set<ObjectName> memberObjectNames = getGfsh().getOperationInvoker().queryNames(objectName, query); if (!memberObjectNames.isEmpty()) { memberBean = getGfsh().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class); } } catch (MalformedObjectNameException e) { getGfsh().logSevere(e.getMessage(), e); } return memberBean; }
Example 14
Source File: JmxMonitor.java From moleculer-java with MIT License | 5 votes |
public JmxMonitor() { try { server = ManagementFactory.getPlatformMBeanServer(); name = ObjectName.getInstance("java.lang:type=OperatingSystem"); } catch (Throwable cause) { cause.printStackTrace(); invalidMonitor.set(true); } }
Example 15
Source File: MemberInfoWithStatsMBeanGFEValidationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Test to check region & client details obtained through * MemberInfoWithStatsMBean with Operations done in between. * * @throws Exception one of the reasons could be failure of JMX operations */ public void testRegionAndClientDetailsWithOps() throws Exception { logWriter.fine("Entered MemberInfoWithStatsMBeanGFEValidationDUnitTest.testRegionAndClientDetails"); int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); final int numberOfOps = 1000; final String prefix = "testRegionAndClientDetailsWithOps"; //1. Start Cache & Server startCache(serverPort, HOST0, CACHE_VM); pause(5000); //wait for server initialization //2. Connect Client to the server started earlier connectClient(serverPort, HOST0, CLIENT_VM); pause(5000); //wait for client initialization ObjectName wrapper = ObjectName.getInstance(MemberInfoWithStatsMBean.MBEAN_NAME); String[] members = commonTestCode(wrapper); assertTrue("No. of members are expected be more than zero.", members.length != 0); Map<?, ?> oldData = null; Map<?, ?> currentData = null; //1. Without any ops // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (1) check without doing puts starts ..."); oldData = verifyRegionAndClientDetails(wrapper, members[0], 1/*no of regions*/, HOST0, CACHE_VM); // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (1) check without doing puts ended ..."); //2. After doing - numberOfOps - puts // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : testRegionAndClientDetailsWithOps : (2) check with doing puts starts ..."); doPuts(prefix, numberOfOps, HOST0, CACHE_VM); doGetsPutsToUpdateStats(prefix, numberOfOps, HOST0, CACHE_VM, true, false); //puts are done earlier so skipping pause(5000); //wait for ops on client to happen waitForAgentAutoRefresh(); currentData = verifyRegionAndClientDetails(wrapper, members[0], 1, HOST0, CACHE_VM); verifyVariationWithOldData(oldData, currentData); oldData = currentData; // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (2) check without doing puts ended ..."); //3. After doing - numberOfOps - deletes // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (3) check with doing deletes starts ..."); doDeletes(prefix, numberOfOps, HOST0, CACHE_VM); doGetsPutsToUpdateStats(prefix, numberOfOps, HOST0, CACHE_VM, true, true); pause(5000); //wait for ops on client to happen waitForAgentAutoRefresh(); currentData = verifyRegionAndClientDetails(wrapper, members[0], 1, HOST0, CACHE_VM); verifyVariationWithOldData(oldData, currentData); // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (3) check with doing deletes ended ..."); //4. Check after adding region // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (4) Adding region starts ..."); addRegion(DS_REGION2_NAME, prefix, 100, HOST0, CACHE_VM); waitForAgentAutoRefresh(); verifyRegionAndClientDetails(wrapper, members[0], 2/*no of regions*/, HOST0, CACHE_VM); // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (4) Adding region ended ..."); //4. Check after deleting the added region // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (5) Deleting region starts ..."); deleteRegion(DS_REGION2_NAME, HOST0, CACHE_VM); waitForAgentAutoRefresh(); verifyRegionAndClientDetails(wrapper, members[0], 1, HOST0, CACHE_VM); // logWriter.info("ABHISHEK: testRegionAndClientDetailsWithOps : (5) Deleting region ended ..."); disConnectClient(HOST0, CLIENT_VM); pause(5000); stopCache(HOST0, CACHE_VM); logWriter.fine("Exited MemberInfoWithStatsMBeanGFEValidationDUnitTest.testRegionAndClientDetails"); shouldDoGatewayHubCleanup = false; }
Example 16
Source File: ServerNotifForwarder.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Integer addNotificationListener(final ObjectName name, final NotificationFilter filter) throws InstanceNotFoundException, IOException { if (logger.traceOn()) { logger.trace("addNotificationListener", "Add a listener at " + name); } checkState(); // Explicitly check MBeanPermission for addNotificationListener // checkMBeanPermission(name, "addNotificationListener"); if (notificationAccessController != null) { notificationAccessController.addNotificationListener( connectionId, name, getSubject()); } try { boolean instanceOf = AccessController.doPrivileged( new PrivilegedExceptionAction<Boolean>() { public Boolean run() throws InstanceNotFoundException { return mbeanServer.isInstanceOf(name, broadcasterClass); } }); if (!instanceOf) { throw new IllegalArgumentException("The specified MBean [" + name + "] is not a " + "NotificationBroadcaster " + "object."); } } catch (PrivilegedActionException e) { throw (InstanceNotFoundException) extractException(e); } final Integer id = getListenerID(); // 6238731: set the default domain if no domain is set. ObjectName nn = name; if (name.getDomain() == null || name.getDomain().equals("")) { try { nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(), name.getKeyPropertyList()); } catch (MalformedObjectNameException mfoe) { // impossible, but... IOException ioe = new IOException(mfoe.getMessage()); ioe.initCause(mfoe); throw ioe; } } synchronized (listenerMap) { IdAndFilter idaf = new IdAndFilter(id, filter); Set<IdAndFilter> set = listenerMap.get(nn); // Tread carefully because if set.size() == 1 it may be the // Collections.singleton we make here, which is unmodifiable. if (set == null) set = Collections.singleton(idaf); else { if (set.size() == 1) set = new HashSet<IdAndFilter>(set); set.add(idaf); } listenerMap.put(nn, set); } return id; }
Example 17
Source File: EmptyDomainNotificationTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { final MBeanServer mbs = MBeanServerFactory.createMBeanServer(); final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); server.start(); JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null); final MBeanServerConnection mbsc = client.getMBeanServerConnection(); final ObjectName mbean = ObjectName.getInstance(":type=Simple"); mbsc.createMBean(Simple.class.getName(), mbean); System.out.println("EmptyDomainNotificationTest-main: add a listener ..."); final Listener li = new Listener(); mbsc.addNotificationListener(mbean, li, null, null); System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ..."); mbsc.invoke(mbean, "emitNotification", null, null); System.out.println("EmptyDomainNotificationTest-main: waiting notif..."); final long stopTime = System.currentTimeMillis() + 2000; synchronized(li) { long toWait = stopTime - System.currentTimeMillis(); while (li.received < 1 && toWait > 0) { li.wait(toWait); toWait = stopTime - System.currentTimeMillis(); } } if (li.received < 1) { throw new RuntimeException("No notif received!"); } else if (li.received > 1) { throw new RuntimeException("Wait one notif but got: "+li.received); } System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!"); System.out.println("EmptyDomainNotificationTest-main: remove the listener."); mbsc.removeNotificationListener(mbean, li); // clean client.close(); server.stop(); System.out.println("EmptyDomainNotificationTest-main: Bye."); }
Example 18
Source File: LocalProcessControllerJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testProcessMBean() throws Exception { final String testName = "testProcessMBean"; final int pid = ProcessUtils.identifyPid(); final Process process = new Process(pid, true); final ObjectName objectName = ObjectName.getInstance( getClass().getSimpleName() + ":testName=" + testName); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectInstance instance = server.registerMBean(process, objectName); assertNotNull(instance); try { // validate basics of the ProcessMBean Set<ObjectName> mbeanNames = server.queryNames(objectName, null); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); assertEquals(1, mbeanNames.size()); final ObjectName name = mbeanNames.iterator().next(); final MBeanInfo info = server.getMBeanInfo(name); final MBeanOperationInfo[] operInfo = info.getOperations(); assertEquals(1, operInfo.length); assertEquals("stop", operInfo[0].getName()); final MBeanAttributeInfo[] attrInfo = info.getAttributes(); assertEquals(2, attrInfo.length); // The order of these attributes is indeterminate // assertEquals("Pid", attrInfo[0].getName()); // assertEquals("Process", attrInfo[1].getName()); assertNotNull(server.getAttribute(name, "Pid")); assertNotNull(server.getAttribute(name, "Process")); assertEquals(pid, server.getAttribute(name, "Pid")); assertEquals(true, server.getAttribute(name, "Process")); // validate query using only Pid attribute QueryExp constraint = Query.eq( Query.attr("Pid"), Query.value(pid)); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong Pid finds nothing constraint = Query.eq( Query.attr("Pid"), Query.value(pid+1)); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); // validate query using both attributes constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(true)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong attribute finds nothing constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(false)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); } finally { try { server.unregisterMBean(objectName); } catch (Throwable t) { t.printStackTrace(); } } }
Example 19
Source File: MemberInfoWithStatsMBean.java From gemfirexd-oss with Apache License 2.0 | 3 votes |
/** * Queries the MBean server with the string formed using placing the params in * the parameterized string passed as queryStr. * * @param queryStr * parameterized string * @param params * params to put in the string * @return results of an ObjectName query * @throws MalformedObjectNameException * If the query expression ObjectName formed is not valid */ private Set<ObjectName> queryObjectNames(String queryStr, Object ... params) throws MalformedObjectNameException { Set<ObjectName> queried = Collections.emptySet(); queryStr = MessageFormat.format(queryStr, params); ObjectName queryExp = ObjectName.getInstance(queryStr); queried = agent.getMBeanServer().queryNames(null, queryExp); return queried; }
Example 20
Source File: ObjectNameBuilder.java From activemq-artemis with Apache License 2.0 | 2 votes |
/** * Returns the ObjectName used by DivertControl. * * @see DivertControl */ public ObjectName getDivertObjectName(final String name, String address) throws Exception { return ObjectName.getInstance(String.format("%s:broker=%s,component=addresses,address=%s,subcomponent=diverts,divert=%s", domain, ObjectName.quote(brokerName), ObjectName.quote(address.toString()), ObjectName.quote(name.toString()))); }