2017-01-29 3 views
0

ストリームIには、InfoSphereをwithingカスタマイズされたJava演算子を使用する方法について、今しばらく探してきた私は必要なもののJava APIに圏のJava API内のJavaカスタム演算子を使用して

ストリーム以下のようにカスタマイズされたオペレータを書いた後..です。

public class Test extends AbstractOperator { 
private int i; 
private int num; 
@Override 
public synchronized void initialize(OperatorContext context) throws Exception { 
super.initialize(context); 
i = 0; .... 

私は以下のようにそれを使用したい....

 Topology topology = new Topology("toplogy_test"); 
     TStream<String> inDataFileName = ... 
//call the "Test" operator here 

答えて

0

次の手順でトポロジAPIからJavaオペレータ/ C++演算子を呼び出すことができます:

  1. のJavaオペレータのツールキット追加:

    SPL.addToolkit(トポロジー、新しいファイル( "/ホーム/ streamsadmin/myTkを"));

  2. SPLストリームに入力ストリームを変換します

    SPLStream splOutputStream = SPL.invokeOperator( "OperatorNamespace :: YourOperatorName"、splInputStream、rstringSchema、新しいHashMapの(:

    StreamSchema rstringSchema = Type.Factory.getStreamSchema("tuple<rstring rstring_attr_name>"); 
    
    SPLStream splInputStream = SPLStreams.convertStream(inDataFileName, new BiFunction<String, OutputTuple, OutputTuple>(){ 
    
        @Override 
        public OutputTuple apply(String input_string, OutputTuple output_rstring) { 
        output_rstring.setString("rstring_attr_name", input_string); 
        return output_rstring; 
        }}, rstringSchema); 
    
  3. はオペレーターを呼び出します));

あなたがここにこれについての詳細な情報を見つけることができます:あなたはストリームトポロジを書くためにトポロジのAPIを使用して考えているならば、それを書くのは簡単です、サイドノートで

http://ibmstreams.github.io/streamsx.documentation/docs/4.2/java/java-appapi-devguide/#integrating-spl-operators-with-the-java-application-api

を通常のJavaクラスであり、Topology APIから直接呼び出します。例えば

:ここ

MyJavaCode someObj = new MyJavaCode(); 

Topology topology = new Topology("MyTopology"); 
TStream<String> inDataFileName = ... 
inDataFileName.transform(new Function<String, String>(){ 
     @Override 
     public String apply(String word) { 
      return someObj.someFunction(word); 
     } 
    }); 

唯一の要件は、JavaクラスがSerializableを実装する必要があるということです。

+0

someObj.someFunction(word)、この関数はWebサービス呼び出しかJDBC挿入呼び出しですか? –

+0

はい、この関数は何でもできます。私はこのアプローチを採用し、GSONライブラリをラップして、Topology APIを使用してJSON解析をストリーミングします。重要なことは、クラスがSerializableであり、トポロジAPIに戻されるオブジェクトがシリアライズ可能であることを確認することです。 –

関連する問題