-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from evenh/startup-strategy
Configurable scheduler start
- Loading branch information
Showing
10 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...tarter/src/main/java/com/github/kagkarlsson/scheduler/boot/config/DbSchedulerStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.kagkarlsson.scheduler.boot.config; | ||
|
||
public interface DbSchedulerStarter { | ||
void doStart(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...n/java/com/github/kagkarlsson/scheduler/boot/config/startup/AbstractSchedulerStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.kagkarlsson.scheduler.boot.config.startup; | ||
|
||
import com.github.kagkarlsson.scheduler.Scheduler; | ||
import com.github.kagkarlsson.scheduler.SchedulerState; | ||
import com.github.kagkarlsson.scheduler.boot.config.DbSchedulerStarter; | ||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class AbstractSchedulerStarter implements DbSchedulerStarter { | ||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
private final Scheduler scheduler; | ||
|
||
protected AbstractSchedulerStarter(Scheduler scheduler) { | ||
this.scheduler = Objects.requireNonNull(scheduler, "A scheduler must be provided"); | ||
} | ||
|
||
@Override | ||
public void doStart() { | ||
SchedulerState state = scheduler.getSchedulerState(); | ||
|
||
if (state.isShuttingDown()) { | ||
log.warn("Scheduler is shutting down - will not attempting to start"); | ||
return; | ||
} | ||
|
||
if (state.isStarted()) { | ||
log.info("Scheduler already started - will not attempt to start again"); | ||
return; | ||
} | ||
|
||
log.info("Triggering scheduler start"); | ||
scheduler.start(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...src/main/java/com/github/kagkarlsson/scheduler/boot/config/startup/ContextReadyStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.kagkarlsson.scheduler.boot.config.startup; | ||
|
||
import com.github.kagkarlsson.scheduler.Scheduler; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
|
||
public class ContextReadyStart extends AbstractSchedulerStarter { | ||
public ContextReadyStart(Scheduler scheduler) { | ||
super(scheduler); | ||
} | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void whenContextIsReady() { | ||
doStart(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...er/src/main/java/com/github/kagkarlsson/scheduler/boot/config/startup/ImmediateStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.kagkarlsson.scheduler.boot.config.startup; | ||
|
||
import com.github.kagkarlsson.scheduler.Scheduler; | ||
import javax.annotation.PostConstruct; | ||
|
||
public class ImmediateStart extends AbstractSchedulerStarter { | ||
public ImmediateStart(final Scheduler scheduler) { | ||
super(scheduler); | ||
} | ||
|
||
@PostConstruct | ||
void startImmediately() { | ||
doStart(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters