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 boolean
This method is called instart()
method.com.google.common.util.concurrent.ListenableFuture<Boolean>
shutdown()
Shutdown module.final boolean
Shutdown module and wait for completion for specified amount of time.com.google.common.util.concurrent.ListenableFuture<Boolean>
start()
Start in background and return immediately.void
Start and block until shutdown is requested.void
startBlocking
(Consumer<Boolean> initFinishCallback) Start and block until shutdown is requested.protected abstract boolean
This method is called inshutdown()
method.
-
Constructor Details
-
AbstractLightyModule
-
AbstractLightyModule
public AbstractLightyModule()
-
-
Method Details
-
initProcedure
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
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
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
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
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:LightyModule
Shutdown module.- Specified by:
shutdown
in interfaceLightyModule
- Returns:
- true if module shutdown was successful, false or exception otherwise.
-
shutdown
Description copied from interface:LightyModule
Shutdown module and wait for completion for specified amount of time.- Specified by:
shutdown
in 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.
-