0

私の iPOJO アプリケーションでは、サービスを 2 つのコンシューマーにバインドしようとしています。

消費者:

@Component(immediate = true)
@Instantiate(name = "com.example.consumerX")
@Provides
public class consumerX{
    @Requires(id="ms",optional=true)
    private MyService[] services;

    @Bind(id = "ms", aggregate = true, optional = true)
    public synchronized void register(MyService service) {
            System.out.println("service bind to consumer");
    }

    @Unbind(id = "ms")
    public synchronized void unregister(MyService service) {
            System.out.println("service unbind from consumer");
    }
}

サービス:

@Component(immediate = true)
@Instantiate(name = "com.example.serviceX")
@Provides(specifications = { MyService.class, MyServiceX.class})
public class MyServiceX{
    ...
}

consumerA、consumerB、および serviceA を開始すると、サービスは consumerA にのみバインドされます。consumerB と serviceA を開始すると、サービスは consumerB にバインドされます。

サービスを両方のコンシューマにバインドさせることは可能ですか? それに対する注釈はありますか?

ありがとう。

4

1 に答える 1

0

サービスが複数のコンシューマによって使用されることは間違いなく可能です。あなたのコードは見栄えが良いので、うまくいくはずです。

「インスタンス」コマンド (http://felix.apache.org/site/ipojo-arch-command.html) を使用して現在の状態を確認しようとしましたか?

于 2012-04-24T06:04:32.277 に答える