Package net.sf.eBus.feed.pattern
Class EventPattern
- java.lang.Object
-
- net.sf.eBus.feed.pattern.EventPattern
-
public final class EventPattern extends Object
EventPatternprovides the two pieces of information needed to do pattern matching: 1) thenotification feedsproviding the events used in the match and 2) the pattern itself. Patterns come in two types:- Ordered: events must arrive in the event pattern order to effect a match.
- Unordered: specifies the number of each event type which must be collected to effect a match where the events may arrive in any order.
Once an event series is received matching the pattern, those events are tested against the
pattern condition. Only if that condition is satisfied is aMatchEventgenerated and forwarded to the subscriber.Event patterns are constructed via
EventPattern.Builder. See that class for detailed instructions on building event patterns.- Author:
- Charles W. Rapp
- See Also:
EventPattern.Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEventPattern.BuilderBuilderis the only way to create anEventFeedinstance.static classEventPattern.FeedInfoThis class provides the information needed byEPatternFeedtobuildto a notification message feed.static classEventPattern.PatternTypeeBus patterns come in two varieties: ordered and unordered.
-
Field Summary
Fields Modifier and Type Field Description static StringALL_EVENTSThe group "__ALL_EVENTS__" contains all matched events in received order.static Predicate<MatchEvent>DEFAULT_CONDITIONDefault match event which always returnstrue.static intDEFAULT_MATCH_COUNTThe default minimum and maximum match count is 1.static MatchConditionDEFAULT_PREDICATEDefault event match predicate returnstrue.static BiPredicate<List<ENotificationMessage>,ENotificationMessage>DEFAULT_UNTILThe default until predicate always returnstrue.protected StringmPatternNamePattern name used as theMatchEventsubject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EventPattern.Builderbuilder(String pName, EventPattern.PatternType pType)Returns a named, ordered or unordered event pattern builder which has no pre-defined parameters.static EventPattern.Builderbuilder(String pName, EventPattern.PatternType pType, Map<String,EventPattern.FeedInfo> parameters)Returns a named, ordered or unordered event pattern builder using the given parameters.EventPattern.FeedInfofeedInfo(String feedName)ReturnsEventPattern.FeedInfofor the given feed name.booleanisExclusive()Returnstrueif the events matching this pattern are used in one match only.EMessageKeymessageKey(String feedName)Returns the message key associated with the given feed name.Map<String,EventPattern.FeedInfo>parameters()Returns the read-only event pattern parameters map.StringpatternName()Returns the user-assigned pattern name.EventPattern.PatternTypepatternType()Returns the pattern type.
-
-
-
Field Detail
-
ALL_EVENTS
public static final String ALL_EVENTS
The group "__ALL_EVENTS__" contains all matched events in received order. This means the order may not be chronological according to the event timestamp.- See Also:
- Constant Field Values
-
DEFAULT_UNTIL
public static final BiPredicate<List<ENotificationMessage>,ENotificationMessage> DEFAULT_UNTIL
The default until predicate always returnstrue.
-
DEFAULT_MATCH_COUNT
public static final int DEFAULT_MATCH_COUNT
The default minimum and maximum match count is 1.- See Also:
- Constant Field Values
-
DEFAULT_PREDICATE
public static final MatchCondition DEFAULT_PREDICATE
Default event match predicate returnstrue.
-
DEFAULT_CONDITION
public static final Predicate<MatchEvent> DEFAULT_CONDITION
Default match event which always returnstrue. This condition should be used when subscriber wants all match events returned.
-
mPatternName
protected final String mPatternName
Pattern name used as theMatchEventsubject.
-
-
Method Detail
-
patternName
public String patternName()
Returns the user-assigned pattern name.- Returns:
- pattern name.
-
patternType
public EventPattern.PatternType patternType()
Returns the pattern type.- Returns:
- pattern type.
-
parameters
public Map<String,EventPattern.FeedInfo> parameters()
Returns the read-only event pattern parameters map.- Returns:
- event pattern parameters map.
-
isExclusive
public boolean isExclusive()
Returnstrueif the events matching this pattern are used in one match only. This means that if an event could be used in two separate matches of the same pattern, it will be used for only the the first completed match. The second match will be dropped as a result.Exclusive is only within a single pattern. Exclusion does not work between two separate pattern instances.
- Returns:
trueif events are used in a single match only.
-
feedInfo
public EventPattern.FeedInfo feedInfo(String feedName)
ReturnsEventPattern.FeedInfofor the given feed name.- Parameters:
feedName- a known feed name from parameters map.- Returns:
- feed information.
- Throws:
IllegalArgumentException- ifparameteris not a known feed name.
-
messageKey
public EMessageKey messageKey(String feedName)
Returns the message key associated with the given feed name.- Parameters:
feedName- feed name in parameters map.- Returns:
- message key.
- Throws:
IllegalArgumentException- ifparameteris not a known feed name.
-
builder
public static EventPattern.Builder builder(String pName, EventPattern.PatternType pType)
Returns a named, ordered or unordered event pattern builder which has no pre-defined parameters. These parameters must be defined usingEventPattern.Builder.beginParameterMap()/EventPattern.Builder.endParameterMap()before adding components to the event pattern.- Parameters:
pName- user-assigned pattern name. Used for logging purposes only.pType- specifies whether the pattern is ordered or unordered.- Returns:
- event pattern builder.
- Throws:
NullPointerException- ifpNameorpTypeisnull.IllegalArgumentException- ifpNameis an empty string.- See Also:
builder(String, PatternType, Map)
-
builder
public static EventPattern.Builder builder(String pName, EventPattern.PatternType pType, Map<String,EventPattern.FeedInfo> parameters)
Returns a named, ordered or unordered event pattern builder using the given parameters.parametersmaps a unique name to a notification feed. The map keys are used in the event pattern regular expression to reference a particular notification feed.This map may not be
null, empty, or containnullvalues.- Parameters:
pName- user-assigned pattern name. Used as the subject for postedmatch events. purposes only. May not benullor empty.pType- specifies whether the pattern is ordered or unordered.parameters- event pattern parameters.- Returns:
- event pattern builder.
- Throws:
NullPointerException- ifpName,pType, orparametersisnull.IllegalArgumentException- ifpNameis an empty string orparametersis either empty or contains anullvalue.- See Also:
builder(String, PatternType)
-
-