com.isti.openorbutil
Class EvtChManager

java.lang.Object
  extended by com.isti.openorbutil.EvtChManager

public class EvtChManager
extends java.lang.Object

Class EvtChManager contains methods for managing a CORBA event channel.


Field Summary
protected  int disChannelIdValue
           
protected  int disConsumerIdValue
           
protected  boolean disConsumerPendingFlag
           
protected  int disSupplierIdValue
           
protected  boolean disSupplierPendingFlag
           
protected  java.lang.Throwable errorExceptionObj
           
protected  java.lang.String errorMessage
           
protected  org.omg.CosNotifyChannelAdmin.EventChannel eventChannelObj
           
protected  EvtChConsumer evtChConsumerObj
           
protected  EvtChSupplier evtChSupplierObj
           
protected  EvtChEventType[] evtFilterTypeArr
           
protected  java.lang.String locatorString
           
protected  LogFile logObj
           
protected  OrbManager orbManagerObj
           
protected  boolean structuredEventsFlag
           
 
Constructor Summary
EvtChManager(OrbManager orbManagerObj, LogFile logObj)
          Constructs an event channel manager (using 'Any' events).
EvtChManager(OrbManager orbManagerObj, LogFile logObj, boolean structuredEventsFlag)
          Constructs an event channel manager.
 
Method Summary
static java.lang.String channelToString(org.omg.CORBA.ORB orbObj, org.omg.CosNotifyChannelAdmin.EventChannel evtChObj)
          Converts the given event channel object to an "IOR:" string.
 void clearErrorMessage()
          Clears the error message string.
 void closeChannel()
          Closes the event channel.
 boolean connectConsumer(EvtChConsumer consumerObj)
          Connects the given consumer object to the event channel.
 boolean connectConsumer(EvtChMsgProcIntrf msgProcessorObj)
          Creates a consumer object and connects it to the event channel such that incoming messages will be directed to the 'processMessage()' method of the given call-back class.
 boolean connectSupplier()
          Creates a supplier object and connects it to the event channel.
 boolean createChViaNotifService()
          Creates an event channel.
 boolean createChViaNotifService(java.lang.String hostNameStr, java.lang.String servicePortStr)
          Creates an event channel.
 void disconnectConsumer()
          Disconnects the consumer object from the event channel and discards the consumer object.
 void disconnectSupplier()
          Disconnects the supplier object from the event channel and discards the supplier object.
static java.lang.String fixIiopString(java.lang.String iiopStr)
          Modifies an ORBacus v3 ("iiop://") locator string into an ORBacus v4 ("corbaloc::") locator string.
 java.lang.Throwable getErrorExceptionObj()
          Returns the exception-object associated with the last error.
 boolean getErrorFlag()
          Returns true if an error was detected.
 java.lang.String getErrorMessage()
          Returns message string for last error (or 'No error' if none) and clears the error.
 org.omg.CosNotifyChannelAdmin.EventChannelFactory getEventChannelFactory(java.lang.String hostNameStr, java.lang.String servicePortStr)
          Returns the 'EventChannelFactory' object used for event channels.
 org.omg.CosNotifyChannelAdmin.EventChannel getEventChannelObj()
          Returns the event channel object.
 EvtChConsumer getEvtChConsumerObj()
          Returns the event channel consumer object.
 EvtChSupplier getEvtChSupplierObj()
          Returns the event channel supplier object.
 java.lang.String getIorString()
          Returns an "IOR:" string for the event channel.
 java.lang.String getLocatorString()
          Returns the locator string for the event channel created via the 'createChViaNotifService()' method or located using the 'openViaLocator...()' methods.
 boolean isConsumerConnected()
          Returns the status of the consumer connection.
 boolean isOpen()
          Returns the status of the event channel connection.
 boolean isSupplierConnected()
          Returns the status of the supplier connection.
 boolean openViaLocatorFile(java.lang.String evtChLocFileNameStr)
          Reads the locator string from the given file and then connects to the event channel, locating it via the loaded string.
 boolean openViaLocatorString(java.lang.String locStr)
          Finds the event channel specified by the given locator string.
 boolean openViaServiceName(java.lang.String serviceName)
          Finds the event channel using a given service name known to the ORB.
