||
Skip to end of metadata
Go to start of metadata

The server startup observer is an extension point that can be used to execute any custom code during server startup. This allows a developer to perform any work before and/or after server startup (i.e. starting all the transports), as required. The ServerStartupObserver interface needs to be implemented in order to use this extension and it includes two methods to be overridden. The completingServerStartup() method could contain the implementation of any task that needs to be performed before starting all the transports. The completedServerStartup() method could contain the implementation of any task that needs to be performed after all the transports are completely started.

Usage

A sample implementation of the org.wso2.carbon.core.ServerStartupObserver interface is as follows:

package org.example.handlers;

import org.wso2.carbon.core.ServerStartupObserver;

public class SampleServerStartupObserver implements ServerStartupObserver{

   @Override 
   public void completingServerStartup() {
       // Any work that needs to be performed before starting all the transports

   }

   @Override 
   public void completedServerStartup() {
       // Any work that needs to be performed after completion of starting all the transports
   }
}

The following Maven dependency will be needed for the above implementation:

<dependency>
   <groupId>org.wso2.carbon</groupId>
   <artifactId>org.wso2.carbon.core</artifactId>
   <version>4.4.2</version>
</dependency>

After implementing the ServerStartupObserver interface, the implementation class needs to be registered as an OSGI service for the server to recognize it. Following is a sample bundle activator inside which the service is registered.

package org.example.handlers.internal;

import org.example.handlers.SampleServerStartupObserver;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.wso2.carbon.core.ServerStartupObserver;

public class SampleActivator implements BundleActivator {
   @Override public void start(BundleContext bundleContext) throws Exception {
       bundleContext.registerService(ServerStartupObserver.class.getName(), new SampleServerStartupObserver() , null);

   }

   @Override public void stop(BundleContext bundleContext) throws Exception {
      
   }
}

Your custom ServerStartupObserver should be packaged in an OSGi bundle and added to the <PRODUCT_HOME>/repository/components/dropins directory.

  • No labels