com.ibm.pvc.we.ins
Class TriggerHandlerV2

java.lang.Object
  |
  +--com.ibm.pvc.we.ins.TriggerHandlerV2
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
TriggerHandlerWrapper

public abstract class TriggerHandlerV2
extends java.lang.Object
implements java.io.Serializable

Since:
March 2002
See Also:
Serialized Form

Field Summary
protected  boolean pinned
          Pin this trigger in memory and do not cache out
 
Constructor Summary
TriggerHandlerV2()
           
 
Method Summary
 void activate()
          Calling this method tells the trigger handler controller to start initiate the pending subscriptions and begin to accept subscription events.
protected  void deleteContent(java.lang.String contentID)
          Delete the content stored under the contentID.
 void doDelete(TriggerRequest treq)
          Delete this trigger and return all resources that are currently held by this trigger.
 void doGet(TriggerRequest req, TriggerResponse resp)
          Query the current state of the trigger.
 void doPost(TriggerRequest req, TriggerResponse resp)
          Update the state of a trigger.
 void doPut(TriggerRequest treq)
          Create a new trigger instance.
 void drop()
          Drop all incoming and queued up subscription events.
protected  com.ibm.pvc.we.ins.iqueue.CContent fetchContent(java.lang.String contentID)
          Fetch the content wrapper object CContent stored under the contentID.
 int getLastErrorCode()
          Get the last error, for example, if pause() too long, the input queue may overflow.
protected  ANotificationService getNotificationService()
          Get the NotificationService object for this trigger mananger.
protected  java.lang.String getOwnerName()
          Get the user name that created this trigger
protected  java.lang.String getOwnerRealm()
          Get the owner's realm name.
 java.util.Timer getTimer()
          Get a Timer object to schedule TimerTask events
 java.lang.String[] getTopicAndSelector(int n)
           
 long getTriggerExpirationTimeMillis()
          Get the current expiration time in milliseconds for this trigger
protected  TriggerID getTriggerID()
          Get the TriggerID for this trigger
 void handleMatch(com.ibm.pvc.we.ins.iqueue.ContentMessage msg)
          Trigger manager calls this method when a subscribed event occurred.
 void init(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c, long ttl, int size)
          Called by the TriggerHandlerController to set up this trigger.
 boolean isPinned()
          Return the pin state of this trigger
 void pause(int dropPolicy)
          Queue up subscription events and do not call the handleMatch() method.
protected  void publish(com.ibm.pvc.we.ins.iqueue.ContentMessage msg)
          Publish a ContentMessage object.
 void remove()
          Trigger initiated delete action.
 void restore(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c)
          Called by the TriggerHandlerController when the TriggerManager server startup and the triggers are retrieved from the trigger store.
 void resume()
          Resume accepting subscription events.
 void save()
          Save this the serialize form of this trigger to the trigger store.
protected  java.lang.String saveContent(com.ibm.pvc.we.ins.iqueue.CContent ccontent)
          Save the content into the content store.
 void setController(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c)
          Restore the trigger handler controller setting in case this trigger was cast out to trigger store by the trigger manager cache.
 long setTriggerExpirationTimeMillis(long expirationTimeMillis)
          Set the expiration time in milliseconds for this trigger The expiration time cannot exceed a maximum allowed expiration time for this trigger.
 int size()
          Returns the maximum number of subscriptions that this trigger is allow to have.
protected  int subscribe(java.lang.String cs, java.lang.String selector)
          Create a subscription base on the content source name and the selector string.
 void unsubscribe()
          Unsubscribe all subscriptions.
 void unsubscribe(int id)
          Unsubsribe a subscription base on the subscription index.
 void unsubscribe(java.lang.String cs, java.lang.String selector)
          Unsubscribe a subscription base on the content source name and selector string.
 void update(int id, java.lang.String cs, java.lang.String selector)
          Update a previous subscription with a new content source name and/or a new selector string.
protected  boolean updateContent(java.lang.String contentID, com.ibm.pvc.we.ins.iqueue.CContent ccontent)
          Update the content that was stored at this contentID location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pinned

protected boolean pinned
Pin this trigger in memory and do not cache out
Constructor Detail

TriggerHandlerV2

public TriggerHandlerV2()
Method Detail

doPut

public void doPut(TriggerRequest treq)
           throws TriggerException
Create a new trigger instance. This method is invoked by the trigger manager during an addTrigger() call, so it is called only once for every trigger instance. The trigger should set up the subsription event that it wants to know about, and then call the activate() to activate the event listening. It is recommended that the activate() method be called prior to the exiting of this method. Otherwise, an event match could occurred and the handleMatch is called while the trigger has not completed this doPut() method.

