Package io.lighty.core.controller.api
Class AbstractLightyModule
- java.lang.Object
-
- io.lighty.core.controller.api.AbstractLightyModule
-
- All Implemented Interfaces:
LightyModule
- Direct Known Subclasses:
LightyControllerImpl
public abstract class AbstractLightyModule extends Object implements LightyModule
This abstract class implementLightyModuleinterface with synchronization ofLightyModule.start(),LightyModule.startBlocking()andLightyModule.shutdown()methods. Users who don't want to implement their own synchronization can extend this class and provide justinitProcedure()andstopProcedure()methods.These methods will be then automatically called instart(),startBlocking()andshutdown()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; } }- Author:
- andrej.zan
-
-
Constructor Summary
Constructors Constructor Description AbstractLightyModule()AbstractLightyModule(ExecutorService executorService)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract booleaninitProcedure()This method is called instart()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.voidstartBlocking()Start and block until shutdown is requested.voidstartBlocking(Consumer<Boolean> initFinishCallback)Start and block until shutdown is requested.protected abstract booleanstopProcedure()This method is called inshutdown()method.
-
-
-
Constructor Detail
-
AbstractLightyModule
public AbstractLightyModule(ExecutorService executorService)
-
AbstractLightyModule
public AbstractLightyModule()
-
-
Method Detail
-
initProcedure
protected abstract boolean initProcedure() throws InterruptedExceptionThis method is called instart()method. Implementation of this method should initialize everything necessary.- Returns:
- success of initialization
- Throws:
InterruptedException
-
stopProcedure
protected abstract boolean stopProcedure() throws InterruptedExceptionThis method is called inshutdown()method. Implementation of this method should do everything necessary to shutdown correctly (e.g. stop initialized beans, release resources, ...).- Returns:
- success of stop.
- Throws:
InterruptedException
-
start
public com.google.common.util.concurrent.ListenableFuture<Boolean> start()
Description copied from interface:LightyModuleStart in background and return immediately.- Specified by:
startin interfaceLightyModule- Returns:
- true if module initialization was successful, false or exception otherwise.
-
startBlocking
public void startBlocking() throws InterruptedExceptionDescription copied from interface:LightyModuleStart and block until shutdown is requested.- Specified by:
startBlockingin interfaceLightyModule- Throws:
InterruptedException- thrown in case module initialization fails.
-
startBlocking
public void startBlocking(Consumer<Boolean> initFinishCallback) throws InterruptedException
Start and block until shutdown is requested.- Parameters:
initFinishCallback- callback that will be called after start is completed.- Throws:
InterruptedException- thrown in case module initialization fails.
-
shutdown
public com.google.common.util.concurrent.ListenableFuture<Boolean> shutdown()
Description copied from interface:LightyModuleShutdown module.- Specified by:
shutdownin interfaceLightyModule- Returns:
- true if module shutdown was successful, false or exception otherwise.
-
-