Open Kilda Java Documentation
AbstractBolt.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.wfm;
17 
19 
20 import lombok.extern.slf4j.Slf4j;
21 import org.apache.storm.task.OutputCollector;
22 import org.apache.storm.task.TopologyContext;
23 import org.apache.storm.topology.base.BaseRichBolt;
24 import org.apache.storm.tuple.Tuple;
25 
26 import java.util.Map;
27 
28 @Slf4j
29 public abstract class AbstractBolt extends BaseRichBolt {
30  private OutputCollector output;
31 
32  @Override
33  public void execute(Tuple input) {
34  try {
35  handleInput(input);
36  } catch (Exception e) {
37  log.error(String.format("Unhandled exception in %s", getClass().getName()), e);
38  } finally {
39  output.ack(input);
40  }
41  }
42 
43  protected abstract void handleInput(Tuple input) throws AbstractException;
44 
45  protected void unhandledInput(Tuple input) {
46  log.error(
47  "{} is unable to handle input tuple from {} stream {} - have topology being build correctly?",
48  getClass().getName(), input.getSourceComponent(), input.getSourceStreamId());
49  }
50 
51  @Override
52  public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
53  this.output = collector;
54  }
55 
56  protected OutputCollector getOutput() {
57  return output;
58  }
59 }
void unhandledInput(Tuple input)
abstract void handleInput(Tuple input)
void prepare(Map stormConf, TopologyContext context, OutputCollector collector)