It is not required that the activate() method be called during this method.

Parameters:
treq - TriggerRequest contains application data that is passed to this trigger.
Throws:
IQueueException -  
TriggerException -  

doGet

public void doGet(TriggerRequest req,
                  TriggerResponse resp)
           throws TriggerException
Query the current state of the trigger. TriggerManager calls this method when it receives a queryTrigger() method call.
Parameters:
req - Trigger request object contain information for the trigger.
resp - Trigger response that goes back to the application. Any information that the trigger wants to send back to the application should be
Throws:
IQueueException -  

doPost

public void doPost(TriggerRequest req,
                   TriggerResponse resp)
            throws TriggerException
Update the state of a trigger. The trigger mananager calls the method when the TriggerManager.updateTrigger(java.lang.String, com.ibm.pvc.we.ins.TriggerID, com.ibm.pvc.we.ins.TriggerRequest) method call by the application.
Parameters:
req - Trigger request object from the application
resp - Trigger response object to be pass back to the application
Throws:
TriggerException -  

doDelete

public void doDelete(TriggerRequest treq)
              throws TriggerException
Delete this trigger and return all resources that are currently held by this trigger.
Parameters:
treq - Trigger request object from the application
Throws:
TriggerException -  

handleMatch

public void handleMatch(com.ibm.pvc.we.ins.iqueue.ContentMessage msg)
Trigger manager calls this method when a subscribed event occurred.
Parameters:
msg - Content message that represent the occurance of a subscription event
Throws:
IQueueException -  

init

public void init(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c,
                 long ttl,
                 int size)
Called by the TriggerHandlerController to set up this trigger. The method is called when this trigger is instantiatioin of this trigger, as part of the addTrigger() method call.

<TO DO> Move to a super class and hide it from the trigger programmer

Parameters:
c - Context
ttl - Time to live in seconds - set by the init parameter of this trigger class
size - max number of subscriptions

restore

public void restore(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c)
             throws IQueueException
Called by the TriggerHandlerController when the TriggerManager server startup and the triggers are retrieved from the trigger store. What needs to be done the re-establishment of the subscriptions to the pub/sub manager.

<TO DO> Move to a super class and hide it from the trigger programmer

Parameters:
c - The controller object for this trigger handler
Throws:
IQueueException -  

activate

public void activate()
              throws IQueueException
Calling this method tells the trigger handler controller to start initiate the pending subscriptions and begin to accept subscription events.
Throws:
IQueueException -  

setController

public void setController(com.ibm.pvc.we.ins.iqueue.TriggerHandlerController c)
Restore the trigger handler controller setting in case this trigger was cast out to trigger store by the trigger manager cache. Since the trigger manager server did not stop, this mean the values in the subscriptionList[] is still valid, so subscription does not need to be re-establish.

<TO DO> Move to a super class and hide it from the trigger programmer

Parameters:
c - Trigger handler controller object

subscribe

protected int subscribe(java.lang.String cs,
                        java.lang.String selector)
                 throws IQueueException
Create a subscription base on the content source name and the selector string. If the trigger is activated, create the subscription and the trigger has to be ready to accept the handling of the subscription events. If the trigger is not activated yet, this call queues up the subscription until the activate() method is called.

No checking of duplicate subscription is performed. When duplicate subscription happens, then the handleMatch() method is call the same number of times as the number of duplicates with same content message.

Parameters:
cs - Content source name, for example, "stocks", "news", or "weather"
selector - SQL92 filter string, for example, (symbol = 'IBM') AND (last > 100)
Returns:
subscription index
Throws:
-  
IQueueException -  

update

public void update(int id,
                   java.lang.String cs,
                   java.lang.String selector)
            throws IQueueException
Update a previous subscription with a new content source name and/or a new selector string.
Parameters:
id - Subscription id that was returned during the subscribe() method call
cs - Content source name
selector - SQL92 selector string
Throws:
-  
IQueueException -  

unsubscribe

public void unsubscribe(java.lang.String cs,
                        java.lang.String selector)
                 throws IQueueException
Unsubscribe a subscription base on the content source name and selector string. These strings must be equal to the parameters that were used to make the original subscription using the subscribe() method call.
Parameters:
cs - Content source name
selector - SQL92 selector string
Throws:
-  
IQueueException -  

unsubscribe

public void unsubscribe(int id)
                 throws IQueueException
Unsubsribe a subscription base on the subscription index.
Parameters:
id - Subscription id returned from a subscribe() call
Throws:
-  
IQueueException -  

