We were recently working on a customer scenario who wanted to make a custom code call during server startup.In order to achieve the same you would need to implement the Load interface in your custom component as described below:
In the component.xml you would need to use the load-class tag in for the classes which implement the same and are to be loaded e.g;
<load-class>please.tell.me.you.start.LifeCycleImpl</load-class>
In the above example the LifeCycleImpl class implements the Load interface (com.adobe.idp.dsc.component.Load ) which is defined as below:
public interface Load {
public void onLoad();
public void onUnload();
}
The corresponding onLoad() method call contains the custom code that we would like to be called during startup. In a similar way we can use the onUnload() method.
The corresponding class “LifeCycleImpl” in our case implementing Load interface will look like below:
import java.util.logging.Level;
import com.adobe.idp.dsc.component.ComponentContext;
import com.adobe.idp.dsc.component.LifeCycle;
import com.adobe.idp.dsc.component.Load;
import com.adobe.logging.AdobeLogger;
public class LifeCycleImpl implements LifeCycle, Load {
private static final AdobeLogger logger = AdobeLogger.getAdobeLogger(LifeCycleImpl.class);
private ComponentContext m_ctx;
public void setComponentContext(ComponentContext aCtx) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, “setComponentContext: ” + aCtx.getComponent().getComponentId());
}
m_ctx = aCtx;
}
public void onStart() {
logger.log(Level.INFO, “Called onStart: ” + m_ctx.getComponent().getComponentId());
}
public void onStop() {
logger.log(Level.INFO, “Called onStop: ” + m_ctx.getComponent().getComponentId());
}
public void onLoad(){
System.out.println(“***Custom code implemtation goes here*****”);
logger.log(Level.INFO, “*************Called onLoad “);
}
public void onUnload() {
// TODO Auto-generated method stub
}
}
Calling custom code implementation during LiveCycle Server Startup,