Java Clients
Events and Connection PointsSome IOM objects support one or more event interfaces, which are interfaces that contain operations that are to be implemented by the client (in Java). The operations are called by the IOM object whenever some particular event occurs. For example, the SAS Language Component supports an event interface and calls operations on it whenever a SAS procedure or DATA step finishes execution, which allows you to check the progress of a submitted SAS program. To listen for events from an IOM object, you need to know how to use skeletons and connection points. Extending SkeletonsA skeleton is the complement of a stub. While a stub is a Java class that repackages method calls into requests and forwards them to the IOM server, a skeleton is a Java class that accepts requests from the IOM server and repackages them into Java method calls. You provide the implementation of the method calls by extending the skeleton with implementations of all the methods in the event interface. When an event arrives, the IOM Bridge for Java provides a temporary thread of execution and calls the appropriate method through the skeleton. The following example demonstrates how to extend the skeleton for the event interface supported by the SAS Language Component: public class LanguageEventsListener extends com.sas.iom.SASEvents._ILanguageEventsImplBase { // implement declared methods in com.sas.iom.SASEvents.ILanguageEvents public void ProcStart(java.lang.String procname) { /* your implementation */ } public void SubmitComplete(int sasrc) { /* your implementation */ } public void ProcComplete(java.lang.String procname) { /* your implementation */ } public void DatastepStart() { /* your implementation */ } public void DatastepComplete() { /* your implementation */ } public void StepError() { /* your implementation */ } }
Note that all the methods return Finding a Connection Point
After you have written an event listener using the preceding example as a guide, you
then make the listener known to the IOM object using a connection point. A
connection point is, in effect, a child component of an IOM object that
serves as a conduit for passing events from the IOM object to its listeners.
IOM objects that support event interfaces implement an interface called
The
The following example shows you how to get a unique interface identifier and
use it to initialize the String cpidString = com.sas.iom.SASEvents.ILanguageEventsHelper.id(); int d1 = (int)java.lang.Long.parseLong(cpidString.substring(4,12),16); short d2 = (short)java.lang.Integer.parseInt(cpidString.substring(13,17),16); short d3 = (short)java.lang.Integer.parseInt(cpidString.substring(18,22),16); byte[] d4 = new byte[8]; for (int i=0;i<2;i++) { d4[i] = (byte)java.lang.Short.parseShort( cpidString.substring(23+(i*2),25+(i*2)),16); } for (int i=0;i<6;i++) { d4[i+2] = (byte)java.lang.Short.parseShort( cpidString.substring(28+(i*2),30+(i*2)),16); } com.sas.iom.SASIOMDefs.CP_ID cpid=new com.sas.iom.SASIOMDefs.CP_ID( d1,d2,d3,d4);
After you have constructed the
The following example shows you how to find the connection point for the
com.sas.iom.SASIOMDefs.ConnectionPointContainer cpContainer = com.sas.iom.SASIOMDefs.ConnectionPointContainerHelper.narrow(sasLanguage); com.sas.iom.SASIOMDefs.ConnectionPointHolder cpHolder = new com.sas.iom.SASIOMDefs.ConnectionPointHolder(); cpContainer.FindConnectionPoint(cpid,cpHolder); com.sas.iom.SASIOMDefs.ConnectionPoint cp = cpHolder.value; Using a Connection Point
After you have obtained a reference to a connection point, the final step is to
make the connection point aware of your event listener. This step is done using
the The following example illustrates the use of a connection point: org.omg.CORBA.IntHolder handleHolder = new org.omg.CORBA.IntHolder(); cp.Advise(sasLanguageEventsListener,handleHolder); int handle = handleHolder.value; /* event listener can now receive events */ cp.Unadvise(handle); |