public abstract class AbstractLightyModule extends Object implements LightyModule
LightyModule interface with
synchronization of LightyModule.start(),
LightyModule.startBlocking() and LightyModule.shutdown()
methods. Users who don't want to implement their own synchronization
can extend this class and provide just
initProcedure() and
stopProcedure() methods.These methods
will be then automatically called in
start(),
startBlocking() and
shutdown() methods.
Example usage:
public class MyLightyModule extends AbstractLightyModule {
private SomeBean someBean;
...
@Override
protected boolean initProcedure() {
this.someBean = new SomeBean();
boolean success = this.someBean.init();
return success;
}
@Override
protected boolean stopProcedure() {
boolean stopSuccess = this.someBean.stop();
this.someBean = null;
return stopSuccess;
}
}
| Constructor and Description |
|---|
AbstractLightyModule() |
AbstractLightyModule(ExecutorService executorService) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
initProcedure()
This method is called in
start() method. |
com.google.common.util.concurrent.ListenableFuture<Boolean> |
shutdown()
shutdown module
|
com.google.common.util.concurrent.ListenableFuture<Boolean> |
start()
Start in background and return immediately.
|
void |
startBlocking()
Start and block until shutdown is requested.
|
void |
startBlocking(Consumer<Boolean> initFinishCallback)
Start and block until shutdown is requested.
|
protected abstract boolean |
stopProcedure()
This method is called in
shutdown() method. |
public AbstractLightyModule(ExecutorService executorService)
public AbstractLightyModule()
protected abstract boolean initProcedure()
start() method.
Implementation of this method should initialize everything necessary.protected abstract boolean stopProcedure()
shutdown() method.
Implementation of this method should do everything necessary to
shutdown correctly (e.g. stop initialized beans, release resources, ...).public com.google.common.util.concurrent.ListenableFuture<Boolean> start()
LightyModulestart in interface LightyModulepublic void startBlocking()
throws InterruptedException
LightyModulestartBlocking in interface LightyModuleInterruptedException - thrown in case module initialization fails.public void startBlocking(Consumer<Boolean> initFinishCallback) throws InterruptedException
initFinishCallback - callback that will be called after start is completed.InterruptedException - thrown in case module initialization fails.public com.google.common.util.concurrent.ListenableFuture<Boolean> shutdown()
LightyModuleshutdown in interface LightyModuleCopyright © 2019. All rights reserved.