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
Registering the new interface
ArtifactUnloader implementation should be registered as an OSGi service using the
org.wso2.carbon.core.ArtifactUnloader interface as shown below.
The required Maven dependency for the
org.wso2.carbon.core.ArtifactUnloader interface is
org.wso2.carbon.core as shown below.
You can also check the actual implementations of
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.