You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Bengt Rodehav <be...@rodehav.com> on 2013/12/09 16:20:47 UTC

iPojo: Default configuration and @Update

I have a iPojo component singleton defined as follows:

@Component(managedservice = "connect.fm.notifier", name =
"connect.fm.notifier", publicFactory = false)
@Provides(specifications = INotificationProvider.class)
@Instantiate
public class NotifierService implements INotifier, INotificationProvider {
...
  @Property(name = "defaultLogTypeId", mandatory = true)
  private String mDefaultLogTypeId;

  @Updated
  public void updated(Dictionary conf) {
    System.out.println("Updated");
    Enumeration en = conf.keys();
    while (en.hasMoreElements()) {
      Object key = en.nextElement();
      System.out.println("  " + key.toString() + " -> " + conf.get(key));
    }
  }

....

I have two questions regarding this:

a) When I have a mandatory property ("defaultLogTypeId" above) with no
default value, it seems like no component instance will be created. I feed
ConfigAdmin with a proper configuration using FileInstall but it seems that
it is "too late". If the default configuration was not valid then no
instance will be created regardless if I provide a correct installation
later on. Is this as designed or have I misunderstood this? I was expecting
the instance creation to be delayed until a correct configuration was
provided. Note that if I have a correct default configuration then the
instance will be created and it will be automatically reconfigured via
FileInstall.

b) The Dictionary passed into the updated() method always seem to reflect
the default configuration - not the current configuration. This looks like
a bug to me.

/Bengt

Re: iPojo: Default configuration and @Update

Posted by Bengt Rodehav <be...@rodehav.com>.
Created the following JIRA:

https://issues.apache.org/jira/browse/FELIX-4351

/Bengt


2013/12/9 Bengt Rodehav <be...@rodehav.com>

> OK. I do use managed service factories quite a lot but primarily when
> multiple instances must be supported. In this case it's a singleton but
> some properties do not have sensible default values. It seems then that,
> unless I use the factory pattern, all properties must either be optional or
> have default values. It seems kind of limiting.
>
> Will create a JIRA for the other issue.
>
> /Bengt
> Den 9 dec 2013 18:55 skrev "Clement Escoffier" <
> clement.escoffier@gmail.com>:
>
> Hi,
>>
>> On 9 déc. 2013, at 16:20, Bengt Rodehav <be...@rodehav.com> wrote:
>>
>> > I have a iPojo component singleton defined as follows:
>> >
>> > @Component(managedservice = "connect.fm.notifier", name =
>> > "connect.fm.notifier", publicFactory = false)
>> > @Provides(specifications = INotificationProvider.class)
>> > @Instantiate
>> > public class NotifierService implements INotifier,
>> INotificationProvider {
>> > ...
>> >  @Property(name = "defaultLogTypeId", mandatory = true)
>> >  private String mDefaultLogTypeId;
>> >
>> >  @Updated
>> >  public void updated(Dictionary conf) {
>> >    System.out.println("Updated");
>> >    Enumeration en = conf.keys();
>> >    while (en.hasMoreElements()) {
>> >      Object key = en.nextElement();
>> >      System.out.println("  " + key.toString() + " -> " + conf.get(key));
>> >    }
>> >  }
>> >
>> > ....
>> >
>> > I have two questions regarding this:
>> >
>> > a) When I have a mandatory property ("defaultLogTypeId" above) with no
>> > default value, it seems like no component instance will be created. I
>> feed
>> > ConfigAdmin with a proper configuration using FileInstall but it seems
>> that
>> > it is "too late". If the default configuration was not valid then no
>> > instance will be created regardless if I provide a correct installation
>> > later on. Is this as designed or have I misunderstood this? I was
>> expecting
>> > the instance creation to be delayed until a correct configuration was
>> > provided. Note that if I have a correct default configuration then the
>> > instance will be created and it will be automatically reconfigured via
>> > FileInstall.
>>
>> You should remove the @Instantiate and create a ManagedServiceFactory
>> configuration using the configuration admin.
>>
>> >
>> > b) The Dictionary passed into the updated() method always seem to
>> reflect
>> > the default configuration - not the current configuration. This looks
>> like
>> > a bug to me.
>> >
>>
>> Looks like it. Could you open an issue ?
>>
>> Regards,
>>
>> Clement
>>
>> > /Bengt
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>

