com.ibm.wbi.plugin
Class Meg

com.ibm.wbi.plugin.Meg
Direct Known Subclasses:
Editor, Generator, Monitor, RequestEditor

public abstract class Meg

A meg is a self-contained content tailoring entity. It is registered in a Plugin and receives a call to handleRequest() if its condition satisfies the request. The meg must be thread safe since multiple threads (for different requests) may be calling the handleRequest() method.


Field Summary
static java.lang.String COPYRIGHT
          IBM copyright information.
static int EDITOR
          An Editor meg.
static int GENERATOR
          A Generator meg.
static int MONITOR
          A Monitor meg.
static int REQUEST_EDITOR
          A Request Editor meg.
static int UNDEFINED
          An undefined meg type.
 
Constructor Summary
Meg()
          Constucts a new meg with default characteristics.
Meg(java.lang.String name, java.lang.String condition)
          Constructs a new meg with the specified characteristics and is enabled.
Meg(java.lang.String name, java.lang.String condition, int priority)
          Constructs a new meg with the specified characteristics and is enabled.
Meg(java.lang.String name, java.lang.String condition, int priority, boolean enabled)
          Constructs a new meg with the specified characteristics.
 
Method Summary
 void forwardRequest(Meg meg, RequestEvent event)
          Used if this meg wants to forward the request to another meg instead of rejecting the request.
 java.lang.String getCondition()
          Get the condition of the meg.
 boolean getEnabled()
          Get the enabled state of the meg.
 int getMegType()
          Get the type of this meg.
 java.lang.String getName()
          Get the name of the meg.
 Plugin getPlugin()
          Get the plugin of the meg.
 int getPriority()
          Get the priority of the meg (1-100).
abstract  void handleRequest(RequestEvent event)
          The method called to handle a request that satisfies the meg's condition.
 boolean isEnabled()
          Determine if this meg is enabled.
protected  void processRejectedRequest(RequestEvent request)
          Do any necessary processing when a request is rejected.
 void setCondition(java.lang.String condition)
          Set the condition of the meg.
 void setEnabled(boolean enabled)
          Set the enabled state of the meg.
 void setName(java.lang.String name)
          Set the name of the meg.
 void setPriority(int priority)
          Set the priority of the meg (1-100).
 void setup(java.lang.String propertyName)
          Load the attributes for the meg from a property file.
 void setup(java.lang.String name, java.lang.String condition)
          Setup the meg with the given attributes.
 void setup(java.lang.String name, java.lang.String condition, int priority)
          Setup the meg with the given attributes.
 void setup(java.lang.String name, java.lang.String condition, int priority, boolean enabled)
          Setup the meg with the given attributes.
 long threadManagerRun(com.ibm.wbi.plugin.ThreadManagerArgument argument)
          The method used to run the meg on it's own thread because it participate's in a thread pooling scheme.
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
IBM copyright information.

UNDEFINED

public static final int UNDEFINED
An undefined meg type.

REQUEST_EDITOR

public static final int REQUEST_EDITOR
A Request Editor meg.

GENERATOR

public static final int GENERATOR
A Generator meg.

EDITOR

public static final int EDITOR
An Editor meg.

MONITOR

public static final int MONITOR
A Monitor meg.
Constructor Detail

Meg

public Meg()
Constucts a new meg with default characteristics.

Meg

public Meg(java.lang.String name,
           java.lang.String condition)
Constructs a new meg with the specified characteristics and is enabled.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.

Meg

public Meg(java.lang.String name,
           java.lang.String condition,
           int priority)
Constructs a new meg with the specified characteristics and is enabled.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.
priority - The priority of the meg incase of a condition tie.

Meg

public Meg(java.lang.String name,
           java.lang.String condition,
           int priority,
           boolean enabled)
Constructs a new meg with the specified characteristics.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.
priority - The priority of the meg incase of a condition tie.
enabled - true if enabled.
Method Detail

setup

public void setup(java.lang.String propertyName)
Load the attributes for the meg from a property file. Any or all of the following attributes can be set: Name, Condition, Priority, Enabled
Parameters:
propertyFileName - The property file to load the meg attributes from.

setup

public void setup(java.lang.String name,
                  java.lang.String condition)
Setup the meg with the given attributes.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.

setup

public void setup(java.lang.String name,
                  java.lang.String condition,
                  int priority)
Setup the meg with the given attributes.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.
priority - The priority of the meg incase of a condition tie.

setup

public void setup(java.lang.String name,
                  java.lang.String condition,
                  int priority,
                  boolean enabled)
Setup the meg with the given attributes.
Parameters:
name - The name of the meg.
condition - The condition under which this meg should be invoked.
priority - The priority of the meg incase of a condition tie.
enabled - true if enabled.

getMegType

public int getMegType()
Get the type of this meg.
Returns:
One of Meg.UNDEFINED, Meg.REQUEST_EDITOR, Meg.GENERATOR, Meg.MONITOR

handleRequest

public abstract void handleRequest(RequestEvent event)
                            throws RequestRejectedException,
                                   java.io.IOException
