You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mark van Cuijk <ma...@van-cuijk.nl> on 2012/10/20 23:34:40 UTC

Service properties on aspect services in DM

Hi,

I've been playing a bit with aspect services using the DependencyManager and I've found some behavior that doesn't match my expectations. So either my expectations are wrong or I stumbled upon a bug...

Given an empty interface example.ExampleService, an empty implementation class example.ExampleServiceImpl and the Activator included below, would expect the aspect with ranking 20 to have property=aspect, but it actually has property=original, as shown in the Gogo Shell output included below the Activator source.

What is the intended behavior in this situation?

Regards,
Mark

public class Activator extends DependencyActivatorBase {

  @Override
  public void init(BundleContext context, DependencyManager manager) throws Exception {
    manager.add(createComponent()
        .setInterface(ExampleService.class.getName(), new Properties() {{
          put("property", "original");
        }})
        .setImplementation(ExampleServiceImpl.class));

    manager.add(createAspectService(ExampleService.class, null, 10)
        .setServiceProperties(new Properties() {{
          put("property", "aspect");
        }})
        .setImplementation(ExampleServiceImpl.class));

    manager.add(createAspectService(ExampleService.class, null, 20)
        .setImplementation(ExampleServiceImpl.class));
  }

  @Override
  public void destroy(BundleContext context, DependencyManager manager) throws Exception {
  }

}

[8] AspectExample
  example.ExampleService(property=original) registered
  org.apache.felix.dm.impl.AspectServiceImpl$AspectImpl@6087e704 registered
    example.ExampleService (!(org.apache.felix.dependencymanager.aspect=*)) service optional available
  example.ExampleService(service.ranking=10,property=aspect,org.apache.felix.dependencymanager.aspect=19) registered
    example.ExampleService (&(|(!(service.ranking=*))(service.ranking<=9))(|(service.id=19)(org.apache.felix.dependencymanager.aspect=19))) service required available
  org.apache.felix.dm.impl.AspectServiceImpl$AspectImpl@7a4fe91e registered
    example.ExampleService (!(org.apache.felix.dependencymanager.aspect=*)) service optional available
  example.ExampleService(service.ranking=20,property=original,org.apache.felix.dependencymanager.aspect=19) registered
    example.ExampleService (&(|(!(service.ranking=*))(service.ranking<=19))(|(service.id=19)(org.apache.felix.dependencymanager.aspect=19))) service required available


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


Re: Service properties on aspect services in DM

Posted by Marcel Offermans <ma...@luminis.nl>.
Hello Mark,

On Oct 22, 2012, at 23:42 PM, Mark van Cuijk <ma...@van-cuijk.nl> wrote:

> On Oct 21, 2012, at 23:08 , Marcel Offermans wrote:
> 
>> Out of curiosity, did you want to exploit the behavior you expected? In other words, do you have a use case for it?
> 
> I was indeed working on something and wanted to try whether aspects services would fit for this use case.
> 
> Basically I defined an interface for a service to retrieve records from a remote system. Multiple implementation may be registered in a whiteboard style. Some external systems don't supply values for all fields of a record, so I used service properties to specify which information is available in the retrieved records.
> 
> Some fields can be deduced from other fields. For example, I have a service that is able to map an account ID from the remote system to the account ID in the internal system. My experiment was to create an aspect service that consumes the original retriever, wraps the records, such that internal account IDs are available and could therefore republish the service with a new set of properties. I also made another aspect service this way to deduce the value of an enum field using information from other fields.

I'm not entirely sure why you'd want to use service properties to describe the fields that a record has. My first instinct would be to have a "getAvailableFields()" method on the Record service. That would then also solve your problem, since then the method invocations for the two aspects would be nicely chained.

> Things started to fall apart when I chained those two aspect services. In short, I expected to find a service when filtering on something like (&(accountType=INTERNAL)(directionType=*)), both of which were added / overridden by one of the aspect services.

Aspects were designed to provide services that are identical to the "original" service they are an aspect of, so your use case is slightly outside of their intended use. You could also take a look at Adapters, who are designed to adapt a service A into a service B, but those don't necessarily chain, so if you make an A that adapts on B and B that adapts on C and you take away B, you will break the chain. So you're back at my first suggestion.

> Anyway, I learned that using aspect services for an interface that is assumed to be used whiteboard style complicates things a lot. I'm already working out the solution I was about to use if I didn't want to try out using aspect services and I just wanted to check on the intended behavior ;-)

Well, if you use DM to create your whiteboard listeners, you will find that they "magically" understand aspects, so if you have services S1 and S2, and an aspect on all S'es, you end up with A1 and A2 (and the original S1 and S2 will be hidden from your listener, only to reappear when the aspects go away).

