公開された(宣言型)サービスを使用してOSGiバンドルを作成しました。アクティベートが呼び出されたときに、サービスを提供できないなどの問題があることに気付いた場合は、サービスが公開されないようにする必要があります。現時点では、活性化関数は次のようになっています。
public void activate(ComponentContext context, Map<String, Object> properties) {
pid = (String) properties.get(Constants.SERVICE_PID);
try {
...
}
catch(Exception e) {
context.disableComponent(pid);
}
}
もう1つの方法は、次のように例外をラップ/伝播する(または、場合によっては新しい例外をスローする)ことです。
public void activate(ComponentContext context, Map<String, Object> properties) {
try {
...
}
catch(Exception e) {
throw new ComponentException("Some reason");
}
}
OSGi Service Platform Service Compendiumの宣言型サービスのセクションで指定されている正しい動作が見つかりませんが、何かが足りない可能性があります