HP Integrity NonStop H-Series User Manual
Page 88

/*Copyright 2013 Hewlett-Packard Development Company, L.P. */
/**
* WhoAmIClient is a sample nsasj client program that demonstrates the usage
* of com.hp.nsk.nsasj.client.NSASJClient to get information about the user connected
* to the host controlller.
*
*/
package com.hp.nsk.nsasj.client.demo;
import org.jboss.dmr.ModelNode
import com.hp.nsk.nsasj.client.NSASJClient;
public class WhoAmIClient extends NSASJClient {
/**
* method - main(). The main method takes the arguments and (1) connects to
* HostController (2) executes the command (3) disconnects from Host
* Controller
*
* @param args
* arg[0] path to the nsasj.client.properties file
*/
public static void main(String[] args) {
WhoAmIClient obj = null;
/**
* Get the args nsasj.client.properties file
*/
if (args.length > 1) {
System.out
println("Usage : java com.hp.nonstop.nsasj.client.demo.WhoAmIClient
System.exit(0);
} else if (args.length == 1)
obj = new WhoAmIClient(args[0]);
else {
/**
* assumes the property file is nsasj.client.properties present in
* the current folder.
*/
obj = new WhoAmIClient(null);
}
/**
* Connect to Host Controller
*/
obj.connectToHC();
/**
* Create and execute the command
*/obj.executeCommand();
/**
* Disconnect and exit
*/
obj.disconnectFromHC();
}
/**
* Constructor - Calls the NSASJClient constructor that creates an
* org.jboss.as.controller.client.ModelControllerClient
*
* @param propFile
* - The file that contains the default authentication
* information.
*/
public WhoAmIClient(String propFile) {
super(propFile);
}
/**
* executeCommand() - the abstract method of NSASJClient is overridden here.
* The method whoAmI() is called which constructs and executes a custom
* whoAmI command on the node /host=master
*/
@Override
public void executeCommand() {
whoAmI();
}
/**
* method - whoAmI(). A method to query and display who is connected to
* NSASJ HC at the moment.
*
*/
private void whoAmI() {
/**
* Create the org.jboss.dmr.ModelNode. Update the operation and the node
* address to create the command.
*/
ModelNode op = new ModelNode();
op.get("operation").set("whoami");
ModelNode address = op.get("address");
address.add("host", hostControllerName);
88
Managing NSASJ