Skip to content

Commit b13f381

Browse files
author
Gerald Unterrainer
committed
Merge branch 'develop'
2 parents 615273b + ed2e803 commit b13f381

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424
/target/
25+
26+
.settings/

.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
23
org.eclipse.jdt.core.compiler.codegen.targetPlatform=13
34
org.eclipse.jdt.core.compiler.compliance=13
45
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>crontab-scheduler</artifactId>
13-
<version>0.1.10</version>
13+
<version>0.1.11</version>
1414
<name>CrontabScheduler</name>
1515
<packaging>jar</packaging>
1616

src/main/java/info/unterrainer/commons/crontabscheduler/CrontabScheduler.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)