Created
December 3, 2019 16:13
-
-
Save rhusar/eebbb49f03917b4a937cba6d8a1d8c89 to your computer and use it in GitHub Desktop.
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
class SingletonService implements Service { | |
private Logger LOG = Logger.getLogger(this.getClass()); | |
private Node node; | |
private Supplier<Group> groupSupplier; | |
private Consumer<Node> nodeConsumer; | |
SingletonService(Supplier<Group> groupSupplier, Consumer<Node> nodeConsumer) { | |
this.groupSupplier = groupSupplier; | |
this.nodeConsumer = nodeConsumer; | |
} | |
@Override | |
public void start(StartContext context) { | |
this.node = this.groupSupplier.get().getLocalMember(); | |
this.nodeConsumer.accept(this.node); | |
LOG.infof("Singleton service is started on node '%s'.", this.node); | |
} | |
@Override | |
public void stop(StopContext context) { | |
LOG.infof("Singleton service is stopping on node '%s'.", this.node); | |
this.node = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment