|
From: Dave B. <bla...@us...> - 2012-01-17 14:11:14
|
Update of /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples
In directory vz-cvs-3.sog:/tmp/cvs-serv17572/smpl/org/sblim/cimclient/samples
Modified Files:
Jsr48PegasusIndicationSample.java
Log Message:
3469018 - Properties not passed to CIMIndicationHandler
Index: Jsr48PegasusIndicationSample.java
===================================================================
RCS file: /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples/Jsr48PegasusIndicationSample.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Jsr48PegasusIndicationSample.java 10 Aug 2011 11:52:14 -0000 1.5
+++ Jsr48PegasusIndicationSample.java 17 Jan 2012 14:11:11 -0000 1.6
@@ -1,5 +1,5 @@
/**
- * (C) Copyright IBM Corp. 2011
+ * (C) Copyright IBM Corp. 2011, 2012
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
@@ -16,6 +16,7 @@
* 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect
* 3267429 2011-04-01 blaschke-oss Samples should close client
* 3374206 2011-07-22 blaschke-oss NullPointerException caused by Indication
+ * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler
*/
package org.sblim.cimclient.samples;
@@ -24,6 +25,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.Properties;
import javax.cim.CIMArgument;
import javax.cim.CIMDataType;
@@ -37,6 +39,8 @@
import javax.wbem.listener.WBEMListener;
import javax.wbem.listener.WBEMListenerFactory;
+import org.sblim.cimclient.WBEMListenerSBLIM;
+
/**
* Class Jsr48PegasusIndicationSample is an example for setting up an indication
* listener with the JSR48 API and receiving a test indication from an
@@ -160,6 +164,62 @@
}
/**
+ * Starts a reliable listener. The JSR48 library will open a HTTP(S) server
+ * socket and listen for incoming indications on that socket. Any
+ * indications received will be forwarded to the registered
+ * IndicationListener implementation. The sample one here just prints the
+ * indication to stdout along with a message indicating whether the CIMOM
+ * supports reliable indications.
+ *
+ * @return <code>true</code> if the listener could be started,
+ * <code>false</code> otherwise.
+ */
+ public static boolean startReliableListener() {
+ try {
+ cListener = WBEMListenerFactory.getListener(WBEMClientConstants.PROTOCOL_CIMXML);
+
+ // Cast WBEMListener to WBEMListenerSBLIM to get access to the
+ // addListener() method that accepts properties - this method is not
+ // part of the JSR48 standard, but is a SBLIM addition
+ WBEMListenerSBLIM sListener = (WBEMListenerSBLIM) cListener;
+
+ // Enable reliable indications using 2 retries at intervals of 30
+ // seconds
+ Properties props = new Properties();
+ props.setProperty("sblim.wbem.listenerEnableReliableIndications", "true");
+ props.setProperty("sblim.wbem.listenerDeliveryRetryAttempts", "2");
+ props.setProperty("sblim.wbem.listenerDeliveryRetryInterval", "30");
+
+ sListener.addListener(new IndicationListener() {
+
+ public void indicationOccured(String pIndicationURL, CIMInstance pIndication) {
+ System.out.println("Indication received on: " + pIndicationURL + ":");
+ try {
+ URL parsedURL = new URL(pIndicationURL);
+ System.out.println("The URL could be parsed, path is: "
+ + parsedURL.getPath());
+ } catch (MalformedURLException e) {
+ System.out.println("The URL could NOT be parsed: " + e);
+ }
+ System.out.println(Jsr48CimSample.toMof(pIndication));
+ CIMProperty<?> context = pIndication.getProperty("SequenceContext");
+ CIMProperty<?> number = pIndication.getProperty("SequenceNumber");
+ System.out.println("Based on content of indication, CIMOM DOES"
+ + (context == null || number == null || context.getValue() == null
+ || number.getValue() == null ? " NOT " : " ")
+ + "support reliable indications.");
+ }
+ }, Integer.parseInt(LISTENER_PORT), PROTOCOL, null, props);
+
+ return true;
+
+ } catch (IOException e) {
+ // nothing to do here
+ }
+ return false;
+ }
+
+ /**
* Constructs a CIM_ListenerDestinationCIMXML instance
*
* @param pNamespace
|