The method called to handle a request that satisfies the meg's condition.
Parameters:
event - The request event used to modify the request/response.
Throws:
RequestRejectedException - Thrown if the request is rejected. This must be thrown before anything is written to the event's output stream otherwise the meg forfeits it's opportunity.
java.io.Exception - can be thrown if an exception was generated by the meg while processing the MegInput/OutputStreams.

forwardRequest

public void forwardRequest(Meg meg,
                           RequestEvent event)
                    throws RequestRejectedException,
                           java.io.IOException
Used if this meg wants to forward the request to another meg instead of rejecting the request.
Parameters:
meg - The meg to handle the request.
event - The request event to use.
Throws:
RequestRejectedException - Thrown if the request is rejected. This must be thrown before anything is written to the event's output stream otherwise the meg forfeits its opportunity.
java.io.Exception - can be thrown if an exception was generated by the meg while processing the MegInput/OutputStreams.

threadManagerRun

public final long threadManagerRun(com.ibm.wbi.plugin.ThreadManagerArgument argument)
                            throws java.lang.Exception
The method used to run the meg on it's own thread because it participate's in a thread pooling scheme.
Parameters:
argument - The argument contains the request event and the request that dispatched the meg.
Throws:
java.lang.Exception - If any exception/error occurs.

setName

public void setName(java.lang.String name)
Set the name of the meg.
Parameters:
name - The name of the meg.

getName

public java.lang.String getName()
Get the name of the meg.
Returns:
The name of the meg.

setCondition

public void setCondition(java.lang.String condition)
Set the condition of the meg. The condition property is used to determine whether the meg should be invoked for a transaction. The condition property is specified according to a grammar for Monitors, Editors, RequestEditors and Generators. The basic concept of the meg condition grammar is the use of one or more key-value pairs. A key-value pair consists of a keyword (predefined or application-specific) and an argument.

The following rules apply for specifying conditions:

WBI offers two different kinds of keywords: predefined and application-specific.

Predefined Keywords

The following predefined keywords can be used:

For example, if you wanted to register a response editor that was triggered when a response was issued from hosts that ended with the letters 'ibm.com' and were of type HTML, the following syntax would be used:

                  myMeg.setCondition("host *ibm.com & content-type *htm*");
                
If you wished to register a generator that fired when the following request was issued:
                  http://_myPlugin/generator/One
                
You would use the following when registering your generator:
                  myMeg.setCondition("protocol http & host _myPlugin & path /generator/One");
                

Application-Specific Keywords

The second kind of keywords are application-specific. These keywords are very useful if the plugin itself wants to control whether a particular meg should be invoked during a transaction or not. An application-specific keyword can be any string that complies with the following syntax:
                  AppKeyword := '$'( [a-zA-Z0-9] | '-' | '_' )*
                
The constraints on arguments to application-specific keywords are the same as for the predefined keywords.

Examples:
A simple application-specific keyword would be:

                  myMeg.setCondition("$myApp invokeMyMeg");
                
Application-specific keywords can be combined with any predefined keyword, such as:
                  myMeg.setCondition("$myApp invokeMyMeg & host www.yahoo.com");
                
Note:The rules for combining application-specific keywords with any other keyword (application-specific or predefined) are the same as for combinations of predefined keywords only.

A meg that was setup with application-specific keyword(s) will only be invoked during a transaction if another meg sets these keywords correctly. Application-specific keywords are referred to as extra rule keys within WBI. These extra rule keys can be set during a transaction by any meg that is invoked during the transaction. Extra rule keys are set by calling the

                   setExtraRuleKey( String key, String value ) 
                
method of class RequestInfo.
Parameters:
condition - A string holding the condition under which this meg gets invoked.
See Also:
RequestInfo, DocumentInfo


getCondition

public java.lang.String getCondition()
Get the condition of the meg.
Returns:
The condition of the meg as a String containing rules which are used to determine when a meg gets invoked.
See Also:
Meg.setCondition(...)

setEnabled

public void setEnabled(boolean enabled)
Set the enabled state of the meg.
Parameters:
enabled - true if enabled.

getEnabled

public boolean getEnabled()
Get the enabled state of the meg.
Returns:
true if enabled.

isEnabled

public boolean isEnabled()
Determine if this meg is enabled.
Returns:
true if enabled.

setPriority

public void setPriority(int priority)
Set the priority of the meg (1-100).
Parameters:
priority - The priority of the meg (1-100).

getPriority

public int getPriority()
Get the priority of the meg (1-100).
Returns:
The priority of the meg (1-100).

getPlugin

public Plugin getPlugin()
Get the plugin of the meg.
Parameters:
null - if none; else the plugin.

processRejectedRequest

protected void processRejectedRequest(RequestEvent request)
                               throws java.io.IOException
Do any necessary processing when a request is rejected. This method should be overridden by the various Meg types for special processing. If you override this, make sure to either call processNextMeg(...) or to write(..) to the stream so that waiting thread unblocks.
Parameters:
request - the original request that was passed to the Meg's handleRequest(...) method