What is the different Between 'Bind' and 'Activate

577 Views Asked by At

I started using OSGI in eclipse.Under Declarative Services I found out that there are two methods that's been executed once a service is activated. I.e Activate and Bind.. What is the difference between these two?

If I want to execute certain actions to be performed when my service is started, do I put it in the Bind method or the Activate method?

2

There are 2 best solutions below

0
On

The activate method is called when your component is activated. So this is a good time to perform any initialization activities. A bind method is called once for each service your component references. So if your component has a reference to LogService, your bind method for LogService will be called with each LogService object bound to your component. The method can then store the LogService in a field.

1
On

Bind methods are used to inject service references into the component instance, i.e. services that the component depends on. The activate method (if declared) is called in the last step of the activation process, when a component is satisfied.

So, I suppose you want to code your actions in the activate method, knowing that all your mandatory dependencies have been resolved at that point.

Note also that a declarative service component isn't a service in itself, but it may provide one.