Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Aries managed-service-factory also manage properties?

I'm using Apache Aries 0.2 in Servicemix 4.3.1 and creating a cm:managed-service-factory. Creation of the services with .cfg files works fine (except for #ARIES-584), but the properties from the .cfg file do not get injected into the service object. They do get set properly in ConfigAdmin, just my bean setter methods never get called for the values in my config file.

I was thinking I should maybe use a cm:managed-properties or something like that nested inside my managed-service-factory, but that would require a separate pid, so doesn't seem right.

If I don't put the property tag in, then no value ever gets set. With the property tag, then just the default value gets set, but never the actual config file value.

I can't find any documentation for usage of the Aries CM subproject, except for blueprint-sample.xml, which doesn't show managed properties inside a managed service factory. I've really been trying to use Servicemix, but around every corner there is missing documentation, broken or missing features, or bugs that affect core functionality.

Both the spring and gemini documentation indicate that their managed-service-factory implementations should also function as managed-properties.


foo.xml:

<blueprint>
  <cm:managed-service-factory id="myfoo-msf" factory-pid="my.msf" interface="my.IFoo">
    <cm:managed-component class="my.Foo"> 
      <property name="name" value="default />
    </cm:managed-component>
  </cm:managed-service-factory>
</blueprint>

IFoo.java

package my;
public interface IFoo {
  public String getName();
  public void setName(String name);
}

Foo.java

package my;
public class Foo implements IFoo {
  private String name;
  public void setName(String name) {
    this.name = name;
    System.out.println("name set to: " + name);
  }
  public String getName() {
    return name;
  }
}

my.msf-1.cfg

name=name1

my.msf-2.cfg

name=name2

System.out

name set to default
name set to default

config:proplist

service.pid = my.msf.xxxxxxx-xx-xx-xxxxxxxxxxxxxxx
name = name1
service.factoryPid = my.msf

service.pid = my.msf.yyyyyyy-yy-yy-yyyyyyyyyyyyyyy
name = name2
service.factoryPid = my.msf
like image 815
John Ellinwood Avatar asked Oct 21 '11 15:10

John Ellinwood


1 Answers

I believe you have to add one extra line within your managed-component element.

<blueprint>
  <cm:managed-service-factory id="myfoo-msf" factory-pid="my.msf" interface="my.IFoo">
    <cm:managed-component class="my.Foo"> 
      <cm:managed-properties persistent-id="" update-strategy="container-managed"/>
      <property name="name" value="default />
    </cm:managed-component>
  </cm:managed-service-factory>
</blueprint>

The default value will indeed be overwritten whatever is in your cfg file. If it matters,the default property value setter will be invoked, followed by the same property setter with the value from the cfg.

In this case I have used container-managed for update strategy. But you could use component managed.

This seems kind of redundant to me and in poor taste. Why do I need to set another managed-properties within my bean with a blank persistent id when I have already done so above? Maybe there is a better way but this seems to work.

Also, there is no obvious way to affect the Service Properties that are advertised. For example, we might want to have a convention that any cfg properties that start with service:xxx would be passed through to the Service properties.

Update: The Apache Aries tests are pretty helpful. They can be found here http://aries.apache.org/downloads/currentrelease.html. In particular take a look at the one for configuration management, org.apache.aries.blueprint.cm . In the test folder it has some examples. It shows that in addition to the cm:managed-properties child element within the cm:managed-component shown above, there is also an option to have a cm:cm-properties element within the service-properties.

<service-properties>
    <entry key="key" value="foo3" />
    <cm:cm-properties persistent-id="" update="true"/>
</service-properties>
like image 74
Ed Ost Avatar answered Oct 04 '22 15:10

Ed Ost