static org.omg.CosNotifyChannelAdmin.EventChannel resolveChannel(org.omg.CORBA.ORB orbObj, java.lang.String serviceName)
          Resolves an Notification Service event channel object.
 boolean sendMessage(java.lang.String msgStr)
          Sends a message via the event channel supplier.
 boolean sendMessage(java.lang.String eventNameStr, java.lang.String msgStr)
          Sends a structured-event message via the event channel supplier.
 boolean sendMessage(java.lang.String domainNameStr, java.lang.String typeNameStr, java.lang.String eventNameStr, java.lang.String msgStr)
          Sends a structured-event message via the event channel supplier.
protected  void setErrorMessage(java.lang.String str)
          Enters error message (if none previously entered).
protected  void setErrorMessage(java.lang.String str, java.lang.Throwable exObj)
          Enters error message (if none previously entered).
 boolean setupConsumerFilter(EvtChEventType[] evtTypeArr)
          Sets up the filter to be attached to the consumer created and connected to the event channel via the 'connectConsumer(EvtChMsgProcIntrf)' method.
static org.omg.CosNotifyChannelAdmin.EventChannel stringToChannel(org.omg.CORBA.ORB orbObj, java.lang.String evtChIORStr)
          Converts the given "IOR:" or "corbaloc::" string to an event channel object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

orbManagerObj

protected final OrbManager orbManagerObj

logObj

protected final LogFile logObj

structuredEventsFlag

protected final boolean structuredEventsFlag

eventChannelObj

protected org.omg.CosNotifyChannelAdmin.EventChannel eventChannelObj

evtChSupplierObj

protected EvtChSupplier evtChSupplierObj

evtChConsumerObj

protected EvtChConsumer evtChConsumerObj

evtFilterTypeArr

protected EvtChEventType[] evtFilterTypeArr

disChannelIdValue

protected int disChannelIdValue

disSupplierPendingFlag

protected boolean disSupplierPendingFlag

disSupplierIdValue

protected int disSupplierIdValue

disConsumerPendingFlag

protected boolean disConsumerPendingFlag

disConsumerIdValue

protected int disConsumerIdValue

locatorString

protected java.lang.String locatorString

errorMessage

protected java.lang.String errorMessage

errorExceptionObj

protected java.lang.Throwable errorExceptionObj
Constructor Detail

EvtChManager

public EvtChManager(OrbManager orbManagerObj,
                    LogFile logObj,
                    boolean structuredEventsFlag)
Constructs an event channel manager.

Parameters:
orbManagerObj - the ORB manager to use.
logObj - log file object to use, or null for none.
structuredEventsFlag - true to use structured events, false to use 'Any' events.

EvtChManager

public EvtChManager(OrbManager orbManagerObj,
                    LogFile logObj)
Constructs an event channel manager (using 'Any' events).

Parameters:
orbManagerObj - the ORB manager to use.
logObj - log file object to use, or null for none.
Method Detail

createChViaNotifService

public boolean createChViaNotifService(java.lang.String hostNameStr,
                                       java.lang.String servicePortStr)
Creates an event channel. The event channel's locator string may be fetched via the 'getLocatorString()' method.

Parameters:
hostNameStr - host name to use, or null to use the IP of the local host.
servicePortStr - port number for Notification Service on host, or null for 2005.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

createChViaNotifService

public boolean createChViaNotifService()
Creates an event channel. The event channel's locator string may be fetched via the 'getLocatorString()' method.

Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

getEventChannelFactory

public org.omg.CosNotifyChannelAdmin.EventChannelFactory getEventChannelFactory(java.lang.String hostNameStr,
                                                                                java.lang.String servicePortStr)
Returns the 'EventChannelFactory' object used for event channels.

Parameters:
hostNameStr - host name to use, or null to use the IP of the local host.
servicePortStr - port number for Notification Service on host, or null for 2005.
Returns:
The 'EventChannelFactory' object, or null if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

