Hi,
On 12.10.2009, at 18:36, Vlatko Davidovski wrote:
Clement,
I basically want to have one bundle called the aparat-configurator -
a centralized bundle for management of the different service
configuration.
It is basically a proxy for the ConfigurationAdmin with the
difference that it has 2 methods:
getCustomProperties(String pid) - gets the properties for a
registered service from the configuration admin
gedDefaultProperties(String pid) - gets safe properties (can be used
in case something goes wrong with the first one)
Therefore, when I have:
@Component(architecture = true, immediate = true, propagation =
true, managedservice =
"ch
.ethz.inf.vs.aparat.registry.osgi.services.DeviceRegistryServiceImpl")
@Provides
public class DeviceRegistryServiceImpl implements
DeviceRegistryService {
@Requires
private ConfiguratorService configuratorService;
@ServiceProperty
private String databasePath;
@Validate
public void start() {
Dictionary<String, String> properties =
configuratorService.getCustomProperties(managedservice);
databasePath = properties.get("databasePath");
try{
// Create db using custom properties
}
catch(Exception e) {
Dictionary<String, String> properties =
configuratorService.getDefaultProperties(managedservice);
databasePath = properties.get("databasePath");
// Create db using default properties
}
And I need access to the managedservice property programmatically.
Thanks fro these explanations. It is a very interesting use case.
Actually, the managed service is the only configuration parameter non
retrievable with 'architecture' !
I'm filling a new Jira issue to support that (Felix-1741).
For the time being, you can duplicate the name inside a configuration
property:
@Component // No more need to set the managed service here, it will be
set in the instance configuration
public class MyClass {
@Property(name="managed.service.pid")
String myManagedServicePID;
...
}
Then, in the instance declaration you can add the property
<instance component="...">
<property name="managed.service.pid" value="mymanagedservicepid"/>
</instance>
The managed service pid property will be used twice : 1) as the
managed service pid, 2) as property value (injected inside the
myManagedServicePID).
Regards,
Clement
On Oct 12, 2009, at 5:55 PM, Clement Escoffier wrote:
BTW,
if you just need to get access to your configuration,
just use the @Property annotation:
@Property
private String myProperty;
If the configuration admin contains a configuration for you, this
field will contain the value.
Regards,
clement
On 12.10.2009, at 17:51, Clement Escoffier wrote:
Hi,
On 12.10.2009, at 14:36, Vlatko Davidovski wrote:
Thanks Clement!
A small question.
I still cannot find how to get the managedservice parameter from
the architecture.getInstanceDescription()
Currently I have:
@Component(architecture=true, immediate=true, propagation = true,
managedservice
=
"ch
.ethz
.inf.vs.aparat.registry.osgi.services.DeviceRegistryServiceImpl")
@Provides
public class DeviceRegistryServiceImpl implements
DeviceRegistryService {
.......
@Requires
private Architecture architecture;
@Validate
public void start() {
......
// I need the managedservice value here
}
Can you explain me a little bit what's your architecture and goal ?
ManagedService is a service. If enabled, iPOJO registers this
service for you with the given PID, the instance.name and
factory.name properties.
So if you know the name of your instance or of your factory (be
care if you create several component instance), you just need a
service dependencies on the service.
However, you should never directly access to the ManagedService
which is a Configuration Admin service.
If you need to get a configuration:
- either you push it in the instance declaration:
<instance component="...">
<property name="p" value="v"/>
</instance>
- or you create a ManagedServiceFactory configuration (using your
component type name as ManagedServiceFactory PID.
If you just need to reconfigure yourself, then, you just use the
(direct) reconfigure method of the Factory service.
Regards,
Clement
On Oct 12, 2009, at 7:58 AM, Clement Escoffier wrote:
Hi,
On 12.10.2009, at 02:01, Vlatko Davidovski wrote:
Hi!
As I am new to iPojo, I have a couple of questions:
1. How to get the value of the annotated field managedservice
programmatically?
The Architecture service can give you such information. If not
disabled, every instance exposed an Architecture service
allowing you to get the InstanceDescription. Thanks to that
object you can check the current state of properties, provided
services, dependencies...
2. Does immediate attribute of service A mean that required
services (B & C) are monitored and as soon as they are
available, an instance of the service A is created?
Immediate means that, as soon as valid (i.e.e service
dependencies resolved), a POJO instance will be created. It will
not create a component instance, but it will create a component
implementation class object.
3. What is the difference between @Property and @ServiceProperty?
@ServiceProperty are properties published with the provided
services (if the instance publishes services).
@Property are internal properties which are not published with
the provided services.
4. What is the usage of the attributes architecture,
factory_method, public_factory of @Component?
- architecture allows you to disable the introspection service.
The introspection is enabled by default.
- factory_method allows you to use a static method of the class
to create the POJO object. In that case, iPOJO call this method
instead of the regular constructor when the creation of one
object is required.
- public_factory allows you to set if the component type factory
is public or not. Public factories (the default) are exposed as
services (Factory, and ManagedServiceFactory) and allows the
creation of component instances from others bundles (either
declared inside a metadata.xml, or with the API).
Regards,
Clement
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]