1

Eclipse Equinox OSGi 環境で Apache Felix Service Component Runtime (SCR) を使用しています。

org.example.Producer次のようなインターフェイスを実装する宣言されたコンポーネントがいくつかあります。

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ProducerA">
    <implementation class="org.example.ProducerA"/>
    <service>
        <provide interface="org.example.Producer"/>
    </service>
</scr:component>

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ProducerB">
    <implementation class="org.example.ProducerB"/>
    <service>
        <provide interface="org.example.Producer"/>
    </service>
</scr:component>

org.example.Producerここで、別のコンポーネントで、インターフェイスを動的に実装するすべてのコンポーネントを参照したいと思います。

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ConsumerA">
    <implementation class="org.example.ConsumerA"/>
    <reference bind="bindProducer" cardinality="0..n" interface="org.example.Producer" policy="dynamic" unbind="unbindProducer"/>
    <service>
        <provide interface="org.example.Consumer"/>
    </service>
</scr:component>

しかし、これは実行時にエラーになります。SCR の検索フィルターにコンポーネント名が含まれているようです。

!ENTRY org.eclipse.equinox.ds 1 0 2015-06-22 11:31:31.781
!MESSAGE Could not bind a reference of component org.example.ConsumerA. The reference is: Reference[name = org.example.Producer, interface = org.example.Producer, policy = dynamic, cardinality = 0..n, target = null, bind = bindProducer, unbind = unbindProducer]

エラー メッセージでわかるように、名前が のコンポーネントを明示的に検索していますorg.example.Producer。ただし、上記のコンポーネントにはその名前 ( org.example.ProducerAorg.example.ProducerB) はありません。

問題は、名前を無視して特定のインターフェイスの実装を提供するコンポーネントを動的に参照するにはどうすればよいかということです。

4

1 に答える 1