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 implementLightyModule
interface 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 boolean
initProcedure()
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.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 inshutdown()
method.
-
-
-
Constructor Detail
-
AbstractLightyModule
public AbstractLightyModule(ExecutorService executorService)
-
AbstractLightyModule
public AbstractLightyModule()
-
-
Method Detail
-
initProcedure
protected abstract boolean initProcedure() throws InterruptedException
This method is called instart()
method. Implementation of this method should initialize everything necessary.- Returns:
- success of initialization
- Throws:
InterruptedException
- if initialization was interrupted.
-
stopProcedure
protected abstract boolean stopProcedure() throws InterruptedException
This 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
- if stopping was interrupted.
-
start
public com.google.common.util.concurrent.ListenableFuture<Boolean> start()
Description copied from interface:LightyModule
Start in background and return immediately.- Specified by:
start
in interfaceLightyModule
- Returns:
- true if module initialization was successful, false or exception otherwise.
-
startBlocking
public void startBlocking() throws InterruptedException
Description copied from interface:LightyModule
Start and block until shutdown is requested.- Specified by:
startBlocking
in 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:LightyModule
Shutdown module.- Specified by:
shutdown
in interfaceLightyModule
- Returns:
- true if module shutdown was successful, false or exception otherwise.
-
-