Package lumis.portal.deployment.lifecycle

Deployment lifecycle


Lifecycle overview


Contains deployment lifecycle-related classes and interfaces. There are two lifecycle available to be used:
One of them, AfterClassLoaderStarted, indicate a method that will be called after the owner module's class loader is started.
The other one, BeforeClassLoaderStop, indicate a method that will be called before the owner module's class loader is stopped.
For both of them, the target method must be a zero-arg, public, non-static, non-abstract method. The class the target method belongs must be a public, non-abstract class and must have a no-arg public constructor.
The typical usage is:
 import lumis.portal.deployment.lifecycle.AfterClassLoaderStarted;
 import lumis.portal.deployment.lifecycle.BeforeClassLoaderStop;
 
 public class MyModuleLifecycle
 {
        @AfterClassLoaderStarted
        public void afterClassLoaderStarted()
        {
                // perform any start code here
        }
 
        @BeforeClassLoaderStop
        public void beforeClassLoaderStop()
        {
                // perform any stop code here (such as resource disposal)
        }
 }
 


Class inheritance


It is important to notice that class inheritance is considered.
For example, suppose the given classes:
 import lumis.portal.deployment.lifecycle.AfterClassLoaderStarted;
 import lumis.portal.deployment.lifecycle.BeforeClassLoaderStop;
 
 public abstract class AbstractLifecycle
 {
        @AfterClassLoaderStarted
        public void afterClassLoaderStarted()
        {
                // perform any start code here
        }
 
        @BeforeClassLoaderStop
        public void beforeClassLoaderStop()
        {
                // perform any stop code here (such as resource disposal)
        }
 }
 


And:
 import lumis.portal.deployment.lifecycle.AfterClassLoaderStarted;
 import lumis.portal.deployment.lifecycle.BeforeClassLoaderStop;
 
 public class MyLifecycle extends AbstractLifecycle
 {
 }
 


In that situation, the methods AbstractLifecycle.afterClassLoaderStarted() and AbstractLifecycle.beforeClassLoaderStop() will be called in instances of MyLifecycle class (that inherit those methods be extension).

Object instantiation


Each time a lifecycle method is going to be called, a new object instance is created (using the no-arg constructor of the class).
So, a code like the following will not work as one may expect:
 import lumis.portal.deployment.lifecycle.AfterClassLoaderStarted;
 import lumis.portal.deployment.lifecycle.BeforeClassLoaderStop;
 
 public class ModuleLifecycle
 {
        private Object someObject;
 
        @AfterClassLoaderStarted
        public void afterClassLoaderStarted()
        {
                // create the someObject instance
                someObject = new Object();
        }
 
        @BeforeClassLoaderStop
        public void beforeClassLoaderStop()
        {
                // use the someObject instance
                someObject.toString(); // <--- null pointer exception here (someObject is null at this point)
        }
 }
 


When the afterClassLoaderStarted() method is invoked, an instance of ModuleLifecycle is created and this instance is discarded as soon as this method is finished.
When the beforeClassLoaderStop() method is invoked, another instance of ModuleLifecycle is created. This method will not use the same instance the previous did.

Error handling


When a given lifecycle method generates an error, the classloader start/stop and even the deployment will not be interrupted.
For example:
 import lumis.portal.deployment.lifecycle.AfterClassLoaderStarted;
 import lumis.portal.deployment.lifecycle.BeforeClassLoaderStop;
 
 public class ModuleLifecycle
 {
        @AfterClassLoaderStarted
        public void afterClassLoaderStarted()
        {
                // the following exception will neither prevent the classloader to be started 
                // nor the deployment to be completed
                throw new RuntimeException("OOOpppss");
        }
 
        @BeforeClassLoaderStop
        public void beforeClassLoaderStop()
        {
                // this method will still be called before the classloader is stopped
        }
 }
 


Classloader lifecycle debugging


To debug the LumisXP classloaders lifecycle execution, the following loggers must have their level set to debug:
  • lumis.portal.deployment.PortalClassLoader
  • lumis.portal.deployment.lifecycle.DeploymentLifecycleUtil