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
This abstract class implement
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;
}
}
- Author:
- andrej.zan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanThis method is called instart()method.com.google.common.util.concurrent.ListenableFuture<Boolean> shutdown()Shutdown module.final booleanShutdown module and wait for completion for specified amount of time.com.google.common.util.concurrent.ListenableFuture<Boolean> start()Start in background and return immediately.voidStart and block until shutdown is requested.voidstartBlocking(Consumer<Boolean> initFinishCallback) Start and block until shutdown is requested.protected abstract booleanThis method is called inshutdown()method.
-
Constructor Details
-
AbstractLightyModule
-
AbstractLightyModule
public AbstractLightyModule()
-
-
Method Details
-
initProcedure
protected abstract boolean initProcedure() throws InterruptedException, javax.servlet.ServletExceptionThis method is called instart()method. Implementation of this method should initialize everything necessary.- Returns:
- success of initialization
- Throws:
InterruptedException- if initialization was interrupted.javax.servlet.ServletException
-
stopProcedure
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.ExecutionException
-
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
Description copied from interface:LightyModuleStart and block until shutdown is requested.- Specified by:
startBlockingin interfaceLightyModule- Throws:
InterruptedException- thrown in case module initialization fails.
-
startBlocking
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
Description copied from interface:LightyModuleShutdown module.- Specified by:
shutdownin interfaceLightyModule- Returns:
- true if module shutdown was successful, false or exception otherwise.
-
shutdown
Description copied from interface:LightyModuleShutdown module and wait for completion for specified amount of time.- Specified by:
shutdownin interfaceLightyModule- Parameters:
duration- duration of time to wait for completionunit- unit of time duration- Returns:
- true if module shutdown was successful in specified time, false otherwise.
-