Greetings, Marcel


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


Re: Service properties on aspect services in DM

Posted by Mark van Cuijk <ma...@van-cuijk.nl>.
Hi Marcel,

On Oct 21, 2012, at 23:08 , Marcel Offermans wrote:

> Hello Mark,
> 
> Out of curiosity, did you want to exploit the behavior you expected? In other words, do you have a use case for it?

I was indeed working on something and wanted to try whether aspects services would fit for this use case.

Basically I defined an interface for a service to retrieve records from a remote system. Multiple implementation may be registered in a whiteboard style. Some external systems don't supply values for all fields of a record, so I used service properties to specify which information is available in the retrieved records.

Some fields can be deduced from other fields. For example, I have a service that is able to map an account ID from the remote system to the account ID in the internal system. My experiment was to create an aspect service that consumes the original retriever, wraps the records, such that internal account IDs are available and could therefore republish the service with a new set of properties. I also made another aspect service this way to deduce the value of an enum field using information from other fields.

Things started to fall apart when I chained those two aspect services. In short, I expected to find a service when filtering on something like (&(accountType=INTERNAL)(directionType=*)), both of which were added / overridden by one of the aspect services.

Anyway, I learned that using aspect services for an interface that is assumed to be used whiteboard style complicates things a lot. I'm already working out the solution I was about to use if I didn't want to try out using aspect services and I just wanted to check on the intended behavior ;-)

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


Re: Service properties on aspect services in DM

Posted by Marcel Offermans <ma...@luminis.nl>.
Hello Mark,

On Oct 20, 2012, at 23:34 PM, Mark van Cuijk <ma...@van-cuijk.nl> wrote:

> I've been playing a bit with aspect services using the DependencyManager and I've found some behavior that doesn't match my expectations. So either my expectations are wrong or I stumbled upon a bug...
> 
> Given an empty interface example.ExampleService, an empty implementation class example.ExampleServiceImpl and the Activator included below, would expect the aspect with ranking 20 to have property=aspect, but it actually has property=original, as shown in the Gogo Shell output included below the Activator source.
> 
> What is the intended behavior in this situation?

The intended behavior is that aspects inherit the service properties of the original service they are an aspect of.

Your example has an original service and two aspects on top of that, one with ranking 10, another with ranking 20.

The one with ranking 10 adds (or rather overwrites) a property called "property", giving it the value "aspect". So that value will overwrite the original value of "original".

The one with ranking 20 does not add any properties, and therefore it will inherit the ones from the original service. This probably was not what you expected, judging from your question. You expected it to inherit the properties of the aspect with ranking 10.

Out of curiosity, did you want to exploit the behavior you expected? In other words, do you have a use case for it?

> public class Activator extends DependencyActivatorBase {
> 
>  @Override
>  public void init(BundleContext context, DependencyManager manager) throws Exception {
>    manager.add(createComponent()
>        .setInterface(ExampleService.class.getName(), new Properties() {{
>          put("property", "original");
>        }})
>        .setImplementation(ExampleServiceImpl.class));
> 
>    manager.add(createAspectService(ExampleService.class, null, 10)
>        .setServiceProperties(new Properties() {{
>          put("property", "aspect");
>        }})
>        .setImplementation(ExampleServiceImpl.class));
> 
>    manager.add(createAspectService(ExampleService.class, null, 20)
>        .setImplementation(ExampleServiceImpl.class));
>  }
> 
>  @Override
>  public void destroy(BundleContext context, DependencyManager manager) throws Exception {
>  }
> 
> }
> 
> [8] AspectExample
>  example.ExampleService(property=original) registered
>  org.apache.felix.dm.impl.AspectServiceImpl$AspectImpl@6087e704 registered
>    example.ExampleService (!(org.apache.felix.dependencymanager.aspect=*)) service optional available
>  example.ExampleService(service.ranking=10,property=aspect,org.apache.felix.dependencymanager.aspect=19) registered
>    example.ExampleService (&(|(!(service.ranking=*))(service.ranking<=9))(|(service.id=19)(org.apache.felix.dependencymanager.aspect=19))) service required available
>  org.apache.felix.dm.impl.AspectServiceImpl$AspectImpl@7a4fe91e registered
>    example.ExampleService (!(org.apache.felix.dependencymanager.aspect=*)) service optional available
>  example.ExampleService(service.ranking=20,property=original,org.apache.felix.dependencymanager.aspect=19) registered
>    example.ExampleService (&(|(!(service.ranking=*))(service.ranking<=19))(|(service.id=19)(org.apache.felix.dependencymanager.aspect=19))) service required available


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