openViaServiceName

public boolean openViaServiceName(java.lang.String serviceName)
Finds the event channel using a given service name known to the ORB. The service name is usually defined in an ORB configuration file.

Parameters:
serviceName - the service name to use.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

openViaLocatorString

public boolean openViaLocatorString(java.lang.String locStr)
Finds the event channel specified by the given locator string.

Parameters:
locStr - the locator string to use.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

openViaLocatorFile

public boolean openViaLocatorFile(java.lang.String evtChLocFileNameStr)
Reads the locator string from the given file and then connects to the event channel, locating it via the loaded string.

Parameters:
evtChLocFileNameStr - the name of the locator file.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

closeChannel

public void closeChannel()
Closes the event channel. (The reference to the event channel is released.)


isOpen

public boolean isOpen()
Returns the status of the event channel connection.

Returns:
true if the event channel is open (or if a close is pending), false otherwise.

getLocatorString

public java.lang.String getLocatorString()
Returns the locator string for the event channel created via the 'createChViaNotifService()' method or located using the 'openViaLocator...()' methods.

Returns:
The locator string, or null if none is available.

getEventChannelObj

public org.omg.CosNotifyChannelAdmin.EventChannel getEventChannelObj()
Returns the event channel object.

Returns:
The event channel object, or null if the event channel is not open.

getEvtChSupplierObj

public EvtChSupplier getEvtChSupplierObj()
Returns the event channel supplier object.

Returns:
The event channel supplier object, or null if the supplier is not connected.

getEvtChConsumerObj

public EvtChConsumer getEvtChConsumerObj()
Returns the event channel consumer object.

Returns:
The event channel consumer object, or null if the consumer is not connected.

connectSupplier

public boolean connectSupplier()
Creates a supplier object and connects it to the event channel. The event channel needs to have been opened using one of the 'open...' methods.

Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

sendMessage

public boolean sendMessage(java.lang.String msgStr)
Sends a message via the event channel supplier. The supplier needs to have been connected using one of the 'connectSupplier()' methods.

Parameters:
msgStr - the message string to send.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

sendMessage

public boolean sendMessage(java.lang.String eventNameStr,
                           java.lang.String msgStr)
Sends a structured-event message via the event channel supplier. The supplier needs to have been connected using one of the 'connectSupplier()' methods.

Parameters:
eventNameStr - the event name to use, or null for none.
msgStr - the message string to send.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

sendMessage

public boolean sendMessage(java.lang.String domainNameStr,
                           java.lang.String typeNameStr,
                           java.lang.String eventNameStr,
                           java.lang.String msgStr)
Sends a structured-event message via the event channel supplier. The supplier needs to have been connected using one of the 'connectSupplier()' methods.

Parameters:
domainNameStr - the domain name to use, or null for none.
typeNameStr - the type name to use, or null for none.
eventNameStr - the event name to use, or null for none.
msgStr - the message string to send.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

disconnectSupplier

public void disconnectSupplier()
Disconnects the supplier object from the event channel and discards the supplier object.


isSupplierConnected

public boolean isSupplierConnected()
Returns the status of the supplier connection.

Returns:
true if connected (or if a disconnect is pending), false otherwise.

setupConsumerFilter

public boolean setupConsumerFilter(EvtChEventType[] evtTypeArr)
Sets up the filter to be attached to the consumer created and connected to the event channel via the 'connectConsumer(EvtChMsgProcIntrf)' method. Event filtering is implemented such that only events that match one or more of the 'EvtChEventType' objects will be received, and a match consists of both the "domain" and "type" strings being the same as those in the event. Event filtering is only used with structured events. If this method is used, it must be called before the 'connectConsumer(EvtChMsgProcIntrf)' method is called.

Parameters:
evtTypeArr - the array of 'EvtChEventType' objects to use to build the Notification Service filter object to use for the filtering of structured events to be received by the consumer, or null for none.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

connectConsumer

