|
From: Dave B. <bla...@us...> - 2012-08-17 01:45:18
|
Update of /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples
In directory vz-cvs-3.sog:/tmp/cvs-serv5357/smpl/org/sblim/cimclient/samples
Modified Files:
Tag: Experimental
Jsr48IndicationTester.java
Log Message:
3529066 - Add Jsr48IndicationTester (format)
Index: Jsr48IndicationTester.java
===================================================================
RCS file: /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples/Attic/Jsr48IndicationTester.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- Jsr48IndicationTester.java 7 Jul 2012 00:59:27 -0000 1.1.2.2
+++ Jsr48IndicationTester.java 17 Aug 2012 01:45:15 -0000 1.1.2.3
@@ -51,14 +51,14 @@
/**
* Class Jsr48IndicationTester is an interactive, command line program that
- * facilitates testing of end-to-end indication delivery between CIMOM and
- * the SBLIM Java CIM Client. The program starts an indication listener, sends
- * a subscription request to the CIMOM and reports any indications received by
- * the listener. The listener will continue to wait for new indications until
- * a keyboard interrupt is received or the timer expired. An indication can be
+ * facilitates testing of end-to-end indication delivery between CIMOM and the
+ * SBLIM Java CIM Client. The program starts an indication listener, sends a
+ * subscription request to the CIMOM and reports any indications received by the
+ * listener. The listener will continue to wait for new indications until a
+ * keyboard interrupt is received or the timer expired. An indication can be
* triggered via the program's trigger-mode, intended to be run from a separate
- * console. An indication may also triggered by some independent means.
- * The program is based on the Java CIM Client Jsr48IndicationSample programs.
+ * console. An indication may also triggered by some independent means. The
+ * program is based on the Java CIM Client Jsr48IndicationSample programs.
*/
public abstract class Jsr48IndicationTester {
@@ -142,9 +142,9 @@
public void indicationOccured(String pIndicationURL, CIMInstance pIndication,
InetAddress pSenderAddress) {
- System.out.println("Indication received on: " + pIndicationURL
- + ": from IP: " + pSenderAddress.getHostAddress()
- + ": classname: " + pIndication.getClassName());
+ System.out.println("Indication received on: " + pIndicationURL + ": from IP: "
+ + pSenderAddress.getHostAddress() + ": classname: "
+ + pIndication.getClassName());
}
};
IndicationListenerSBLIM ilsDetail = new IndicationListenerSBLIM() {
@@ -169,9 +169,9 @@
+ "support reliable indications.");
}
};
- System.out.printf("Added listener on port %d.\n\n", Integer.valueOf(
- sListener.addListener(pPrintInd ? ilsDetail : ilsBrief,
- pDestURL.getPort(), pDestURL.getProtocol(), null, props)));
+ System.out.printf("Added listener on port %d.\n\n", Integer.valueOf(sListener
+ .addListener(pPrintInd ? ilsDetail : ilsBrief, pDestURL.getPort(), pDestURL
+ .getProtocol(), null, props)));
return true;
@@ -234,8 +234,8 @@
* @throws UnknownHostException
* If "localhost" could not be resolved
*/
- private static CIMInstance makeFilter(String pInteropNS, String pIndicationNS, String pQuery, String pHost)
- throws UnknownHostException {
+ private static CIMInstance makeFilter(String pInteropNS, String pIndicationNS, String pQuery,
+ String pHost) throws UnknownHostException {
final CIMProperty<String> name = new CIMProperty<String>("Name", CIMDataType.STRING_T,
"JSR48SampleFilter" + getNextId(), true, false, null);
final CIMProperty<String> creationClassName = new CIMProperty<String>("CreationClassName",
@@ -244,8 +244,8 @@
CIMDataType.STRING_T, InetAddress.getByName(pHost).getHostName(), true, false, null);
final CIMProperty<String> systemCCN = new CIMProperty<String>("SystemCreationClassName",
CIMDataType.STRING_T, "CIM_ComputerSystem", true, false, null);
- final CIMProperty<String> query = new CIMProperty<String>("Query",
- CIMDataType.STRING_T, pQuery, false, false, null);
+ final CIMProperty<String> query = new CIMProperty<String>("Query", CIMDataType.STRING_T,
+ pQuery, false, false, null);
final CIMProperty<String> queryLanguage = new CIMProperty<String>("QueryLanguage",
CIMDataType.STRING_T, "WQL", false, false, null);
final CIMProperty<String> sourceNameSpace = new CIMProperty<String>("SourceNamespace",
@@ -314,14 +314,14 @@
* @return <code>true</code> if the subscription succeeds,
* <code>false</code> otherwise
*/
- public static boolean subscribe(WBEMClient pClient, String pInteropNS,
- String pIndicationNS, String pHost, URL pDestURL, String pQuery) {
+ public static boolean subscribe(WBEMClient pClient, String pInteropNS, String pIndicationNS,
+ String pHost, URL pDestURL, String pQuery) {
try {
- cDestinationPath = pClient.createInstance(makeListenerDestination(pInteropNS, pDestURL.getProtocol()
- + "://" + pDestURL.getHost() + ":" + pDestURL.getPort()
- + "/create", pHost));
- cFilterPath = pClient.createInstance(makeFilter(pInteropNS,
- pIndicationNS, pQuery, pHost));
+ cDestinationPath = pClient.createInstance(makeListenerDestination(pInteropNS, pDestURL
+ .getProtocol()
+ + "://" + pDestURL.getHost() + ":" + pDestURL.getPort() + "/create", pHost));
+ cFilterPath = pClient.createInstance(makeFilter(pInteropNS, pIndicationNS, pQuery,
+ pHost));
cSubscriptionPath = pClient.createInstance(makeSubscription(pInteropNS,
cDestinationPath, cFilterPath));
@@ -389,9 +389,12 @@
System.out.println(" (default: http://localhost:5988)");
System.out.println(" --destUrl DESTURL URL of destination handler");
System.out.println(" (default: http://localhost:7000)");
- System.out.println(" --intNS INTEROPNS Interop namespace name (default: root/interop)");
- System.out.println(" --indNS INDICATIONNS Namespace in which the register the indication");
- System.out.println(" (default is the same value as the interop namespace)");
+ System.out
+ .println(" --intNS INTEROPNS Interop namespace name (default: root/interop)");
+ System.out
+ .println(" --indNS INDICATIONNS Namespace in which the register the indication");
+ System.out
+ .println(" (default is the same value as the interop namespace)");
}
/**
@@ -407,32 +410,29 @@
if (url.getUserInfo() != null) {
String[] userInfo = url.getUserInfo().split(":");
System.out.printf("-username : %s\n", userInfo[0]);
- if (userInfo.length > 1)
- System.out.printf("-password : %s\n", userInfo[1]);
+ if (userInfo.length > 1) System.out.printf("-password : %s\n", userInfo[1]);
}
System.out.printf("File : %s\n", url.getFile());
System.out.printf("Path : %s\n", url.getPath());
System.out.printf("Query : %s\n", url.getQuery());
System.out.printf("Ref : %s\n", url.getRef());
try {
- System.out.printf("InetAddress.getHostAddress(): %s\n",
- InetAddress.getByName(url.getHost()).getHostAddress());
- System.out.printf("InetAddress.getHostName() : %s\n",
- InetAddress.getByName(url.getHost()).getHostName());
+ System.out.printf("InetAddress.getHostAddress(): %s\n", InetAddress.getByName(
+ url.getHost()).getHostAddress());
+ System.out.printf("InetAddress.getHostName() : %s\n", InetAddress.getByName(
+ url.getHost()).getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
-
+
/**
* Check that namespace is valid, apply default prefix if necessary
*/
private static String chkNamespace(String pNamespace) {
int fields = pNamespace.split("/").length;
- if (fields == 1)
- return "root/" + pNamespace;
- else if (fields == 2)
- return pNamespace;
+ if (fields == 1) return "root/" + pNamespace;
+ else if (fields == 2) return pNamespace;
else {
throw new IllegalArgumentException("Invalid namespace: " + pNamespace);
}
@@ -459,27 +459,27 @@
* "user", "pw", "root/interop" }
*/
static public void main(String[] args) {
-
+
try {
// Parse command line arguments
List<String> orphanArgs = new ArrayList<String>();
List<String> singleDashOpts = new ArrayList<String>();
- Map<String,String> doubleDashOpts = new HashMap<String,String>();
-
- for (int i=0; i < args.length; i++) {
+ Map<String, String> doubleDashOpts = new HashMap<String, String>();
+
+ for (int i = 0; i < args.length; i++) {
if (args[i].charAt(0) == '-') {
- if (args[i].length() < 2)
- throw new IllegalArgumentException("Invalid argument: " + args[i]);
+ if (args[i].length() < 2) throw new IllegalArgumentException(
+ "Invalid argument: " + args[i]);
if (args[i].charAt(1) == '-') {
- if (i >= args.length-1)
- throw new IllegalArgumentException("Expected arg after: " + args[i]);
- if (args[i].length() < 3)
- throw new IllegalArgumentException("Invalid argument: " + args[i]);
- doubleDashOpts.put(args[i].toLowerCase(), args[i+1]);
+ if (i >= args.length - 1) throw new IllegalArgumentException(
+ "Expected arg after: " + args[i]);
+ if (args[i].length() < 3) throw new IllegalArgumentException(
+ "Invalid argument: " + args[i]);
+ doubleDashOpts.put(args[i].toLowerCase(), args[i + 1]);
i++;
} else {
- if (args[i].length() > 2)
- throw new IllegalArgumentException("Invalid argument: " + args[i]);
+ if (args[i].length() > 2) throw new IllegalArgumentException(
+ "Invalid argument: " + args[i]);
singleDashOpts.add(args[i]);
}
} else {
@@ -491,32 +491,34 @@
boolean printInd = singleDashOpts.contains("-p") ? true : false;
boolean trigger = singleDashOpts.contains("-t") ? true : false;
boolean verbose = singleDashOpts.contains("-v") ? true : false;
-
- if (help) { printUsage(); printHelp(); System.exit(0); }
-
+
+ if (help) {
+ printUsage();
+ printHelp();
+ System.exit(0);
+ }
+
// If indication namespace not specified, use interop namespace
- final String interopNS = doubleDashOpts.containsKey("--intns") ?
- chkNamespace(doubleDashOpts.get("--intns")) : "root/interop";
- final String indicationNS = doubleDashOpts.containsKey("--indns") ?
- chkNamespace(doubleDashOpts.get("--indns")) : interopNS;
+ final String interopNS = doubleDashOpts.containsKey("--intns") ? chkNamespace(doubleDashOpts
+ .get("--intns"))
+ : "root/interop";
+ final String indicationNS = doubleDashOpts.containsKey("--indns") ? chkNamespace(doubleDashOpts
+ .get("--indns"))
+ : interopNS;
- final URL cimomURL = doubleDashOpts.containsKey("--cimomurl") ?
- new URL(doubleDashOpts.get("--cimomurl")) :
- new URL("http://localhost:5988");
- final URL destURL = doubleDashOpts.containsKey("--desturl") ?
- new URL(doubleDashOpts.get("--desturl")) :
- new URL("http://localhost:7000");
+ final URL cimomURL = doubleDashOpts.containsKey("--cimomurl") ? new URL(doubleDashOpts
+ .get("--cimomurl")) : new URL("http://localhost:5988");
+ final URL destURL = doubleDashOpts.containsKey("--desturl") ? new URL(doubleDashOpts
+ .get("--desturl")) : new URL("http://localhost:7000");
String userInfo = cimomURL.getUserInfo();
- final String cimomUser = (userInfo != null) ?
- userInfo.split(":")[0] : null;
- final String cimomPasswd = (userInfo != null) ?
- userInfo.split(":")[1] : null;
+ final String cimomUser = (userInfo != null) ? userInfo.split(":")[0] : null;
+ final String cimomPasswd = (userInfo != null) ? userInfo.split(":")[1] : null;
- if (orphanArgs.isEmpty())
- throw new IllegalArgumentException("No indication classname provided");
- else if (orphanArgs.size() > 1)
- throw new IllegalArgumentException("Garbled command: too many arguments");
+ if (orphanArgs.isEmpty()) throw new IllegalArgumentException(
+ "No indication classname provided");
+ else if (orphanArgs.size() > 1) throw new IllegalArgumentException(
+ "Garbled command: too many arguments");
final String indClassName = orphanArgs.get(0);
if (verbose) {
@@ -534,8 +536,8 @@
// Initialize client. This will not trigger any communication with
// the CIMOM.
- final WBEMClientSBLIM client =
- (WBEMClientSBLIM) connect(cimomURL, cimomUser, cimomPasswd);
+ final WBEMClientSBLIM client = (WBEMClientSBLIM) connect(cimomURL, cimomUser,
+ cimomPasswd);
if (client == null) {
System.err.println("Client init failed. Probably due to invalid cl parameters.");
@@ -550,23 +552,22 @@
// This will trigger a TestIndication that is caught by the
// remote listener
- Object obj = client.invokeMethod(new CIMObjectPath(null,
- null, null, indicationNS, indClassName, null),
- "SendTestIndication", input, output);
- if (obj.toString().equals("0"))
- System.out.println("Indication generated successfully.");
- else
- System.out.println("Indication not generated successfully!");
+ Object obj = client.invokeMethod(new CIMObjectPath(null, null, null, indicationNS,
+ indClassName, null), "SendTestIndication", input, output);
+ if (obj.toString().equals("0")) System.out
+ .println("Indication generated successfully.");
+ else System.out.println("Indication not generated successfully!");
System.exit(0);
}
// cleanup at shutdown or keyboard interrupt (ctrl-C)
Runtime.getRuntime().addShutdownHook(new Thread() {
+
@Override
public void run() {
cleanup(client, interopNS, destURL);
}
- });
+ });
// start the listener so that we are "on air" when the indications
// come in
@@ -585,15 +586,14 @@
// any connectivity or authentication problems the WBEMException
// will be thrown right in the subscribe method.
String query = "SELECT * FROM " + indClassName;
- if (subscribe(client, interopNS, indicationNS,
- cimomURL.getHost(), destURL, query)) {
+ if (subscribe(client, interopNS, indicationNS, cimomURL.getHost(), destURL, query)) {
System.out.println("Successfully subscribed.");
} else {
System.err.println("Subscription failed.");
return;
}
- Thread.sleep(300*1000);
-
+ Thread.sleep(300 * 1000);
+
} finally {
// should never get here as we have ShutdownHook to catch exit
}
|