@@ -20,14 +20,26 @@ public class CrontabScheduler {
2020
2121 protected ScheduledExecutorService executor ;
2222 protected Map <String , BasicCrontabHandler > registeredHandlers = new HashMap <>();
23+ protected boolean handlingActive = true ;
24+
25+ public CrontabScheduler activateHandling () {
26+ handlingActive = true ;
27+ return this ;
28+ }
29+
30+ public CrontabScheduler deactivateHandling () {
31+ handlingActive = false ;
32+ return this ;
33+ }
2334
2435 /**
2536 * Sets new handlers or replaces existing ones in a way that no event-trigger
2637 * gets lost.
2738 *
2839 * @param handlers the handlers to set or use to replace the old ones
40+ * @return an instance of {@link CrontabScheduler} to provide a fluent interface
2941 */
30- public synchronized void setHandlers (final Collection <BasicCrontabHandler > handlers ) {
42+ public synchronized CrontabScheduler setHandlers (final Collection <BasicCrontabHandler > handlers ) {
3143 if (handlers == null )
3244 throw new NullPointerException ("Specify a valid collection of handlers." );
3345 for (BasicCrontabHandler handler : handlers )
@@ -38,15 +50,17 @@ public synchronized void setHandlers(final Collection<BasicCrontabHandler> handl
3850 for (BasicCrontabHandler handler : handlers )
3951 newMap .put (handler .getName (), handler );
4052 setHandlers (newMap );
53+ return this ;
4154 }
4255
4356 /**
4457 * Sets new handlers or replaces existing ones in a way that no event-trigger
4558 * gets lost.
4659 *
4760 * @param handlers the handlers to set or use to replace the old ones
61+ * @return an instance of {@link CrontabScheduler} to provide a fluent interface
4862 */
49- public synchronized void setHandlers (final Map <String , BasicCrontabHandler > handlers ) {
63+ public synchronized CrontabScheduler setHandlers (final Map <String , BasicCrontabHandler > handlers ) {
5064 ZonedDateTime now = ZonedDateTime .now ();
5165 if (handlers == null )
5266 throw new NullPointerException ("Specify a valid collection of handlers." );
@@ -65,6 +79,7 @@ public synchronized void setHandlers(final Map<String, BasicCrontabHandler> hand
6579 for (BasicCrontabHandler handler : registeredHandlers .values ())
6680 handler .initialize (now );
6781 pollAndAdvanceHandlers (now , oldMap );
82+ return this ;
6883 }
6984
7085 /**
@@ -94,9 +109,10 @@ public synchronized List<BasicCrontabHandler> getCopyOfHandlers() {
94109 return new ArrayList <>(registeredHandlers .values ());
95110 }
96111
97- public synchronized void clearHandlers () {
112+ public synchronized CrontabScheduler clearHandlers () {
98113 log .debug ("Clearing handler-map." );
99114 registeredHandlers .clear ();
115+ return this ;
100116 }
101117
102118 @ Builder
@@ -115,6 +131,10 @@ private synchronized void pollAndAdvanceHandlers(final Map<String, BasicCrontabH
115131
116132 private synchronized void pollAndAdvanceHandlers (final ZonedDateTime now ,
117133 final Map <String , BasicCrontabHandler > handlers ) {
134+
135+ if (!handlingActive )
136+ return ;
137+
118138 for (BasicCrontabHandler handler : handlers .values ())
119139 try {
120140 handler .eventuallyHandle (now );
0 commit comments