unsubscribe

public void unsubscribe()
Unsubscribe all subscriptions.
Throws:
-  

publish

protected void publish(com.ibm.pvc.we.ins.iqueue.ContentMessage msg)
                throws IQueueException
Publish a ContentMessage object. This message is published under the content source name defined by the topicName of the content message.
Parameters:
msg - ContentMessage to be publish
Throws:
-  
IQueueException -  

save

public void save()
          throws IQueueException
Save this the serialize form of this trigger to the trigger store.
Throws:
-  
IQueueException -  

pause

public void pause(int dropPolicy)
Queue up subscription events and do not call the handleMatch() method. This call has no effect on any currently executing handleMatch(). The parameter dropPolicy tells the trigger handler controller what to do with the incoming subscription events when the input queue fills up during the pause period.
Parameters:
dropPolicy - Set to TriggerHandlerController.DROP_FIRST_MSG to drop the ealiest message in the queue and queue the latest incoming message. Set to TriggerHandlerController.DROP_LAST_MSG to drop the incoming message.

drop

public void drop()
Drop all incoming and queued up subscription events. Do not call the handleMatch() when a subscription event occurs. Any queued up subscription events in the input queue are removed.

resume

public void resume()
Resume accepting subscription events.
Throws:
-  

getLastErrorCode

public int getLastErrorCode()
Get the last error, for example, if pause() too long, the input queue may overflow. The error is cleared after this call.
Returns:
errorcode See TriggerHandlerV2 ERR_CODE definitions

saveContent

protected java.lang.String saveContent(com.ibm.pvc.we.ins.iqueue.CContent ccontent)
                                throws IQueueException
Save the content into the content store.
Parameters:
ccontent - Content wrapper object that holds the {@linl UserIDList}, expiration time in milliseconds, and the Serializable content.
Returns:
content id
Throws:
-  
IQueueException -  

updateContent

protected boolean updateContent(java.lang.String contentID,
                                com.ibm.pvc.we.ins.iqueue.CContent ccontent)
                         throws IQueueException
Update the content that was stored at this contentID location. Update could be apply to either the UserIDList or the expiration time or the content or all of above.
Parameters:
contentID - content id returned by the saveContent()
ccontent - Content wrapper that contains UserIDList, expiration time in milliseconds and the Serializable content
Returns:
true if the update was successful, false otherwise. Update would fail if the old content is no longer in the content store.
Throws:
-  
IQueueException -  

fetchContent

protected com.ibm.pvc.we.ins.iqueue.CContent fetchContent(java.lang.String contentID)
                                                   throws IQueueException
Fetch the content wrapper object CContent stored under the contentID.
Parameters:
contentID -  
Returns:
stored content in String or byte[], the caller should know the type
Throws:
-  
IQueueException -  

deleteContent

protected void deleteContent(java.lang.String contentID)
Delete the content stored under the contentID.
Parameters:
contentID -  
Throws:
-  

getNotificationService

protected ANotificationService getNotificationService()
Get the NotificationService object for this trigger mananger.
Returns:
 

getTopicAndSelector

public java.lang.String[] getTopicAndSelector(int n)
Returns:
Return the nth topic

size

public int size()
Returns the maximum number of subscriptions that this trigger is allow to have.
Returns:
Maximum number of subscription permissible

remove

public void remove()
Trigger initiated delete action. Delete this trigger and unsubscribe all outstanding subscriptions

getTriggerExpirationTimeMillis

public long getTriggerExpirationTimeMillis()
Get the current expiration time in milliseconds for this trigger
Returns:
Expiration time in milliseconds for this trigger

setTriggerExpirationTimeMillis

public long setTriggerExpirationTimeMillis(long expirationTimeMillis)
Set the expiration time in milliseconds for this trigger The expiration time cannot exceed a maximum allowed expiration time for this trigger.
Parameters:
expirationTimeMillis - expiration time in milliseconds
Returns:
The set expiration time in milliseconds.

getTimer

public java.util.Timer getTimer()
Get a Timer object to schedule TimerTask events
Returns:
A Timer object manage by the trigger manager

getOwnerName

protected final java.lang.String getOwnerName()
Get the user name that created this trigger
Returns:
Owner's name

getOwnerRealm

protected final java.lang.String getOwnerRealm()
Get the owner's realm name.
Returns:
Owner's realm name

getTriggerID

protected final TriggerID getTriggerID()
Get the TriggerID for this trigger
Returns:
TriggerID

isPinned

public final boolean isPinned()
Return the pin state of this trigger
Returns:
TriggerID