There are a number of options to consider:

1. If the Network and Login components are in the same bundle you could 
make the Login component initially disabled.  Then, when the Network 
component is connected it could enable the Login component.  Likewise, 
when the Network component loses its connection it could disable the Login 
connection.  Of course the Login component would still depend upon a 
service provided by the Network component.

2. You could make the Network component a "factory component" that 
manufactures a new Network component when a network connection is 
available. Likewise, the factory would dispose of the Network components 
it creates as their connections are no longer available.

3. Have your Network component be an immediate component that monitors the 
available connections and registers OSGi services "by hand" using the OSGi 
service APIs. This option is probably only practical if the Network 
component does not depend upon any other services, otherwise you're going 
to have to handle their availability too, which is what DS does best.

I hope this helps.  If you need further help, please post again to the 
mailing list. And please let us know what you decided to do.

Simon



From:
Luciana Alvite <[email protected]>
To:
[email protected]
Date:
09/25/2009 03:35 PM
Subject:
[osgi-dev] Activate component only after another component's state      is 
set
Sent by:
[email protected]



Hello dear fellow OSGi devs,

I have the following simplified scenario in my Declarative Services based 
project:

2 Components: Network and Login
Login depends on 1..1 Network component. Network takes care of connecting 
and disconnecting from a given network.

I would like to make the Login component dependency on Network satisfied 
only when the Network is actually connected, meaning the component would 
only be activated after the "network.connect()" method is successfully 
executed.

Approaches I have tried:
 - ConfigAdmin > Setting a property "isConnected" for the Network 
component using the ConfigAdmin when the "connect" method is successfully 
executed
Result: Does not work, since changing the properties will require a 
reactivation of the Network component, therefore recreating the component 
and losing the connection.

- Events > Make login implement EventHandler and listen to Network events. 
When event is "connected", react accordingly. the problem here is that the 
component must be enabled to be able to actually receive events. and this 
goes against the goal of only activating the component AFTER the network 
is connected..

I have tried google, read the specs several times but could not yet think 
of any suitable implementation , any ideas of how I could solve this?

Thanks in advance for any help or pointers!

-- 
Best Regards

Luciana Alvite _______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to