这是我的输入 spout 的代码片段,用于将元组发送到一个处理节点,以便在集群上进行流处理。问题是 BlockingQueue 正在抛出 InterruptedException 。
private SpoutOutputCollector collector;
public BlockingQueue<String> blockingQueue = new LinkedBlockingQueue<String>();
public boolean isDistributed() {
return true;
}
public void open(@SuppressWarnings("rawtypes") final Map conf, final TopologyContext context,
final SpoutOutputCollector collector) {
this.collector=collector;
}
@Override
public void nextTuple() {
try {
//Utils.sleep(100);
collector.emit(new Values("Single Temperature Reading", blockingQueue.take()));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void readInputfile() throws IOException, InterruptedException{
FileInputStream file = new FileInputStream("/home/529076/Desktop/Temperature");
DataInputStream readDate=new DataInputStream(file);
BufferedReader readText=new BufferedReader(new InputStreamReader(readDate));
String line;
String singleReading = null;
while((line=readText.readLine())!=null){
singleReading=line;
blockingQueue.add(singleReading);
}
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("Single Temperature Reading"));
}
异常描述如下:---
java.lang.InterruptedException10930 [Thread-20] INFO backtype.storm.util - 异步循环中断!
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1961)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1996)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
at com.tcs.storm.test.InputStreamSpout.nextTuple(InputStreamSpout.java:65)
at backtype.storm.daemon.task$fn__3349$fn__3404.invoke(task.clj:413)
而 nextTuple(InputStreamSpout.java:65 是 ------>
collector.emit(new Values("Single Temperature Reading", blockingQueue.take()));
谢谢