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

The ArtifactUnloader interface is an extension point that is used when Ghost Deployment is enabled for your product. The main requirement for an ArtifactUnloader is to unload the inactive artifacts and load the artifacts in ghost form, i.e the lazy loaded form of the artifacts.

If defined and registered correctly, these ArtifactUnloader instances will be called by the Carbon core component using a scheduled task that runs periodically to unload inactive artifacts. Currently, these ArtifactUnloader instances are implemented for services and web app artifacts in their relevant components. To handle service unloading when ghost deployment is enabled, the ServiceUnloader interface has been implemented. Similarly, the WebappUnloader interface is implemented to handle the unloading of web apps. However, if there are other artifact types that also support ghost deployment and need support for unloading those artifacts when they are found inactive, a new ArtifactUnloader interface should be implemented. These artifact unloaders should be registered as OSGi services. The Carbon core component will then call all the instances that are registered as OSGi services using a scheduled task.


Implementing the ArtifactUnloader interface

Shown below is a sample implementation of the ArtifactUnloader interface.

import org.wso2.carbon.core.ArtifactUnloader;

/**
* An example implementation of ArtifactUnloader which will be called by the carbon core periodically to unload inactive artifacts.
*
*/
public class ExampleArtifactUnloader implements ArtifactUnloader {
   @Override
   public void unload() {
       //unloading of inactive artifacts logic should go here
   }
}

Registering the new interface

The ArtifactUnloader implementation should be registered as an OSGi service using the org.wso2.carbon.core.ArtifactUnloader interface as shown below. 

ExampleArtifactUnloader exampleUnloader = new ExampleArtifactUnloader();
bundleContext.registerService(ArtifactUnloader.class.getName(), exampleUnloader, null); 

The required Maven dependency for the org.wso2.carbon.core.ArtifactUnloader interface is org.wso2.carbon.core as shown below.

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

You can also check the actual implementations of ServiceUnloader and WebappUnloader, which are used for unloading inactive services and web apps respectively. These unloader implementations check for inactive artifacts that are not accessed over a default time period of 10 minutes and will unload them from the memory and load them back in ghost form into the memory. When a request is received, then those ghost artifacts will be loaded into the actual form before serving any requests. The call to unload() method will happen through periodic tasks.

  • No labels