Steps for this task
Properties connectProps = new Properties(); connectProps.setProperty( AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP); connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost"); connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8879"); AdminClient adminClient = null; try { adminClient = AdminClientFactory.createAdminClient(connectProps); } catch (ConnectorException e) { System.out.println("Exception creating admin client: " + e); }
type | The type of MBean. For example: Server, TraceService, Java Virtual Machine (JVM). |
name | The name identifier for the individual instance of the MBean. |
cell | The name of the cell that the MBean is executing. |
node | The name of the node that the MBean is executing. |
process | The name of the process that the MBean is executing. |
String nodeName = "MyNode"; String query = "WebSphere:type=NodeAgent,node=" + nodeName + ",*"; ObjectName queryName = new ObjectName(query); ObjectName nodeAgent = null; Set s = adminClient.queryNames(queryName, null); if (!s.isEmpty()) nodeAgent = (ObjectName)s.iterator().next(); else System.out.println("Node agent MBean was not found");
String opName = "launchProcess"; String signature[] = { "java.lang.String" }; String params[] = { "MyServer" }; try { adminClient.invoke(nodeAgent, opName, params, signature); } catch (Exception e) { System.out.println("Exception invoking launchProcess: " + e); }
adminClient.addNotificationListener(nodeAgent, this, null, null);In this example, the null value will result in receiving all of the node agent MBean event notifications. You can also use the null value with the handback object.
public void handleNotification(Notification n, Object handback) { System.out.println("***************************************************"); System.out.println("* Notification received at " + new Date().toString()); System.out.println("* type = " + ntfyObj.getType()); System.out.println("* message = " + ntfyObj.getMessage()); System.out.println("* source = " + ntfyObj.getSource()); System.out.println( "* seqNum = " + Long.toString(ntfyObj.getSequenceNumber())); System.out.println("* timeStamp = " + new Date(ntfyObj.getTimeStamp())); System.out.println("* userData = " + ntfyObj.getUserData()); System.out.println("***************************************************"); }