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 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 Details

    • AbstractLightyModule

      public AbstractLightyModule(ExecutorService executorService)
    • AbstractLightyModule

      public AbstractLightyModule()
  • Method Details

    • initProcedure

      protected abstract boolean initProcedure() throws InterruptedException
      This method is called in start() 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 in shutdown() 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 interface LightyModule
      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 interface LightyModule
      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 interface LightyModule
      Returns:
      true if module shutdown was successful, false or exception otherwise.
    • shutdown

      public final boolean shutdown(long duration, TimeUnit unit)
      Description copied from interface: LightyModule
      Shutdown module and wait for completion for specified amount of time.
      Specified by:
      shutdown in interface LightyModule
      Parameters:
      duration - duration of time to wait for completion
      unit - unit of time duration
      Returns:
      true if module shutdown was successful in specified time, false otherwise.