Java Code Examples for javax.management.MBeanServerConnection#getObjectInstance()

The following examples show how to use javax.management.MBeanServerConnection#getObjectInstance() . 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: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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 2
Source File: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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 3
Source File: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void verifyTableMBeanShouldNotPresentInGroup(
    MBeanServerConnection mbeanServer, String tableName, String memberId, String serverGroup) throws MalformedObjectNameException, IOException {
  ObjectName tableON = getTableMBean(tableName, memberId, serverGroup);
    try {
      mbeanServer.getObjectInstance(tableON);
      saveError("Table MBean should not come for this server group, Server Group : " + serverGroup + ", and Table :" + tableName);
    } catch (InstanceNotFoundException e) {
    }
}
 
Example 4
Source File: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void verifyTableMBeanShouldNotPresentInGroup(
    MBeanServerConnection mbeanServer, String tableName, String memberId, String serverGroup) throws MalformedObjectNameException, IOException {
  ObjectName tableON = getTableMBean(tableName, memberId, serverGroup);
    try {
      mbeanServer.getObjectInstance(tableON);
      saveError("Table MBean should not come for this server group, Server Group : " + serverGroup + ", and Table :" + tableName);
    } catch (InstanceNotFoundException e) {
    }
}
 
Example 5
Source File: Client.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void main(String[] args) throws Exception
{
   // The address of the connector server
   JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");

   // The credentials are passed via the environment Map
   Map environment = new HashMap();
   String[] credentials = new String[]{"guest", "guest"};
   environment.put(JMXConnector.CREDENTIALS, credentials);

   // Connect to the server
   JMXConnector cntor = JMXConnectorFactory.connect(url, environment);

   // Create a subject to delegate to
   JMXPrincipal principal = new JMXPrincipal("anotherGuest");
   Set principals = new HashSet();
   principals.add(principal);
   Subject delegate = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);

   // Get two MBeanServerConnection: one that uses the 'guest' principal directly,
   // the second that uses the 'guest' user but delegates to another principal.
   MBeanServerConnection connection = cntor.getMBeanServerConnection();
   MBeanServerConnection delegateConnection = cntor.getMBeanServerConnection(delegate);

   // The example policy file provided allows both MBeanServerConnections to call
   // MBeanServerConnection.queryNames
   Set mbeans = connection.queryNames(null, null);
   System.out.println("MBeans retrieved by a connection without delegate subject:");
   System.out.println(mbeans);
   System.out.println();

   mbeans = delegateConnection.queryNames(null, null);
   System.out.println("MBeans retrieved by a connection with a delegate subject:");
   System.out.println(mbeans);
   System.out.println();

   // The example policy file forbids to call MBeanServerConnection.getObjectInstance
   try
   {
      connection.getObjectInstance(ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"));
      throw new Error();
   }
   catch (SecurityException x)
   {
      System.out.println("No permission to call getObjectInstance for the MBeanServerDelegate");
   }
}