public boolean connectConsumer(EvtChConsumer consumerObj)
Connects the given consumer object to the event channel. The event channel needs to have been opened using one of the 'open...' methods.

Parameters:
consumerObj - the event-channel consumer object to use.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

connectConsumer

public boolean connectConsumer(EvtChMsgProcIntrf msgProcessorObj)
Creates a consumer object and connects it to the event channel such that incoming messages will be directed to the 'processMessage()' method of the given call-back class. The event channel needs to have been opened using one of the 'open...' methods.

Parameters:
msgProcessorObj - the 'MessageProcessor' call-back class to use.
Returns:
true if successful, false if error (in which case the 'getErrorMessage()' method may be used to fetch the error message).

disconnectConsumer

public void disconnectConsumer()
Disconnects the consumer object from the event channel and discards the consumer object.


isConsumerConnected

public boolean isConsumerConnected()
Returns the status of the consumer connection.

Returns:
true if connected (or if a disconnect is pending), false otherwise.

getIorString

public java.lang.String getIorString()
Returns an "IOR:" string for the event channel.

Returns:
An "IOR:" string for the event channel, or null if none could be generated.

setErrorMessage

protected void setErrorMessage(java.lang.String str,
                               java.lang.Throwable exObj)
Enters error message (if none previously entered).

Parameters:
str - the error message text.
exObj - exception object for error.

setErrorMessage

protected void setErrorMessage(java.lang.String str)
Enters error message (if none previously entered).

Parameters:
str - the error message text.

getErrorFlag

public boolean getErrorFlag()
Returns true if an error was detected. The error message may be fetched via the 'getErrorMessage()' method.

Returns:
true if error; false if not.

getErrorMessage

public java.lang.String getErrorMessage()
Returns message string for last error (or 'No error' if none) and clears the error.

Returns:
The error message text (or 'No error' if none).

clearErrorMessage

public void clearErrorMessage()
Clears the error message string.


getErrorExceptionObj

public java.lang.Throwable getErrorExceptionObj()
Returns the exception-object associated with the last error.

Returns:
The exception-object associated with the last error, or null if none is available.

resolveChannel

public static org.omg.CosNotifyChannelAdmin.EventChannel resolveChannel(org.omg.CORBA.ORB orbObj,
                                                                        java.lang.String serviceName)
                                                                 throws org.omg.CORBA.ORBPackage.InvalidName,
                                                                        EvtChSetupException
Resolves an Notification Service event channel object.

Parameters:
orbObj - the CORBA ORB object to be used.
serviceName - the name bound to the event channel.
Returns:
A handle to the resolved event channel.
Throws:
org.omg.CORBA.ORBPackage.InvalidName - if the event channel name could not resolved.
EvtChSetupException - if the event channel could not be setup.

channelToString

public static java.lang.String channelToString(org.omg.CORBA.ORB orbObj,
                                               org.omg.CosNotifyChannelAdmin.EventChannel evtChObj)
Converts the given event channel object to an "IOR:" string.

Parameters:
orbObj - the CORBA ORB object to be used.
evtChObj - the event channel object to be converted.
Returns:
An "IOR:" string, or null if an error occurred.

stringToChannel

public static org.omg.CosNotifyChannelAdmin.EventChannel stringToChannel(org.omg.CORBA.ORB orbObj,
                                                                         java.lang.String evtChIORStr)
                                                                  throws EvtChSetupException
Converts the given "IOR:" or "corbaloc::" string to an event channel object.

Parameters:
orbObj - the CORBA ORB object to be used.
evtChIORStr - an "IOR:" string version of the channel.
Returns:
A handle to the event channel.
Throws:
EvtChSetupException - if the event channel could not be setup.

fixIiopString

public static java.lang.String fixIiopString(java.lang.String iiopStr)
Modifies an ORBacus v3 ("iiop://") locator string into an ORBacus v4 ("corbaloc::") locator string. If the given string does not contain "iiop://" then it is returned unchanged.

Parameters:
iiopStr - a locator string containing "iiop://".
Returns:
a locator string.