实战教程:Java StreamingOutput类的使用方法——实例1:process操作详解
最编程
2024-08-02 11:42:57
...
import com.ibm.streams.operator.StreamingOutput; //导入依赖的package包/类
@Override
protected void process() throws Exception {
final StreamingOutput<OutputTuple> out = getOutput(0);
JSONObject json = new JSONObject();
for (int i = 0; i < 100; i++) {
json.put("username", "Frank");
json.put("tweet", "This JSON message also rocks: " + i);
json.put("timestamp", new Long(1048298240L + i));
/* Now submit tuple */
OutputTuple tuple = out.newTuple();
String jsonString = json.serialize();
long timeStamp = System.currentTimeMillis();
tuple.setString(0, jsonString);
tuple.setLong(1, timeStamp);
out.submit(tuple);
if (i != 0 && i % 20 == 0)
out.punctuate(Punctuation.WINDOW_MARKER);
}
// Make the set of tuples a window.
out.punctuate(Punctuation.WINDOW_MARKER);
}
上一篇: 在Java中,如何处理包外的类引用?