1

プロパティのワイルドカードを使用して、OSGI サービス レジストリからサービスを検索できることは知っています。この質問は、それを逆に行うことに関するものです。

基本的に、次のようなサービスを登録します。

Map<String, String. prop = new HashMap<String, String>();
prop.put("name", "europe-*"); // this is the point - the service is registered with property containing wildcard 
context.registerService(IService.class.getName(), new ContinentServiceEuropeImpl(), prop);

次に、次のように、このプロパティの具体的な値を使用してこのサービスを検索します。

ServiceTracker primaryTracker = new ServiceTracker(bundleContext, "(&(objectClass=<IService class name here>)(name=europe-spain))", null);

サービス登録プロパティはワイルドカードと見なされないため、これはサービスを見つけられません。つまり、特に(name=europe-*)- を要求した場合にのみサービスを見つけることができます (* リテラルを検索するときに * をエスケープする必要があるかどうかはわかりません)。

これとは対照的に - 通常は逆です - サービスを具体的なプロパティ値で登録します。つまり(name=europe-spain)、それを使用して検索します(name=europe-*)

4

1 に答える 1