Holds a List of references to JobListener instances and broadcasts all
events to them (in order) - if the event is not excluded via filtering
(read on).
The broadcasting behavior of this listener to delegate listeners may be
more convenient than registering all of the listeners directly with the
Trigger, and provides the flexibility of easily changing which listeners
get notified.
You may also register a number of Regular Expression patterns to match
the events against. If one or more patterns are registered, the broadcast
will only take place if the event applies to a job who's name/group
matches one or more of the patterns.
| Method from org.quartz.listeners.FilterAndBroadcastJobListener Detail: |
public void addJobGroupPattern(String regularExpression) {
if(regularExpression == null)
throw new IllegalArgumentException("Expression cannot be null!");
groupPatterns.add(regularExpression);
}
If one or more group patterns are specified, only events relating to
jobs who's group matches the given regular expression pattern
will be dispatched to the delegate listeners. |
public void addJobNamePattern(String regularExpression) {
if(regularExpression == null)
throw new IllegalArgumentException("Expression cannot be null!");
namePatterns.add(regularExpression);
}
If one or more name patterns are specified, only events relating to
jobs who's name matches the given regular expression pattern
will be dispatched to the delegate listeners. |
public void addListener(JobListener listener) {
listeners.add(listener);
}
|
public List getJobGroupPatterns() {
return namePatterns;
}
|
public List getJobNamePatterns() {
return namePatterns;
}
|
public List getListeners() {
return java.util.Collections.unmodifiableList(listeners);
}
|
public String getName() {
return name;
}
|
public void jobExecutionVetoed(JobExecutionContext context) {
if(!shouldDispatch(context))
return;
Iterator itr = listeners.iterator();
while(itr.hasNext()) {
JobListener jl = (JobListener) itr.next();
jl.jobExecutionVetoed(context);
}
}
|
public void jobToBeExecuted(JobExecutionContext context) {
if(!shouldDispatch(context))
return;
Iterator itr = listeners.iterator();
while(itr.hasNext()) {
JobListener jl = (JobListener) itr.next();
jl.jobToBeExecuted(context);
}
}
|
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
if(!shouldDispatch(context))
return;
Iterator itr = listeners.iterator();
while(itr.hasNext()) {
JobListener jl = (JobListener) itr.next();
jl.jobWasExecuted(context, jobException);
}
}
|
public boolean removeListener(JobListener listener) {
return listeners.remove(listener);
}
|
public boolean removeListener(String listenerName) {
Iterator itr = listeners.iterator();
while(itr.hasNext()) {
JobListener jl = (JobListener) itr.next();
if(jl.getName().equals(listenerName)) {
itr.remove();
return true;
}
}
return false;
}
|
protected boolean shouldDispatch(JobExecutionContext context) {
JobDetail job = context.getJobDetail();
if(namePatterns.size() == 0 && groupPatterns.size() == 0)
return true;
Iterator itr = groupPatterns.iterator();
while(itr.hasNext()) {
String pat = (String) itr.next();
if(job.getGroup().matches(pat))
return true;
}
itr = namePatterns.iterator();
while(itr.hasNext()) {
String pat = (String) itr.next();
if(job.getName().matches(pat))
return true;
}
return false;
}
|