javax.management.ObjectName Java Examples
The following examples show how to use
javax.management.ObjectName.
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: MBeanFallbackTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static void testPrivate(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a private MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a private MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #2
Source File: MBeanExporter.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public ObjectName registerManagedResource(Object managedResource) throws MBeanExportException { Assert.notNull(managedResource, "Managed resource must not be null"); ObjectName objectName; try { objectName = getObjectName(managedResource, null); if (this.ensureUniqueRuntimeObjectNames) { objectName = JmxUtils.appendIdentityToObjectName(objectName, managedResource); } } catch (Throwable ex) { throw new MBeanExportException("Unable to generate ObjectName for MBean [" + managedResource + "]", ex); } registerManagedResource(managedResource, objectName); return objectName; }
Example #3
Source File: TestMonitoredCounterGroup.java From mt-flume with Apache License 2.0 | 6 votes |
private void assertSrcCounterState(ObjectName on, long eventReceivedCount, long eventAcceptedCount, long appendReceivedCount, long appendAcceptedCount, long appendBatchReceivedCount, long appendBatchAcceptedCount) throws Exception { Assert.assertEquals("SrcEventReceived", getSrcEventReceivedCount(on), eventReceivedCount); Assert.assertEquals("SrcEventAccepted", getSrcEventAcceptedCount(on), eventAcceptedCount); Assert.assertEquals("SrcAppendReceived", getSrcAppendReceivedCount(on), appendReceivedCount); Assert.assertEquals("SrcAppendAccepted", getSrcAppendAcceptedCount(on), appendAcceptedCount); Assert.assertEquals("SrcAppendBatchReceived", getSrcAppendBatchReceivedCount(on), appendBatchReceivedCount); Assert.assertEquals("SrcAppendBatchAccepted", getSrcAppendBatchAcceptedCount(on), appendBatchAcceptedCount); }
Example #4
Source File: MBeanFactory.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Create a new UserDatabaseRealm. * * @param parent MBean Name of the associated parent component * @param resourceName Global JNDI resource name of the associated * UserDatabase * @return the object name of the created realm * * @exception Exception if an MBean cannot be created or registered */ public String createUserDatabaseRealm(String parent, String resourceName) throws Exception { // Create a new UserDatabaseRealm instance UserDatabaseRealm realm = new UserDatabaseRealm(); realm.setResourceName(resourceName); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Container container = getParentContainerFromParent(pname); // Add the new instance to its parent component container.setRealm(realm); // Return the corresponding MBean name ObjectName oname = realm.getObjectName(); // FIXME getObjectName() returns null //ObjectName oname = // MBeanUtils.createObjectName(pname.getDomain(), realm); if (oname != null) { return (oname.toString()); } else { return null; } }
Example #5
Source File: ExceptionDiagnosisTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: MLetCommand.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: JVM_MANAGEMENT_MIB.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Initialization of the MIB with AUTOMATIC REGISTRATION in Java DMK. */ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { // Allow only one initialization of the MIB. // if (isInitialized == true) { throw new InstanceAlreadyExistsException(); } // Initialize MBeanServer information. // this.server = server; populate(server, name); isInitialized = true; return name; }
Example #8
Source File: Repository.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Retrieves the MBean of the name specified from the repository. The * object name must match exactly. * * @param name name of the MBean to retrieve. * * @return The retrieved MBean if it is contained in the repository, * null otherwise. */ public DynamicMBean retrieve(ObjectName name) { if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, Repository.class.getName(), "retrieve", "name = " + name); } // Calls internal retrieve method to get the named object lock.readLock().lock(); try { NamedObject no = retrieveNamedObject(name); if (no == null) return null; else return no.getObject(); } finally { lock.readLock().unlock(); } }
Example #9
Source File: JVM_MANAGEMENT_MIB.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Initialization of the "JvmRuntime" group. * * To disable support of this group, redefine the * "createJvmRuntimeMetaNode()" factory method, and make it return "null" * * @param server MBeanServer for this group (may be null) * **/ protected void initJvmRuntime(MBeanServer server) throws Exception { final String oid = getGroupOid("JvmRuntime", "1.3.6.1.4.1.42.2.145.3.163.1.1.4"); ObjectName objname = null; if (server != null) { objname = getGroupObjectName("JvmRuntime", oid, mibName + ":name=sun.management.snmp.jvmmib.JvmRuntime"); } final JvmRuntimeMeta meta = createJvmRuntimeMetaNode("JvmRuntime", oid, objname, server); if (meta != null) { meta.registerTableNodes( this, server ); // Note that when using standard metadata, // the returned object must implement the "JvmRuntimeMBean" // interface. // final JvmRuntimeMBean group = (JvmRuntimeMBean) createJvmRuntimeMBean("JvmRuntime", oid, objname, server); meta.setInstance( group ); registerGroupNode("JvmRuntime", oid, objname, meta, group, server); } }
Example #10
Source File: NamingResourcesMBean.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Remove any resource link reference with the specified name. * * @param resourceLinkName Name of the resource link reference to remove */ public void removeResourceLink(String resourceLinkName) { resourceLinkName = ObjectName.unquote(resourceLinkName); NamingResources nresources = (NamingResources) this.resource; if (nresources == null) { return; } ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName); if (resourceLink == null) { throw new IllegalArgumentException ("Invalid resource Link name '" + resourceLinkName + "'"); } nresources.removeResourceLink(resourceLinkName); }
Example #11
Source File: ROConnection.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
/** * @see javax.management.MBeanServerConnection#getObjectInstance(javax.management.ObjectName) */ public ObjectInstance getObjectInstance(final ObjectName name) throws InstanceNotFoundException, IOException { if (this.subject == null) { return this.mbs.getObjectInstance(name); } try { return (ObjectInstance) Subject.doAsPrivileged(this.subject, new PrivilegedExceptionAction<ObjectInstance>() { public final ObjectInstance run() throws Exception { return mbs.getObjectInstance(name); } }, this.context); } catch (final PrivilegedActionException pe) { final Exception e = JMXProviderUtils.extractException(pe); if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException) e; if (e instanceof IOException) throw (IOException) e; throw JMXProviderUtils.newIOException("Got unexpected server exception: " + e, e); } }
Example #12
Source File: ImmutableNotificationInfoTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #13
Source File: ScanManager.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Creates a default singleton ObjectName for a given class. * @param clazz The interface class of the MBean for which we want to obtain * a default singleton name, or its implementation class. * Give one or the other depending on what you wish to see in * the value of the key {@code type=}. * @return A default singleton name for a singleton MBean class. * @throws IllegalArgumentException if the name can't be created * for some unfathomable reason (e.g. an unexpected * exception was raised). **/ public final static ObjectName makeSingletonName(Class clazz) { try { final Package p = clazz.getPackage(); final String packageName = (p==null)?null:p.getName(); final String className = clazz.getSimpleName(); final String domain; if (packageName == null || packageName.length()==0) { // We use a reference to ScanDirAgent.class to ease // to keep track of possible class renaming. domain = ScanDirAgent.class.getSimpleName(); } else { domain = packageName; } final ObjectName name = new ObjectName(domain,"type",className); return name; } catch (Exception x) { final IllegalArgumentException iae = new IllegalArgumentException(String.valueOf(clazz),x); throw iae; } }
Example #14
Source File: MBeanServerAccessController.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { checkRead(); return getMBeanServer().getAttribute(name, attribute); }
Example #15
Source File: MBeanUtil.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Unregisters all GemFire MBeans and then releases the MBeanServer for * garbage collection. */ static void releaseMBeanServer() { try { // unregister all GemFire mbeans... Iterator iter = mbeanServer.queryNames(null, null).iterator(); while (iter.hasNext()) { ObjectName name = (ObjectName)iter.next(); if (name.getDomain().startsWith(DEFAULT_DOMAIN)) { unregisterMBean(name); } } // last, release the mbean server... MBeanServerFactory.releaseMBeanServer(mbeanServer); mbeanServer = null; } catch (JMRuntimeException e) { logStackTrace(LogWriterImpl.WARNING_LEVEL, e); } /* See #42391. Cleaning up the static maps which might be still holding * references to ManagedResources */ synchronized (MBeanUtil.managedResources) { MBeanUtil.managedResources.clear(); } synchronized (refreshClients) { refreshClients.clear(); } /* See #42391. Cleaning up the static maps which might be still holding * references to ManagedResources */ synchronized (MBeanUtil.managedResources) { MBeanUtil.managedResources.clear(); } synchronized (refreshClients) { refreshClients.clear(); } }
Example #16
Source File: ScanManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void unregisterMBeans(Map<ObjectName,?> map) throws JMException { for (ObjectName key : map.keySet()) { if (mbeanServer.isRegistered(key)) mbeanServer.unregisterMBean(key); map.remove(key); } }
Example #17
Source File: MBeanServerAccessController.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ @Deprecated public ObjectInputStream deserialize(ObjectName name, byte[] data) throws InstanceNotFoundException, OperationsException { checkRead(); return getMBeanServer().deserialize(name, data); }
Example #18
Source File: ArrayNotificationBuffer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void removeNotificationListener(final ObjectName name, final NotificationListener listener) throws Exception { try { AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { mBeanServer.removeNotificationListener(name, listener); return null; } }); } catch (Exception e) { throw extractException(e); } }
Example #19
Source File: NotificationAccessControllerTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void emitNotification(int seqnum, ObjectName name) { if (name == null) { sendNotification(new Notification("nb", this, seqnum)); } else { sendNotification(new Notification("nb", name, seqnum)); } }
Example #20
Source File: DefaultMBeanServerInterceptor.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException { removeNotificationListener(name, listener, filter, handback, false); }
Example #21
Source File: JConsoleResultNameStrategyImplTest.java From jmxtrans-agent with MIT License | 5 votes |
@Test public void testGetResultNameWithNullAttributeName() throws Exception { Query query = new Query("*:*", "count", null, strategy); String objectName = "Catalina:type=Resource,resourcetype=Context,host=localhost,class=javax.sql.DataSource,name=\"jdbc/my-datasource\""; String actual = strategy.getResultName(query, new ObjectName(objectName), "usage", null, null); assertThat(actual, is("Catalina.javax.sql.DataSource.localhost.jdbc_my-datasource.Context.Resource.usage")); }
Example #22
Source File: OldMBeanServerTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void removeNotificationListener( ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException { NotificationBroadcaster userMBean = (NotificationBroadcaster) getUserMBean(name); NotificationListener wrappedListener = wrappedListener(name, userMBean, listener); userMBean.removeNotificationListener(wrappedListener); }
Example #23
Source File: EnableMBeanExportConfigurationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testLazyAssembling() throws Exception { System.setProperty("domain", "bean"); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(LazyAssemblingConfiguration.class); try { MBeanServer server = (MBeanServer) ctx.getBean("server"); ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4"); assertNotNull(server.getObjectInstance(oname)); String name = (String) server.getAttribute(oname, "Name"); assertEquals("Invalid name returned", "TEST", name); oname = ObjectNameManager.getInstance("bean:name=testBean5"); assertNotNull(server.getObjectInstance(oname)); name = (String) server.getAttribute(oname, "Name"); assertEquals("Invalid name returned", "FACTORY", name); oname = ObjectNameManager.getInstance("spring:mbean=true"); assertNotNull(server.getObjectInstance(oname)); name = (String) server.getAttribute(oname, "Name"); assertEquals("Invalid name returned", "Rob Harrop", name); oname = ObjectNameManager.getInstance("spring:mbean=another"); assertNotNull(server.getObjectInstance(oname)); name = (String) server.getAttribute(oname, "Name"); assertEquals("Invalid name returned", "Juergen Hoeller", name); } finally { System.clearProperty("domain"); ctx.close(); } }
Example #24
Source File: SnmpGenericObjectServer.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Set the value of an SNMP variable. * * <p><b><i> * You should never need to use this method directly. * </i></b></p> * * @param meta The impacted metadata object * @param name The ObjectName of the impacted MBean * @param x The new requested SnmpValue * @param id The OID arc identifying the variable we're trying to set. * @param data User contextual data allocated through the * {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory} * * @return The new value of the variable after the operation. * * @exception SnmpStatusException whenever an SNMP exception must be * raised. Raising an exception will abort the request. <br> * Exceptions should never be raised directly, but only by means of * <code> * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>) * </code> **/ public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException { final String attname = meta.getAttributeName(id); final Object attvalue= meta.buildAttributeValue(id,x); final Attribute att = new Attribute(attname,attvalue); Object result = null; try { server.setAttribute(name,att); result = server.getAttribute(name,attname); } catch(InvalidAttributeValueException iv) { throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue); } catch (InstanceNotFoundException f) { throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName); } catch (ReflectionException r) { throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName); } catch (MBeanException m) { Exception t = m.getTargetException(); if (t instanceof SnmpStatusException) throw (SnmpStatusException) t; throw new SnmpStatusException(SnmpStatusException.noAccess); } catch (Exception e) { throw new SnmpStatusException(SnmpStatusException.noAccess); } return meta.buildSnmpValue(id,result); }
Example #25
Source File: RabbitMetricsBinder.java From summerframework with Apache License 2.0 | 5 votes |
private double getValue(MBeanServer mBeanServer, ObjectName objectName, String attribute) { try { Properties cacheProperties = (Properties)mBeanServer.getAttribute(objectName, "CacheProperties"); return Double.parseDouble(cacheProperties.getProperty(attribute)); } catch (Exception e) { return Double.NaN; } }
Example #26
Source File: InstrumentationManagerImpl.java From cxf with Apache License 2.0 | 5 votes |
private ObjectName getDelegateName() throws JMException { try { return (ObjectName)MBeanServerDelegate.class.getField("DELEGATE_NAME").get(null); } catch (Throwable t) { //ignore, likely on Java5 } try { return new ObjectName("JMImplementation:type=MBeanServerDelegate"); } catch (MalformedObjectNameException e) { JMException jme = new JMException(e.getMessage()); jme.initCause(e); throw jme; } }
Example #27
Source File: JmxMBeanServer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void checkMBeanPermission(String classname, String member, ObjectName objectName, String actions) throws SecurityException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { Permission perm = new MBeanPermission(classname, member, objectName, actions); sm.checkPermission(perm); } }
Example #28
Source File: MBeanExporter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Registers an existing MBean or an MBean adapter for a plain bean * with the {@code MBeanServer}. * @param bean the bean to register, either an MBean or a plain bean * @param beanKey the key associated with this bean in the beans map * @return the {@code ObjectName} under which the bean was registered * with the {@code MBeanServer} */ private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException { ObjectName objectName = getObjectName(bean, beanKey); Object mbeanToExpose = null; if (isMBean(bean.getClass())) { mbeanToExpose = bean; } else { DynamicMBean adaptedBean = adaptMBeanIfPossible(bean); if (adaptedBean != null) { mbeanToExpose = adaptedBean; } } if (mbeanToExpose != null) { if (logger.isInfoEnabled()) { logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]"); } doRegister(mbeanToExpose, objectName); } else { if (logger.isInfoEnabled()) { logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]"); } ModelMBean mbean = createAndConfigureMBean(bean, beanKey); doRegister(mbean, objectName); injectNotificationPublisherIfNecessary(bean, mbean, objectName); } return objectName; }
Example #29
Source File: JMXService.java From incubator-iotdb with Apache License 2.0 | 5 votes |
/** * function for deregistering MBean. */ public static void deregisterMBean(String name) { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(name); if (mbs.isRegistered(objectName)) { mbs.unregisterMBean(objectName); } } catch (MalformedObjectNameException | MBeanRegistrationException | InstanceNotFoundException e) { logger.error("Failed to unregisterMBean {}", name, e); } }
Example #30
Source File: Util.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static ObjectName newObjectName(String string) { try { return new ObjectName(string); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } }