org.apache.storm.topology.IBasicBolt Java Examples

The following examples show how to use org.apache.storm.topology.IBasicBolt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Twister2Bolt.java    From twister2 with Apache License 2.0 6 votes vote down vote up
public Twister2Bolt(String id, Object bolt, MadeASourceListener madeASourceListener) {
  this.id = id;
  this.boltDeclarer = new Twister2BoltDeclarer(madeASourceListener);
  this.outFieldsForEdge = new EdgeFieldMap(Utils.getDefaultStream(id));
  this.keyedOutEdges = new EdgeFieldMap(Utils.getDefaultStream(id));
  if (bolt instanceof IRichBolt) {
    this.stormBolt = (IRichBolt) bolt;
    this.stormBolt.declareOutputFields(this.outFieldsForEdge);
  } else if (bolt instanceof BaseWindowedBolt) {
    this.stormWindowedBolt = (BaseWindowedBolt) bolt;
    this.stormWindowedBolt.declareOutputFields(this.outFieldsForEdge);
    this.stormWindowedBoltExecutor = new WindowedBoltExecutor(this.stormWindowedBolt);
  } else {
    this.stormBasicBolt = (IBasicBolt) bolt;
    this.stormBasicBolt.declareOutputFields(this.outFieldsForEdge);
  }
}
 
Example #2
Source File: StreamBuilder.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
protected void buildStreams(EcoExecutionContext executionContext, TopologyBuilder builder,
                            ObjectBuilder objectBuilder)
    throws IllegalAccessException, InstantiationException, ClassNotFoundException,
    NoSuchFieldException, InvocationTargetException {
  EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
  Map<String, ComponentStream> componentStreams = new HashMap<>();

  HashMap<String, BoltDeclarer> declarers = new HashMap<>();
  for (StreamDefinition stream : topologyDefinition.getStreams()) {
    Object boltObj = executionContext.getBolt(stream.getTo());
    BoltDeclarer declarer = declarers.get(stream.getTo());
    if (boltObj instanceof IRichBolt) {
      if (declarer == null) {
        declarer = builder.setBolt(stream.getTo(),
            (IRichBolt) boltObj,
            topologyDefinition.parallelismForBolt(stream.getTo()));
        declarers.put(stream.getTo(), declarer);
      }
    } else if (boltObj instanceof IBasicBolt) {
      if (declarer == null) {
        declarer = builder.setBolt(
            stream.getTo(),
            (IBasicBolt) boltObj,
            topologyDefinition.parallelismForBolt(stream.getTo()));
        declarers.put(stream.getTo(), declarer);
      }
    } else if (boltObj instanceof IWindowedBolt) {
      if (declarer == null) {
        declarer = builder.setBolt(
            stream.getTo(),
            (IWindowedBolt) boltObj,
            topologyDefinition.parallelismForBolt(stream.getTo()));
        declarers.put(stream.getTo(), declarer);
      }
    }  else {
      throw new IllegalArgumentException("Class does not appear to be a bolt: "
          + boltObj.getClass().getName());
    }

    GroupingDefinition grouping = stream.getGrouping();
    // if the streamId is defined, use it for the grouping,
    // otherwise assume default stream
    String streamId = grouping.getStreamId() == null
        ? Utils.DEFAULT_STREAM_ID : grouping.getStreamId();


    switch (grouping.getType()) {
      case SHUFFLE:
        declarer.shuffleGrouping(stream.getFrom(), streamId);
        break;
      case FIELDS:
        List<String> groupingArgs = grouping.getArgs();
        if (groupingArgs == null) {
          throw new IllegalArgumentException("You must supply arguments for Fields grouping");
        }
        declarer.fieldsGrouping(stream.getFrom(), streamId, new Fields(groupingArgs));
        break;
      case ALL:
        declarer.allGrouping(stream.getFrom(), streamId);
        break;
      case GLOBAL:
        declarer.globalGrouping(stream.getFrom(), streamId);
        break;
      case NONE:
        declarer.noneGrouping(stream.getFrom(), streamId);
        break;
      case CUSTOM:
        declarer.customGrouping(stream.getFrom(), streamId,
            buildCustomStreamGrouping(stream.getGrouping().getCustomClass(),
                executionContext,
                objectBuilder));
        break;
      default:
        throw new UnsupportedOperationException("unsupported grouping type: " + grouping);
    }
  }
  executionContext.setStreams(componentStreams);
}