Re: iPojo: Default configuration and @Update

Posted by Bengt Rodehav <be...@rodehav.com>.
OK. I do use managed service factories quite a lot but primarily when
multiple instances must be supported. In this case it's a singleton but
some properties do not have sensible default values. It seems then that,
unless I use the factory pattern, all properties must either be optional or
have default values. It seems kind of limiting.

Will create a JIRA for the other issue.

/Bengt
Den 9 dec 2013 18:55 skrev "Clement Escoffier" <clement.escoffier@gmail.com
>:

> Hi,
>
> On 9 déc. 2013, at 16:20, Bengt Rodehav <be...@rodehav.com> wrote:
>
> > I have a iPojo component singleton defined as follows:
> >
> > @Component(managedservice = "connect.fm.notifier", name =
> > "connect.fm.notifier", publicFactory = false)
> > @Provides(specifications = INotificationProvider.class)
> > @Instantiate
> > public class NotifierService implements INotifier, INotificationProvider
> {
> > ...
> >  @Property(name = "defaultLogTypeId", mandatory = true)
> >  private String mDefaultLogTypeId;
> >
> >  @Updated
> >  public void updated(Dictionary conf) {
> >    System.out.println("Updated");
> >    Enumeration en = conf.keys();
> >    while (en.hasMoreElements()) {
> >      Object key = en.nextElement();
> >      System.out.println("  " + key.toString() + " -> " + conf.get(key));
> >    }
> >  }
> >
> > ....
> >
> > I have two questions regarding this:
> >
> > a) When I have a mandatory property ("defaultLogTypeId" above) with no
> > default value, it seems like no component instance will be created. I
> feed
> > ConfigAdmin with a proper configuration using FileInstall but it seems
> that
> > it is "too late". If the default configuration was not valid then no
> > instance will be created regardless if I provide a correct installation
> > later on. Is this as designed or have I misunderstood this? I was
> expecting
> > the instance creation to be delayed until a correct configuration was
> > provided. Note that if I have a correct default configuration then the
> > instance will be created and it will be automatically reconfigured via
> > FileInstall.
>
> You should remove the @Instantiate and create a ManagedServiceFactory
> configuration using the configuration admin.
>
> >
> > b) The Dictionary passed into the updated() method always seem to reflect
> > the default configuration - not the current configuration. This looks
> like
> > a bug to me.
> >
>
> Looks like it. Could you open an issue ?
>
> Regards,
>
> Clement
>
> > /Bengt
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: iPojo: Default configuration and @Update

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

On 9 déc. 2013, at 16:20, Bengt Rodehav <be...@rodehav.com> wrote:

> I have a iPojo component singleton defined as follows:
> 
> @Component(managedservice = "connect.fm.notifier", name =
> "connect.fm.notifier", publicFactory = false)
> @Provides(specifications = INotificationProvider.class)
> @Instantiate
> public class NotifierService implements INotifier, INotificationProvider {
> ...
>  @Property(name = "defaultLogTypeId", mandatory = true)
>  private String mDefaultLogTypeId;
> 
>  @Updated
>  public void updated(Dictionary conf) {
>    System.out.println("Updated");
>    Enumeration en = conf.keys();
>    while (en.hasMoreElements()) {
>      Object key = en.nextElement();
>      System.out.println("  " + key.toString() + " -> " + conf.get(key));
>    }
>  }
> 
> ....
> 
> I have two questions regarding this:
> 
> a) When I have a mandatory property ("defaultLogTypeId" above) with no
> default value, it seems like no component instance will be created. I feed
> ConfigAdmin with a proper configuration using FileInstall but it seems that
> it is "too late". If the default configuration was not valid then no
> instance will be created regardless if I provide a correct installation
> later on. Is this as designed or have I misunderstood this? I was expecting
> the instance creation to be delayed until a correct configuration was
> provided. Note that if I have a correct default configuration then the
> instance will be created and it will be automatically reconfigured via
> FileInstall.

You should remove the @Instantiate and create a ManagedServiceFactory configuration using the configuration admin.

> 
> b) The Dictionary passed into the updated() method always seem to reflect
> the default configuration - not the current configuration. This looks like
> a bug to me.
> 

Looks like it. Could you open an issue ?

Regards,

Clement

> /Bengt


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