You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Alexander Tumin <ia...@eientei.org> on 2013/02/12 20:04:11 UTC

[iPOJO] Publishing an OSGi service, annotated with iPOJO's @Component and @Provides after manual instantiating

Hello, i have a felix OSGi system and iPOJO bundles in it, managing 
service dependencies for all other bundles.

And i have three types of public services (interfaces) in this system:

- Subscriber        -- represents a participant in system's messaging.
- ProtocolInstance  -- represents a connection via specific protocol to 
a specific server
- ProtocolManager   -- (Singletone, Factory?) manages (creates and 
pre-configures) ProtocolInstance`s.

And also i have a single instance for whole system of:
- ConnectionManager -- which listens for ProtocolManager`s publications 
and asks them for appropriate ProtocolInstance`s when time and 
conditions are right.

Public services above are implemented and annotated in the following 
way:

--->3---

@Provides
@Instantiate
@Component
ConnectionManager    implements Subscriber

@Provides
@Instantiate
@Component
ProtocolManagerImpl  implements ProtocolManager

@Provides
@Component
ProtocolInstanceImpl implements ProtocolInstance, Subscriber

--->3---

in that way, i wish the following actions to happen:
- Some authorized bundle asks a ConnectionManager to perform a 
connection to server X via protocol Y
- ConnectionManager looks up ProtocolManager service in it's internal 
list of published ProtocolManager`s for manager of protocol Y 
(ProtocolManagerYImpl instance) and if finds it - asks this manager to 
create a connection to server X
- Asked ProtocolManagerYImpl creates a ProtocolInstanceYImpl and 
returns it to ConnectionManager, so he can connect() or disconnect() 
this instance

The problem i faced is lying on the last step. I could create an 
apropriate ProtocolInstance, but it won't be published as OSGi service 
despite it's iPOJO annotations upon mere `new 
ProtocolInstanceYImpl(argsSpecifyingServerXConnectionData);`.

But it is not like nothing happens and regular ProtocolInstanceYImpl 
instance is created - it's, as far as i understood by poking debugger, 
gets augmented with bunch of fields with underscores in names.
Also, this fields disappear when i remove iPOJO annotations from this 
ProtocolInstanceYImpl class.

So, my question it: how do i integrate into iPOJO-fied system the 
object insttance i created by hand?
Or, if it is a wrong question, how do i create a regular 
(non-singletone) instance that way it will be integrated (published, 
binded, injected, etc) into the system?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] Publishing an OSGi service, annotated with iPOJO's @Component and @Provides after manual instantiating

Posted by Alexander Tumin <ia...@eientei.org>.
Many thanks, that worked just perfectly

On 2013-02-14 14:06, Guillaume Sauthier (OW2) wrote:
> Having a component class means that iPOJO is the sole lifecycle 
> controller.
> It will decide when (depending on the dependencies availability) the
> instance will be created (or not).
>
> So, either you have to make ProtocolInstanceImpl not a component 
> anymore
> (you'll gain the lifecycle control), but you'll loose iPOJO's 
> sweetness
> (services injection, configuration, ....).
>
> Or you also can use iPOJO's Factory services.
> Just @Requires a Factory instance:
> @Requires(from="<your-component-name>") Factory factory;
> And then createComponentInstance(giving configuration properties).
>
> --G

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] Publishing an OSGi service, annotated with iPOJO's @Component and @Provides after manual instantiating

Posted by "Guillaume Sauthier (OW2)" <gu...@ow2.org>.
Having a component class means that iPOJO is the sole lifecycle controller.
It will decide when (depending on the dependencies availability) the
instance will be created (or not).

So, either you have to make ProtocolInstanceImpl not a component anymore
(you'll gain the lifecycle control), but you'll loose iPOJO's sweetness
(services injection, configuration, ....).

Or you also can use iPOJO's Factory services.
Just @Requires a Factory instance:
@Requires(from="<your-component-name>") Factory factory;
And then createComponentInstance(giving configuration properties).

--G


2013/2/12 Alexander Tumin <ia...@eientei.org>

> Hello, i have a felix OSGi system and iPOJO bundles in it, managing
> service dependencies for all other bundles.
>
> And i have three types of public services (interfaces) in this system:
>
> - Subscriber        -- represents a participant in system's messaging.
> - ProtocolInstance  -- represents a connection via specific protocol to a
> specific server
> - ProtocolManager   -- (Singletone, Factory?) manages (creates and
> pre-configures) ProtocolInstance`s.
>
> And also i have a single instance for whole system of:
> - ConnectionManager -- which listens for ProtocolManager`s publications
> and asks them for appropriate ProtocolInstance`s when time and conditions
> are right.
>
> Public services above are implemented and annotated in the following way:
>
> --->3---
>
> @Provides
> @Instantiate
> @Component
> ConnectionManager    implements Subscriber
>
> @Provides
> @Instantiate
> @Component
> ProtocolManagerImpl  implements ProtocolManager
>
> @Provides
> @Component
> ProtocolInstanceImpl implements ProtocolInstance, Subscriber
>
> --->3---
>
> in that way, i wish the following actions to happen:
> - Some authorized bundle asks a ConnectionManager to perform a connection
> to server X via protocol Y
> - ConnectionManager looks up ProtocolManager service in it's internal list
> of published ProtocolManager`s for manager of protocol Y
> (ProtocolManagerYImpl instance) and if finds it - asks this manager to
> create a connection to server X
> - Asked ProtocolManagerYImpl creates a ProtocolInstanceYImpl and returns
> it to ConnectionManager, so he can connect() or disconnect() this instance
>
> The problem i faced is lying on the last step. I could create an
> apropriate ProtocolInstance, but it won't be published as OSGi service
> despite it's iPOJO annotations upon mere `new ProtocolInstanceYImpl(**
> argsSpecifyingServerXConnectio**nData);`.
>
> But it is not like nothing happens and regular ProtocolInstanceYImpl
> instance is created - it's, as far as i understood by poking debugger, gets
> augmented with bunch of fields with underscores in names.
> Also, this fields disappear when i remove iPOJO annotations from this
> ProtocolInstanceYImpl class.
>
> So, my question it: how do i integrate into iPOJO-fied system the object
> insttance i created by hand?
> Or, if it is a wrong question, how do i create a regular (non-singletone)
> instance that way it will be integrated (published, binded, injected, etc)
> into the system?
>
> Thanks.
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
> For additional commands, e-mail: users-help@felix.apache.org
>
>