pnoltes opened a new issue, #622:
URL: https://github.com/apache/celix/issues/622

   # Find Hook Service
   
   Add support for the "Find Hook" service, enabling the filtering of services 
for users when necessary.
   
   # Background
   
   Snippet [Service Hook Service Specification of the OSGi 8 
spec](https://docs.osgi.org/specification/osgi.core/8.0.0/framework.servicehooks.html):
   
   > The OSGi framework has built-in support for the normal service primitives: 
publish, find, and bind. Despite their simplicity, these primitives are 
surprisingly powerful and have become quite popular. However, these primitives 
operate on information that is not completely visible to the bundles. For 
example, it is impossible to find out what services are being waited upon by 
other bundles. This information can be useful to provide a service just in time 
to that bundle. Additionally, it is also not possible to allow bundles 
functionality that interacts with the service engine. For example, a bundle 
could proxy another service but to do this transparently, it is required to 
hide the original service and offer the proxy only to a specific bundle. With 
the current primitives this is also not possible.
   
   > Therefore, this service hook specification provides a number of new 
mechanisms that closely interact with the service engine. These interactions 
are not intended for use by application bundles. The service primitives appear 
simple but require surprisingly complex code to make them appear simple to the 
bundle developer. Modifying the behavior of the service engine requires 
developers to closely follow the semantics of the OSGi service model and this 
is often hard, requiring a significant amount of code.
   
   > However, the service hooks provide a more symmetric model for service 
based programming that can act as a multiplier for the framework. The basic 
framework provides a powerful service engine and this specification allows a 
bundle to interact with this service engine 
   
   # Background Find Hook
   
   > The Find Hook is called when a target bundle searches the service registry 
with the getServiceReference or getServiceReferences methods. A registered Find 
Hook service gets a chance to inspect the returned set of service references 
and can optionally shrink the set of returned services. The order in which the 
find hooks are called is the reverse compareTo ordering of their Service 
References. That is, the service with the highest ranking number must be called 
first.
   
   # Implementations hints
   
   The specification notes that find hook callbacks are invoked when 
`getServiceReference`, `getServiceReferences`, or `getAllServiceReferences` are 
executed. For Apache Celix, this translate that all the `useService` calls, 
along with the outcomes of the `trackServices` calls should lead to find hook 
callback invocations. 
   
   The Java FindHook interface is as follows:
   
   The java FindHook interface is:
   ```java
   public interface FindHook {  
     void find​(BundleContext context, String name, String filter, boolean 
allServices, Collection<ServiceReference<?>> references);
   }
   ```
   
   Since, in Apache Celix, the service reference isn't a public API, an 
alternative to the references (inout) parameter must be used. Perhaps, in place 
of a Collection<ServiceReference>, a celix_array_t containing const 
celix_properties_t* entries might be suitable. Filtering out properties would 
then cause the corresponding service to be filtered out.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to