Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Service Activation (Bundle-ActivationPolicy: lazy)
Service Activation (Bundle-ActivationPolicy: lazy) [message #127030] Fri, 06 March 2009 15:02 Go to next message
Emilio Numazaki is currently offline Emilio NumazakiFriend
Messages: 5
Registered: July 2009
Junior Member
Hi,

Let's suppose I have a bundle that MANIFEST attribute
"Bundle-ActivationPolicy" is set as lazy.

Bundle-ActivationPolicy: lazy

Is this bundle supposed to be activated when I get this service through
context.getServiceReference method?

ServiceReference reference =
context.getServiceReference(ServicosCliente.class.getName()) ;
ServicosCliente service = (ServicosCliente) context
.getService(reference);

My problem is if I do not set this bundle as "Eclipse-AutoStart: true", it
is not being found.

Thanks
Re: Service Activation (Bundle-ActivationPolicy: lazy) [message #127055 is a reply to message #127030] Fri, 06 March 2009 15:38 Go to previous messageGo to next message
Simon Kaegi is currently offline Simon KaegiFriend
Messages: 381
Registered: July 2009
Senior Member
Whe a "lazy" bundle is started it moves into a "STARTING" (or "LAZY") state.
The first time a class from this bundle is loaded the bundle will be
properly activated and your Activator's start method will get called.

A sort of cheeky technique some people to get the real activation to happen
is to when getting the service to use the Service class to get the name as
this will cause the class to get loaded.

Another approach that you haven't mentioned is to use Declarative Services.

-Simon

"Emilio Numazaki" <mediasonic.l@gmail.com> wrote in message
news:9e369138e4a45144b1240c3a0374f499$1@www.eclipse.org...
> Hi,
>
> Let's suppose I have a bundle that MANIFEST attribute
> "Bundle-ActivationPolicy" is set as lazy.
>
> Bundle-ActivationPolicy: lazy
>
> Is this bundle supposed to be activated when I get this service through
> context.getServiceReference method?
>
> ServiceReference reference =
> context.getServiceReference(ServicosCliente.class.getName()) ;
> ServicosCliente service = (ServicosCliente) context
> .getService(reference);
>
> My problem is if I do not set this bundle as "Eclipse-AutoStart: true", it
> is not being found.
> Thanks
>
Re: Service Activation (Bundle-ActivationPolicy: lazy) [message #127093 is a reply to message #127055] Fri, 06 March 2009 17:32 Go to previous messageGo to next message
Emilio Numazaki is currently offline Emilio NumazakiFriend
Messages: 5
Registered: July 2009
Junior Member
Hi Simon, first of all, thank you for your help

I've tested what you told and it worked.

But now I have another issue.

My service interface and its implementation is in a separete bundle.

In this case, what really matter is just its implementation, not the
interface itself.

How do I workaround this?

My idea is to have a service interface bundle and many service
implementation bundles for that set of interfaces, doing this, I can have
multiple implementations that can be replaced without code change. I'll
have just one implementation per solution but it can be switched easilly.

To make it possible, I will register bundle/service implementation on its
activation class, referencing by interface name (in another bundle).

Is this a good idea?

Thanks!
Re: Service Activation (Bundle-ActivationPolicy: lazy) [message #127143 is a reply to message #127093] Fri, 06 March 2009 18:44 Go to previous messageGo to next message
Simon Kaegi is currently offline Simon KaegiFriend
Messages: 381
Registered: July 2009
Senior Member
> To make it possible, I will register bundle/service implementation on its
> activation class, referencing by interface name (in another bundle).
>
> Is this a good idea?
That sounds fine however in that case you shouldn't bother with a lazy
bundle-activation policy and just ensure that your bundles are properly
started. Another approach worth looking at is to use Declarative Services.

"Emilio Numazaki" <mediasonic.l@gmail.com> wrote in message
news:5da98ede646ea6bd18944e5853986c56$1@www.eclipse.org...
> Hi Simon, first of all, thank you for your help
>
> I've tested what you told and it worked.
>
> But now I have another issue.
>
> My service interface and its implementation is in a separete bundle.
>
> In this case, what really matter is just its implementation, not the
> interface itself.
>
> How do I workaround this?
>
> My idea is to have a service interface bundle and many service
> implementation bundles for that set of interfaces, doing this, I can have
> multiple implementations that can be replaced without code change. I'll
> have just one implementation per solution but it can be switched easilly.
>
> To make it possible, I will register bundle/service implementation on its
> activation class, referencing by interface name (in another bundle).
>
> Is this a good idea?
>
> Thanks!
>
>
>
Re: Service Activation (Bundle-ActivationPolicy: lazy) [message #127454 is a reply to message #127143] Thu, 12 March 2009 14:29 Go to previous messageGo to next message
Emilio Numazaki is currently offline Emilio NumazakiFriend
Messages: 5
Registered: July 2009
Junior Member
Hi Simon,

I was trying to use DS but there is something wrong with my tests.

Let me try to explain what do I have and what is happening.

I have a bundle that provides a service called "sample.service", this
bundle has an interface (sample.ISample) and its implementation class
(SampleImpl) which is the service itself. In this bundle, I have also a
directory OSGI-INF with configuration xml, called sample.xml. This
configuration xml is referenced in MANIFEST.MF.

OSGI-INF/sample.xml:
********************

<?xml version="1.0"?>
<component name="sample">
<implementation class="sample.SampleImpl"/>
<service>
<provide interface="sample.ISample"/>
</service>
</component>

META-INF/MANIFEST.MF:
*********************

Service-Component: OSGI-INF/sample.xml
**************************************

In order to use this bundle (bundle client), I have a RCP application
called "sample.rcp" with a view (ViewPart), it has also a directory
OSGI-INF with sample-rcp.xml configuration file and a reference on
MANIFEST.MF.

OSGI-INF/sample-rcp.xml:
************************

<?xml version="1.0"?>
<component name="sample-rcp">
<implementation class="sample.SampleView"/>
<reference name="sample"
interface="sample.ISample"
bind="setService"
unbind="unsetService"
cardinality="1..1"
policy="dynamic"/>

</component>

META-INF/MANIFEST.MF:
*********************

Service-Component: OSGI-INF/sample-rcp.xml

SampleView.java
***************

(...)
public void setService(ISample service) {
System.out.println("Setting service");
this.service = service;
}

public void unserService(ISample service) {
System.out.println("Unsetting service");
this.service = null;
}
(...)

The problem is that methods setService and unsetService from
SampleView.java is not being executed. I wrote some tracing code on
Activator.start() class from bundle "sample" on class "sample.SampleImpl"
to ensure required bundles are being started, and they are started already.

Do you know why set and unset methods from RCP bundle is not being
executed?

Thank you,
Re: Service Activation (Bundle-ActivationPolicy: lazy) [message #127535 is a reply to message #127454] Fri, 13 March 2009 12:35 Go to previous message
Emilio Numazaki is currently offline Emilio NumazakiFriend
Messages: 5
Registered: July 2009
Junior Member
Oh, I found the problem.

Declarative Service bundle must be started before everything, so I've
changed config.ini to make it possible.

Now setter method is being called but injected service is not available
for my ViewPart.

I added some logs into ViewPart code and realized that it is being
instantiated at least twice, what makes injected service invalid in second
instance.

Do you know what is the best way to inject services into ViewPart through
DS?
Previous Topic:Annotation gets lost when switch from Junit testing to OSGI (Eclipse application)?
Next Topic:Virtual Host - Equinox - Jetty
Goto Forum:
  


Current Time: Tue Mar 19 09:54:51 GMT 2024

Powered by FUDForum. Page generated in 0.01551 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top