In WSO2, "Carbon" is the
unique OSGi-based middleware platform for all WSO2 carbon products. In every
carbon product like Message Broker, Complex Event Processor (CEP) and
Enterprise Service Bus (ESB) has in-built carbon registry as one of common
carbon feature. That in-built registry can be easily access by product
management console.
Using carbon registry as a service
for a carbon component
When developing an external carbon
component as stat publisher for Message Broker, had to use in-built carbon
registry to store UI data of stat publisher component. For developing purpose,
in-built carbon registry can be use as follows: (Used the example of stat
publisher component)
- Carbon platform is OSGi based platform. Therefore have to access carbon registry as a service.
- First have to retrieve registry service from Activator Class of the component. (Every OSGi bundle has bundle activator class)
- Importing package
import org.wso2.carbon.registry.core.service.RegistryService
- src reference
@scr.reference name="org.wso2.carbon.registry.service"
interface="org.wso2.carbon.registry.core.service.RegistryService"
cardinality="1..1" policy="dynamic" bind="setRegistryService"
unbind="unsetRegistryService"
- In activator class must have separate two methods to set registry to a variable and to unset.
/**
**Set RegistryService
**@param registryService - Registry for this server
*/
protected void setRegistryService(RegistryService registryService) {
StatPublisherValueHolder.setRegistryService(registryService );
}
/**
**Remove RegistryService
**@param registryService - Registry for this server
*/
protected void removeRegistryService(RegistryService registryService) {
StatPublisherValueHolder.setRegistryService(null);
}
- Through pointed registry service variable, can be used it to do any function within component context registry. Registry can be retrieve through registry service as follows;
Registry registry = StatPublisherValueHolder.getRegistryService()
.getConfigSystemRegistry(tenantId);
** In here use tenant ID to identify the carbon component instance. It will be
useful in multitenancy environment.
Happy Storing in Carbon :)
Comments and Questions are well come !
No comments:
Post a Comment