Annotation Type AspectService


@Retention(CLASS) @Target(TYPE) public @interface AspectService
Annotates an Aspect service. Aspects allow you to define an interceptor, or chain of interceptors for a service (to add features like caching or logging, etc ...). The dependency manager intercepts the original service, and allows you to execute some code before invoking the original service ... The aspect will be applied to any service that matches the specified interface and filter and will be registered with the same interface and properties as the original service, plus any extra properties you supply here. If you declare the original service as a member it will be injected.

For "add", "change", "remove" callbacks, the following method signatures are supported:


 (Component comp, ServiceReference ref, Service service)
 (Component comp, ServiceReference ref, Object service)
 (Component comp, ServiceReference ref)
 (Component comp, Service service)
 (Component comp, Object service)
 (Component comp)
 (Component comp, Map properties, Service service)
 (ServiceReference ref, Service service)
 (ServiceReference ref, Object service)
 (ServiceReference ref)
 (Service service)
 (Service service, Map propeerties)
 (Map properties, Service, service)
 (Service service, Dictionary properties)
 (Dictionary properties, Service service)
 (Object service)
 

For "swap" callbacks, the following method signatures are supported:


 (Service old, Service replace)
 (Object old, Object replace)
 (ServiceReference old, Service old, ServiceReference replace, Service replace)
 (ServiceReference old, Object old, ServiceReference replace, Object replace)
 (Component comp, Service old, Service replace)
 (Component comp, Object old, Object replace)
 (Component comp, ServiceReference old, Service old, ServiceReference replace, Service replace)
 (Component comp, ServiceReference old, Object old, ServiceReference replace, Object replace)
 (ServiceReference old, ServiceReference replace)
 (Component comp, ServiceReference old, ServiceReference replace)
 

Usage Examples

Here, the AspectService is registered into the OSGI registry each time an InterceptedService is found from the registry. The AspectService class intercepts the InterceptedService, and decorates its "doWork()" method. This aspect uses a rank with value "10", meaning that it will intercept some other eventual aspects with lower ranks. The Aspect also uses a service property (param=value), and include eventual service properties found from the InterceptedService:

 
 @AspectService(ranking=10))
 class AspectService implements InterceptedService {
     // The service we are intercepting (injected by reflection)
     volatile InterceptedService intercepted;
   
     public void doWork() {
        intercepted.doWork();
     }
 }
 
Author:
Felix Project Team
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    int
    Sets the ranking of this aspect.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The callback method to be invoked when the original service is available.
    The callback method to be invoked when the original service properties have changed.
    Sets the static method used to create the AspectService implementation instance.
    Sets the field name where to inject the original service.
    Sets the filter condition to use with the service interface this aspect is applying to.
    Deprecated.
    you can apply Property annotation directly on the component class.
    The callback method to invoke when the service is lost.
    The service scope for the service of this Component.
    Sets the service interface to apply the aspect to.
    name of the callback method to invoke on swap.
  • Element Details

    • service

      Class<?> service
      Sets the service interface to apply the aspect to. By default, the directly implemented interface is used.
      Returns:
      the service aspect
      Default:
      java.lang.Object.class
    • filter

      String filter
      Sets the filter condition to use with the service interface this aspect is applying to.
      Returns:
      the service aspect filter
      Default:
      ""
    • properties

      Property[] properties
      Deprecated.
      you can apply Property annotation directly on the component class.
      Sets Additional properties to use with the aspect service registration
      Returns:
      the aspect service properties.
      Default:
      {}
    • ranking

      int ranking
      Sets the ranking of this aspect. Since aspects are chained, the ranking defines the order in which they are chained. Chain ranking is implemented as a service ranking so service lookups automatically retrieve the top of the chain.
      Returns:
      the aspect service rank
    • field

      String field
      Sets the field name where to inject the original service. By default, the original service is injected in any attributes of the aspect implementation that are of the same type as the aspect interface.
      Returns:
      the field used to inject the original service
      Default:
      ""
    • added

      String added
      The callback method to be invoked when the original service is available. This attribute can't be mixed with the field attribute.
      Returns:
      the add callback
      Default:
      ""
    • changed

      String changed
      The callback method to be invoked when the original service properties have changed. When this attribute is used, then the added attribute must also be used.
      Returns:
      the changed callback
      Default:
      ""
    • removed

      String removed
      The callback method to invoke when the service is lost. When this attribute is used, then the added attribute must also be used.
      Returns:
      the remove callback
      Default:
      ""
    • swap

      String swap
      name of the callback method to invoke on swap.
      Returns:
      the swap callback
      Default:
      ""
    • factoryMethod

      String factoryMethod
      Sets the static method used to create the AspectService implementation instance. The default constructor of the annotated class is used. The factoryMethod can be used to provide a specific aspect implements, like a DynamicProxy.
      Returns:
      the aspect service factory method
      Default:
      ""
    • scope

      The service scope for the service of this Component.

      If not specified, the singleton service scope is used.

      Default:
      SINGLETON