Java 8 MBeanServerConnection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 MBeanServerConnection class.

This code example shows how to use the following methods:getAttribute, queryNames
 
    private ObjectName assertExists( ObjectName name )
    { 
        try 
        { 
            if ( !server.queryNames( name, null ).isEmpty() )
            { 
                return name;
            } 
        } 
        catch ( IOException handled )
        { 
            // fall through 
        } 
        throw new NoSuchElementException( "No MBeans matching " + name );
    } 
 
    protected <T> T getBean( Class<T> beanInterface )
    { 
        return BeanProxy.load( server, beanInterface, createObjectName( beanInterface ) );

6
CodeRank
This code example shows how to use the following methods:invoke, queryNames
        if (virtualHost != null)
        { 
            ObjectName virtualHostMBeanName = new ObjectName("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost="
                    + ObjectName.quote(virtualHost));
 
            Set<ObjectName> virtualHostMBeans = connection.queryNames(virtualHostMBeanName, null);
            if(virtualHostMBeans.size() == 0)
            { 
                throw new IllegalArgumentException("VirtualHost MBean was not found for virtual host " + virtualHost);
            } 
 
            createAndBindQueueIfRequired(arguments, iteration, connection, virtualHostMBeanName);
        } 
    } 
 
    private void log(String logMessage)
    { 
        System.out.println(logMessage);
    } 
 

6
CodeRank
This code example shows how to use the following methods:getAttribute, invoke
        try { 
            connector = this.getJMXConnector();
            MBeanServerConnection connection = connector.getMBeanServerConnection();
            ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
            int oldNum = getInstancesNum(connection, name);  
            connection.invoke(name, "createInstance", new Object[]{ "itest2", 0, 0, 0, null, null, null, null },
                    new String[]{ "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" });
            Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
            connection.invoke(name, "destroyInstance", new Object[]{ "itest2" }, new String[]{ "java.lang.String" });
            Assert.assertEquals(oldNum, getInstancesNum(connection, name));
        } finally { 
            if (connector != null)
        	    close(connector);
        } 
    } 
 
    private int getInstancesNum(MBeanServerConnection connection, ObjectName name) throws Exception {
        TabularData instances = (TabularData) connection.getAttribute(name, "Instances");
        return instances.size();
    } 

6
CodeRank
This code example shows how to use the following methods:getAttribute, invoke
     
    processEngineConfig.getJobExecutor().shutdown();
     
    // first check that job executor is not activated and correctly reported as being inactive 
    assertFalse(processEngineConfig.isJobExecutorActivate());
    assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
    // now activate it remotely 
    mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate", new Boolean[]{true}, new String[]{Boolean.class.getName()});
     
    // check if it has the effect and correctly reported 
//    assertTrue(processEngineConfig.getJobExecutor().isActive()); 
    assertTrue((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
     
    //agani disable and check it     
    mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate",  new Boolean[]{false}, new String[]{Boolean.class.getName()});
     
    // check if it has the effect and correctly reported 
    assertFalse(processEngineConfig.isJobExecutorActivate());
    assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
  } 

6
CodeRank
This code example shows how to use the following methods:getAttribute, getDefaultDomain
This code example shows how to use the following methods:getAttribute
	/** 
	 * Retrieves the JMX attribute value. 
	 */ 
	@Override 
	protected Object doReceive() { 
		Assert.notNull(this.server, "MBeanServer is required");
		Assert.notNull(this.objectName, "object name is required");
		Assert.notNull(this.attributeName, "attribute name is required");
		try { 
			return this.server.getAttribute(this.objectName, this.attributeName);
		} 
		catch (Exception e) {
			throw new MessagingException("failed to retrieve JMX attribute '" 
					+ this.attributeName + "' on MBean [" + this.objectName + "]", e);
		} 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:invoke
      ObjectInstance manager = cacheManagers.get(activeCacheManager);
      // Shallow copy of the commands to avoid being cleared when the buffer is reset 
      List<ProcessedCommand> bufferedCommands = new ArrayList<ProcessedCommand>(commandBuffer.getBufferedCommands());
      try { 
         String sessionId = getSession(manager);
         Map<String, String> response = (Map<String, String>) mbsc.invoke(manager.getObjectName(), "execute", new String[] { sessionId, commandBuffer.toString() },
               new String[] { String.class.getName(), String.class.getName() });
         if (response.containsKey("OUTPUT")) {
            context.result(bufferedCommands, response.get("OUTPUT"), false);
         } 
         if (response.containsKey("ERROR")) {
            context.result(bufferedCommands, response.get("ERROR"), true);
         } 
         if (response.containsKey("CACHE")) {
            activeCache = response.get("CACHE");
         } 
      } catch (InstanceNotFoundException e) {
         context.result(bufferedCommands, e.toString(), true);
      } catch (MBeanException e) {
         Exception te = e.getTargetException();

6
CodeRank
This code example shows how to use the following methods:sleep, addNotificationListener, createMBean, invoke, removeNotificationListener
            // Create NB MBean 
            // 
            ObjectName nb1 = ObjectName.getInstance("domain:type=NB,name=1");
            ObjectName nb2 = ObjectName.getInstance("domain:type=NB,name=2");
            ObjectName nb3 = ObjectName.getInstance("domain:type=NB,name=3");
            mbsc.createMBean(NB.class.getName(), nb1);
            mbsc.createMBean(NB.class.getName(), nb2);
            mbsc.createMBean(NB.class.getName(), nb3);
 
            // Add notification listener 
            // 
            Listener li = new Listener();
            mbsc.addNotificationListener(nb1, li, null, null);
            mbsc.addNotificationListener(nb2, li, null, null);
 
            // Set security manager 
            // 
            if (sm) {
                echo("Setting SM"); 
                System.setSecurityManager(new SecurityManager());

5
CodeRank
This code example shows how to use the following methods:invoke
 
    @Test
    public void should_get_feature_auth_roles() throws Exception {
        ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
        @SuppressWarnings("unchecked") 
        Set<String> featureAuthRoles = (Set<String>) mbServConn.invoke(objectName, "getPermissions",
                new Object[] {"jmxFeatureWithAuth"}, new String[] {"java.lang.String"});
 
        Assert.assertTrue(featureAuthRoles.contains("ROLE_USER"));
        Assert.assertTrue(featureAuthRoles.contains("ROLE_ADMIN"));
 
        should_add_auth_role_to_feature(); 
        should_remove_auth_role_from_feature(); 
    } 
 
    public void should_add_auth_role_to_feature() throws Exception {
        ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
        mbServConn.invoke(objectName, "grantRoleOnFeature", new Object[] {"NEW_ROLE","jmxEnabledFeature"},
                new String[] {"java.lang.String","java.lang.String"});
    } 

6
CodeRank
This code example shows how to use the following methods:getAttribute
        try { 
            connector = this.getJMXConnector();
            MBeanServerConnection connection = connector.getMBeanServerConnection();
            ObjectName name = new ObjectName("org.apache.karaf:type=obr,name=root");
            @SuppressWarnings("unchecked") 
            List<String> urls = (List<String>) connection.getAttribute(name, "Urls");
            assertEquals(0, urls.size());
            TabularData bundles = (TabularData) connection.getAttribute(name, "Bundles");
            assertEquals(0, bundles.size());
        } finally { 
        	close(connector);
        } 
    } 
 
} 
5
CodeRank
See Code Examples for Java 8 MBeanServerConnection Methods: