我的数据来自通过websocket连接到我的风暴群集的传感器,因此每当数据点到达我的websocket服务器时,我将其添加到 ConcurrentLinkedQueue 。我没有关于数据点和生产的频率的先验信息"。
我的spout在此队列上获取数据点并发出相应的Tupple。 Everythink运作良好一段时间(我会说大约1000个数据点),但后来我得到了以下错误:
76245 [Thread-23-incDp] ERROR backtype.storm.util - Async loop died!
java.lang.NullPointerException: null
at streams.storm.spout.MySpout.nextTuple(MySpout.java:56) ~[bin/:na]
at backtype.storm.daemon.executor$fn__3373$fn__3388$fn__3417.invoke(executor.clj:565) ~[storm-core-0.9.3.jar:0.9.3]
at backtype.storm.util$async_loop$fn__464.invoke(util.clj:463) ~[storm-core-0.9.3.jar:0.9.3]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
76246 [Thread-23-incDp] ERROR backtype.storm.daemon.executor -
java.lang.NullPointerException: null
at streams.storm.spout.MySpout.nextTuple(MySpout.java:56) ~[bin/:na]
at backtype.storm.daemon.executor$fn__3373$fn__3388$fn__3417.invoke(executor.clj:565) ~[storm-core-0.9.3.jar:0.9.3]
at backtype.storm.util$async_loop$fn__464.invoke(util.clj:463) ~[storm-core-0.9.3.jar:0.9.3]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
76481 [Thread-23-incDp] ERROR backtype.storm.util - Halting process: ("Worker died")
java.lang.RuntimeException: ("Worker died")
at backtype.storm.util$exit_process_BANG_.doInvoke(util.clj:325) [storm-core-0.9.3.jar:0.9.3]
at clojure.lang.RestFn.invoke(RestFn.java:423) [clojure-1.5.1.jar:na]
at backtype.storm.daemon.worker$fn__3808$fn__3809.invoke(worker.clj:452) [storm-core-0.9.3.jar:0.9.3]
at backtype.storm.daemon.executor$mk_executor_data$fn__3274$fn__3275.invoke(executor.clj:240) [storm-core-0.9.3.jar:0.9.3]
at backtype.storm.util$async_loop$fn__464.invoke(util.clj:473) [storm-core-0.9.3.jar:0.9.3]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
这是我的鲸鱼喷码:
public class MySpout extends BaseRichSpout
{
private static final long serialVersionUID = 1L;
private AtomicLong messageIdCounter = new AtomicLong();
private static Queue<String> incData;
private SpoutOutputCollector collector;
public MySpout()
{
incData = new ConcurrentLinkedQueue<String>();
}
@Override
public void nextTuple()
{
if(incData.isEmpty())
{
Utils.sleep(500);
}
else
{
String[] splittedMsg = incData.poll().split(" ; ");
JSONParser jsonParser = new JSONParser();
try
{
int ts = Integer.parseInt(splittedMsg[0]);
JSONObject json = (JSONObject) jsonParser.parse(splittedMsg[1]);
collector.emit(new Values( ts, new DataPoint(ts, new ArrayList(json.values()))), messageIdCounter.incrementAndGet() );
}
catch (ParseException e)
{
System.err.println("Wrong input format: should be json");
e.printStackTrace();
}
}
}
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
this.collector = collector;
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("time", "dps" ));
}
public static void addElmtToQueue(String json)
{
incData.add(json);
}
我想这是因为队列出现了问题,或者不再是数据点或者我的两个线程之间的并发问题(顺便说一句,我知道让它静止可能会很糟糕,但我还没找到另一个解决方案,因为我需要在我的服务器线程上访问它...)。
有人遇到同样的问题吗?任何解决方案/评论都会受到欢迎:)祝有人提前感谢。
答案 0 :(得分:1)
MySpout.java的第56行抛出NullPointerException。
java.lang.NullPointerException: null
at streams.storm.spout.MySpout.nextTuple(MySpout.java:56) ~[bin/:na]
我打赌这行就是问题所在:
String[] splittedMsg = incData.poll().split(" ; ");
由于事实that poll() will return null when your queue is empty。
NullPointerException导致您的spout崩溃。我会建议两件事:
示例:
@Override
public void nextTuple() {
try {
String message = _queue.poll();
if (message == null) {
// didn't get a message, sleep for a little bit
Utils.sleep(50);
} else {
// do stuff with message
}
} catch (Exception e) {
_collector.reportError(e);
LOG.error("Spout error {}", e);
}
}