Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find Hook Service #622

Open
pnoltes opened this issue Aug 23, 2023 · 0 comments
Open

Find Hook Service #622

pnoltes opened this issue Aug 23, 2023 · 0 comments
Labels
component/framework Categorizes an issue or PR relevant to the framework. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@pnoltes
Copy link
Contributor

pnoltes commented Aug 23, 2023

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:

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:

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, 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.

@pnoltes pnoltes added kind/feature Categorizes issue or PR as related to a new feature. component/framework Categorizes an issue or PR relevant to the framework. labels Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/framework Categorizes an issue or PR relevant to the framework. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant