Hi Hasnitha,

Thanks for the response. This is what I wanted, I think OSGI doesn't
support to do this via declaration, feature like adding a property as an
implementation class in the *@scr.reference*


Thanks
Godwin


On Mon, Nov 17, 2014 at 12:55 PM, Hasintha Indrajee <[email protected]>
wrote:

> Hi Godwin,
>
> You can track all OSGI Service implementations which implements a
> particular interface and then select the required service out of them.
>
> Following is a sample. In this sample addMessageSendingModule and
> removeMessageSendingModule are binded to add and remove services which
> implements interface
> "org.wso2.carbon.identity.application.message.mgt.MessageSendingModule".
>
> At the time of "addMessageSendingModule" execution you can get information
> about particular service and decide functionality over it.
>
> /**
>  * @scr.reference name="ldap.tenant.manager.listener.service"
>  *
> interface="org.wso2.carbon.identity.application.message.mgt.MessageSendingModule"
>  * cardinality="0..n" policy="dynamic"
>  * bind="addMessageSendingModule"
>  * unbind="removeMessageSendingModule"
>  * @scr.component name="identity.application.message.mgt" immediate="true"
>  */
>
> @SuppressWarnings("unused")
> public class ApplicationMessageMgtServiceComponent {
>
>     private List<MessageSendingModule> messageSendingModules = new
>             ArrayList<MessageSendingModule>();
>
>     protected void activate(ComponentContext ctxt) {
>        // Activate logic goes here
>     }
>
>     protected void deactivate(ComponentContext ctxt) {
>        // Deactivate logic goes here
>     }
>
>     /**
>      * Will register message sending modules dynamically. This method is
> used
>      * to bind the notification sending modules to msg mgt component
>      *
>      * @param module MessageSendingModule
>      */
>     protected void addMessageSendingModule(MessageSendingModule module) {
>         if (log.isDebugEnabled()) {
>             log.debug("Registering a message sending module " +
> module.getModuleName());
>         }
>         if (configBuilder != null) {
>
> module.init(configBuilder.getProperties(module.getModuleName()));
>             messageSendingModules.add(module);
>         }
>
>     }
>
>     /**
>      * This method is used to unbind notification sending modules. Whenever
>      * a module is dynamically deactivated, this method will unregister
> them.
>      *
>      * @param module MessageSendingModule
>      */
>     protected void removeMessageSendingModule(MessageSendingModule module)
> {
>         if (log.isDebugEnabled()) {
>             log.debug("Removing a message module " +
> module.getModuleName());
>         }
>         messageSendingModules.remove(module);
>     }
>
>
> On Mon, Nov 17, 2014 at 11:18 AM, Godwin Amila Shrimal <[email protected]>
> wrote:
>
>> Hi
>>
>> Most of the time we are having one OSGI Service implementation in carbon
>> products. There are situation we require to have multiple OSGI
>> implementations. Then how can we add declarative reference to particular
>> service implementation.
>>
>> Thanks
>> Godwin
>>
>> --
>> *Godwin Amila Shrimal*
>> Senior Software Engineer
>> WSO2 Inc.; http://wso2.com
>> lean.enterprise.middleware
>>
>> mobile: *+94772264165*
>> linkedin: *http://lnkd.in/KUum6D <http://lnkd.in/KUum6D>*
>> twitter: https://twitter.com/godwinamila
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>


-- 
*Godwin Amila Shrimal*
Senior Software Engineer
WSO2 Inc.; http://wso2.com
lean.enterprise.middleware

mobile: *+94772264165*
linkedin: *http://lnkd.in/KUum6D <http://lnkd.in/KUum6D>*
twitter: https://twitter.com/godwinamila
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to