Source Code Cross Referenced for FilterAndBroadcastTriggerListener.java in  » Project-Management » quartz » org » quartz » listeners » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » quartz » org.quartz.listeners 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2006 OpenSymphony
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy
006:         * of the License at
007:         *
008:         *   http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations
014:         * under the License.
015:         */
016:        package org.quartz.listeners;
017:
018:        import java.util.Iterator;
019:        import java.util.LinkedList;
020:        import java.util.List;
021:
022:        import org.quartz.JobExecutionContext;
023:        import org.quartz.Trigger;
024:        import org.quartz.TriggerListener;
025:
026:        /**
027:         * Holds a List of references to TriggerListener instances and broadcasts all
028:         * events to them (in order) - if the event is not excluded via filtering
029:         * (read on).
030:         *
031:         * <p>The broadcasting behavior of this listener to delegate listeners may be
032:         * more convenient than registering all of the listeners directly with the
033:         * Trigger, and provides the flexibility of easily changing which listeners
034:         * get notified.</p>
035:         *
036:         * <p>You may also register a number of Regular Expression patterns to match
037:         * the events against. If one or more patterns are registered, the broadcast
038:         * will only take place if the event applies to a trigger who's name/group
039:         * matches one or more of the patterns.</p>
040:         *
041:         * @see #addListener(org.quartz.TriggerListener)
042:         * @see #removeListener(org.quartz.TriggerListener)
043:         * @see #removeListener(String)
044:         * @see #addTriggerNamePattern(String)
045:         * @see #addTriggerGroupPattern(String)
046:         *
047:         * @author James House (jhouse AT revolition DOT net)
048:         */
049:        public class FilterAndBroadcastTriggerListener implements 
050:                TriggerListener {
051:
052:            private String name;
053:            private List listeners;
054:            private List namePatterns = new LinkedList();
055:            private List groupPatterns = new LinkedList();
056:
057:            /**
058:             * Construct an instance with the given name.
059:             *
060:             * (Remember to add some delegate listeners!)
061:             *
062:             * @param name the name of this instance
063:             */
064:            public FilterAndBroadcastTriggerListener(String name) {
065:                if (name == null)
066:                    throw new IllegalArgumentException(
067:                            "Listener name cannot be null!");
068:                this .name = name;
069:                listeners = new LinkedList();
070:            }
071:
072:            /**
073:             * Construct an instance with the given name, and List of listeners.
074:             *
075:             * @param name the name of this instance
076:             * @param listeners the initial List of TriggerListeners to broadcast to.
077:             */
078:            public FilterAndBroadcastTriggerListener(String name, List listeners) {
079:                this (name);
080:                this .listeners.addAll(listeners);
081:            }
082:
083:            public String getName() {
084:                return name;
085:            }
086:
087:            public void addListener(TriggerListener listener) {
088:                listeners.add(listener);
089:            }
090:
091:            public boolean removeListener(TriggerListener listener) {
092:                return listeners.remove(listener);
093:            }
094:
095:            public boolean removeListener(String listenerName) {
096:                Iterator itr = listeners.iterator();
097:                while (itr.hasNext()) {
098:                    TriggerListener l = (TriggerListener) itr.next();
099:                    if (l.getName().equals(listenerName)) {
100:                        itr.remove();
101:                        return true;
102:                    }
103:                }
104:                return false;
105:            }
106:
107:            public List getListeners() {
108:                return java.util.Collections.unmodifiableList(listeners);
109:            }
110:
111:            /**
112:             * If one or more name patterns are specified, only events relating to
113:             * triggers who's name matches the given regular expression pattern
114:             * will be dispatched to the delegate listeners.
115:             *
116:             * @param regularExpression
117:             */
118:            public void addTriggerNamePattern(String regularExpression) {
119:                if (regularExpression == null)
120:                    throw new IllegalArgumentException(
121:                            "Expression cannot be null!");
122:
123:                namePatterns.add(regularExpression);
124:            }
125:
126:            public List getTriggerNamePatterns() {
127:                return namePatterns;
128:            }
129:
130:            /**
131:             * If one or more group patterns are specified, only events relating to
132:             * triggers who's group matches the given regular expression pattern
133:             * will be dispatched to the delegate listeners.
134:             *
135:             * @param regularExpression
136:             */
137:            public void addTriggerGroupPattern(String regularExpression) {
138:                if (regularExpression == null)
139:                    throw new IllegalArgumentException(
140:                            "Expression cannot be null!");
141:
142:                groupPatterns.add(regularExpression);
143:            }
144:
145:            public List getTriggerGroupPatterns() {
146:                return namePatterns;
147:            }
148:
149:            protected boolean shouldDispatch(Trigger trigger) {
150:
151:                if (namePatterns.size() == 0 && groupPatterns.size() == 0)
152:                    return true;
153:
154:                Iterator itr = groupPatterns.iterator();
155:                while (itr.hasNext()) {
156:                    String pat = (String) itr.next();
157:                    if (trigger.getGroup().matches(pat))
158:                        return true;
159:                }
160:
161:                itr = namePatterns.iterator();
162:                while (itr.hasNext()) {
163:                    String pat = (String) itr.next();
164:                    if (trigger.getName().matches(pat))
165:                        return true;
166:                }
167:
168:                return false;
169:            }
170:
171:            public void triggerFired(Trigger trigger,
172:                    JobExecutionContext context) {
173:
174:                if (!shouldDispatch(trigger))
175:                    return;
176:
177:                Iterator itr = listeners.iterator();
178:                while (itr.hasNext()) {
179:                    TriggerListener l = (TriggerListener) itr.next();
180:                    l.triggerFired(trigger, context);
181:                }
182:            }
183:
184:            public boolean vetoJobExecution(Trigger trigger,
185:                    JobExecutionContext context) {
186:
187:                if (!shouldDispatch(trigger))
188:                    return false;
189:
190:                Iterator itr = listeners.iterator();
191:                while (itr.hasNext()) {
192:                    TriggerListener l = (TriggerListener) itr.next();
193:                    if (l.vetoJobExecution(trigger, context))
194:                        return true;
195:                }
196:                return false;
197:            }
198:
199:            public void triggerMisfired(Trigger trigger) {
200:
201:                if (!shouldDispatch(trigger))
202:                    return;
203:
204:                Iterator itr = listeners.iterator();
205:                while (itr.hasNext()) {
206:                    TriggerListener l = (TriggerListener) itr.next();
207:                    l.triggerMisfired(trigger);
208:                }
209:            }
210:
211:            public void triggerComplete(Trigger trigger,
212:                    JobExecutionContext context, int triggerInstructionCode) {
213:
214:                if (!shouldDispatch(trigger))
215:                    return;
216:
217:                Iterator itr = listeners.iterator();
218:                while (itr.hasNext()) {
219:                    TriggerListener l = (TriggerListener) itr.next();
220:                    l.triggerComplete(trigger, context, triggerInstructionCode);
221:                }
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.