プライマリ・コンテンツに移動
Oracle® Fusion Middleware Oracle Event Processingのカスタマイズ
12c リリース(12.1.3)
E57535-04
目次へ移動
目次

前
前へ
次
次へ

3 アダプタおよびイベントBeanファクトリ

アダプタまたはイベントBeanファクトリ・クラスを実装して構成することで、複数のEPNで単一のカスタム・アダプタまたはイベントBean実装を使用できます。このファクトリ・クラスは、アダプタまたはイベントBeanオブジェクトを、その要求元Oracle Event Processingアプリケーションに対してインスタンス化します。

ここで説明しているAPIの詳細は、Oracle Event Processing Java APIリファレンスを参照してください。

この章の内容は次のとおりです。

3.1 アダプタ・ファクトリの作成

  1. アダプタ・クラスでは、アダプタがファクトリで返されるよう、com.bea.wlevs.ede.api.Adapterインタフェースを実装します。

    これはマーカー・インタフェースなので、メソッドは実装されません。

    public class BusStopAdapter implements Adapter, StreamSource {
        // Adapter implementation code.
    }
    
  2. com.bea.wlevs.ede.api.AdapterFactoryインタフェースを実装するアダプタ・ファクトリ・クラスを作成します。

    createメソッドは、カスタム・アダプタのインスタンスを作成して返します。

    import com.oracle.cep.sample.spatial.BusStopAdapter;
    import com.bea.wlevs.ede.api.AdapterFactory;
    
    public class BusStopAdapterFactory implements AdapterFactory {
      public BusStopAdapterFactory() {}
      public synchronized BusStopAdapter create() throws IllegalArgumentException {
      // Your code might have a particular way to create the instance.
         return new BusStopAdapter();
      }
    }
    
  3. アセンブリ・ファイルで、wlevs:factory要素を使用してファクトリ・クラスを登録します。

    <wlevs:factory provider-name="busStopAdapterProvider" 
      class="com.oracle.cep.sample.spatial.BusStopAdapterFactory"/>
    
  4. osgi:service要素を使用して、アセンブリ・ファイルにOSGiサービスとしてファクトリを登録します。

    OSGiサービス・レジストリのスコープはOracle Event Processing全体です。特定のサーバーにデプロイされた複数のアプリケーションが同じアダプタ・ファクトリを使用する場合は、ファクトリをOSGiサービスとして1回登録します。

    1. エントリを追加して、サービスをcom.bea.wlevs.ede.api.AdapterFactoryインタフェースの実装として登録します。key属性にtypeを指定し、このアダプタ・プロバイダを参照する名前を使用して、プロパティを指定します。

    2. ネストした標準のSpring bean要素を追加して、Springアプリケーション・コンテキストで特定のアダプタ・クラスを登録します。

    <osgi:service interface="com.bea.wlevs.ede.api.AdapterFactory">
      <osgi:service-properties>
        <entry key="type" value="busStopAdapterProvider"</entry>
      </osgi:service-properties>
      <bean class="com.oracle.cep.sample.spatial.BusStopAdapterFactory" />
    </osgi:service>
    
  5. 次の例に示すとおり、(アダプタをクラス名で指定するのではなく)構成したファクトリをプロバイダとして指定し、アダプタのインスタンスを使用するアプリケーションでアダプタを構成します。

    <wlevs:adapter id="BusStopAdapter"
      provider="busStopAdapterProvider">
      // ...
    </wlevs:adapter>

3.2 イベントBeanファクトリの作成

  1. イベントBeanクラスでは、Beanがファクトリで返されるよう、com.bea.wlevs.ede.api.EventBeanインタフェースを実装します。

    これはマーカー・インタフェースなので、メソッドは実装されません。

    public class TradeListener implements EventBean, StreamSink {
      // Bean implementation code.
    }
    
  2. com.bea.wlevs.ede.api.EventBeanFactoryインタフェースを実装するイベントBeanクラスを作成します。

    createメソッドは、イベントBeanのインスタンスを作成して返します。

    import com.oracle.cep.example.tradereport.TradeListener;
    import com.bea.wlevs.ede.api.EventBeanFactory;
    
    public class TradeListenerFactory implements EventBeanFactory {
      public TradeListenerFactory() { }
      public synchronized TradeListener create() throws IllegalArgumentException {
      // Your code might have a particular way to create the instance.
        return new TradeListener();
      }
    }
    
  3. アセンブリ・ファイルで、wlevs:factory要素を使用してファクトリ・クラスを登録します。

    <wlevs:factory provider-name="tradeListenerProvider" 
      class="com.oracle.cep.example.tradereport.TradeListenerFactory"/>
  4. osgi:service要素を使用して、アセンブリ・ファイルにOSGiサービスとしてファクトリを登録します。

    OSGiサービス・レジストリのスコープはOracle Event Processing全体です。特定のサーバーにデプロイされた複数のアプリケーションが同じアダプタ・ファクトリを使用する場合は、ファクトリをOSGiサービスとして1回登録します。

    1. エントリを追加して、サービスを com.bea.wlevs.ede.api.EventBeanFactoryインタフェースの実装として登録します。key属性にtypeを指定し、このアダプタ・プロバイダを参照する名前を使用して、プロパティを指定します。

    2. ネストした標準のSpring bean要素を追加して、Springアプリケーション・コンテキストで特定のアダプタ・クラスを登録します。

    <osgi:service interface="com.bea.wlevs.ede.api.EventBeanFactory">
      <osgi:service-properties>
        <entry key="type" value="tradeListenerProvider"</entry>
        </osgi:service-properties>
      <bean class="com.oracle.cep.example.tradereport.TradeListenerFactory" />
    </osgi:service>
    
  5. 次の例に示すとおり、(Beanをクラス名で指定するのではなく)構成したイベントBeanファクトリをプロバイダとして指定し、イベントBeanのインスタンスを使用するアプリケーションでイベントBeanを構成します。

    <wlevs:event-bean id="TradeListenerBean" provider="tradeListenerProvider">