Java Code Examples for backtype.storm.tuple.Fields

The following examples show how to use backtype.storm.tuple.Fields. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jstorm   Source File: TridentReach.java    License: Apache License 2.0 6 votes vote down vote up
public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    
    builder.setSpout("spout", new InOrderSpout(), 8);
    builder.setBolt("count", new Check(), 8).fieldsGrouping("spout", new Fields("c1"));
    
    conf.setMaxSpoutPending(20);
    
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    
    if (isLocal) {
        drpc = new LocalDRPC();
    }
    
    try {
        JStormHelper.runTopology(buildTopology(drpc), topologyName, conf, 60, new DrpcValidator(), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
 
Example 2
Source Project: jstorm   Source File: TridentSlidingCountWindowTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTridentSlidingCountWindow()
{
    WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory();
    FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE,
                new Values("the cow jumped over the moon"),
                new Values("the man went to the store and bought some candy"),
                new Values("four score and seven years ago"), new Values("how many apples can you eat"),
                new Values("to be or not to be the person"));

    TridentTopology tridentTopology = new TridentTopology();

    Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16)
                .each(new Fields("sentence"), new Split(), new Fields("word"))
                .window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count"))
                .peek(new ValidateConsumer());

    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentSlidingCountWindowTest");

    JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null);
}
 
Example 3
Source Project: incubator-heron   Source File: WorkerTopologyContext.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public WorkerTopologyContext(
    StormTopology topology,
    Map stormConf,
    Map<Integer, String> taskToComponent,
    Map<String, List<Integer>> componentToSortedTasks,
    Map<String, Map<String, Fields>> componentToStreamToFields,
    String stormId,
    String codeDir,
    String pidDir,
    Integer workerPort,
    List<Integer> workerTasks,
    Map<String, Object> defaultResources,
    Map<String, Object> userResources
) {
  super(topology, stormConf, taskToComponent,
      componentToSortedTasks, componentToStreamToFields, stormId);
  throw new RuntimeException("WorkerTopologyContext should never be init this way");
}
 
Example 4
Source Project: jstorm   Source File: KvStatefulBoltExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    createState(context);
    prepare(stormConf, context, collector, keyRangeState);
    
    Map<GlobalStreamId, Grouping> sources = context.getSources(context.getThisComponentId());
    for (Map.Entry<GlobalStreamId, Grouping> entry : sources.entrySet()) {
        GlobalStreamId stream = entry.getKey();
        Grouping grouping = entry.getValue();
        Grouping._Fields groupingFields = Thrift.groupingType(grouping);
        if (Grouping._Fields.FIELDS.equals(groupingFields)) {
            Fields fields = new Fields(Thrift.fieldGrouping(grouping));
            fieldGrouping.put(stream.get_streamId(), fields);
        }
    }
    LOG.info("Source fieldgrouping streams: {}", fieldGrouping);
}
 
Example 5
Source Project: jstorm   Source File: TridentWordCount.java    License: Apache License 2.0 6 votes vote down vote up
public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3,
            new Values("the cow jumped over the moon"),
            new Values("the man went to the store and bought some candy"),
            new Values("four score and seven years ago"), new Values("how many apples can you eat"),
            new Values("to be or not to be the person"));
    spout.setCycle(true);
    
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16)
            .each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word"))
            .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
            .parallelismHint(16);
            
    topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word"))
            .groupBy(new Fields("word"))
            .stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
            .each(new Fields("count"), new FilterNull())
            .aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
 
Example 6
Source Project: jstorm   Source File: BatchAckerTest.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
    Config conf = JStormHelper.getConfig(args);
    int spoutParallelism = JStormUtils.parseInt(conf.get(SPOUT_PARALLELISM_HINT), 1);
    int splitParallelism = JStormUtils.parseInt(conf.get(SPLIT_PARALLELISM_HINT), 2);
    int countParallelism = JStormUtils.parseInt(conf.get(COUNT_PARALLELISM_HINT), 2);
    boolean isValueSpout = JStormUtils.parseBoolean(conf.get("is.value.spout"), false);

    TransactionTopologyBuilder builder = new TransactionTopologyBuilder();
    if (isValueSpout)
        builder.setSpoutWithAck("spout", new BatchAckerValueSpout(), spoutParallelism);
    else
        builder.setSpoutWithAck("spout", new BatchAckerSpout(), spoutParallelism);
    builder.setBoltWithAck("split", new BatchAckerSplit(), splitParallelism).localOrShuffleGrouping("spout");;
    builder.setBoltWithAck("count", new BatchAckerCount(), countParallelism).fieldsGrouping("split", new Fields("word"));
    
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    StormSubmitter.submitTopology(topologyName, conf, builder.createTopology());
}
 
Example 7
Source Project: eagle   Source File: HBaseAuditLogApplication.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public StormTopology execute(Config config, StormEnvironment environment) {
    TopologyBuilder builder = new TopologyBuilder();
    KafkaSpoutProvider provider = new KafkaSpoutProvider();
    IRichSpout spout = provider.getSpout(config);

    HBaseAuditLogParserBolt bolt = new HBaseAuditLogParserBolt();

    int numOfSpoutTasks = config.getInt(SPOUT_TASK_NUM);
    int numOfParserTasks = config.getInt(PARSER_TASK_NUM);
    int numOfJoinTasks = config.getInt(JOIN_TASK_NUM);
    int numOfSinkTasks = config.getInt(SINK_TASK_NUM);

    builder.setSpout("ingest", spout, numOfSpoutTasks);
    BoltDeclarer boltDeclarer = builder.setBolt("parserBolt", bolt, numOfParserTasks);
    boltDeclarer.fieldsGrouping("ingest", new Fields(StringScheme.STRING_SCHEME_KEY));

    HBaseResourceSensitivityDataJoinBolt joinBolt = new HBaseResourceSensitivityDataJoinBolt(config);
    BoltDeclarer joinBoltDeclarer = builder.setBolt("joinBolt", joinBolt, numOfJoinTasks);
    joinBoltDeclarer.fieldsGrouping("parserBolt", new Fields("f1"));

    StormStreamSink sinkBolt = environment.getStreamSink("hbase_audit_log_stream",config);
    BoltDeclarer kafkaBoltDeclarer = builder.setBolt("kafkaSink", sinkBolt, numOfSinkTasks);
    kafkaBoltDeclarer.fieldsGrouping("joinBolt", new Fields("user"));
    return builder.createTopology();
}
 
Example 8
Source Project: storm-benchmark   Source File: WordCount.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public StormTopology getTopology(Config config) {

  final int spoutNum = BenchmarkUtils.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM);
  final int spBoltNum = BenchmarkUtils.getInt(config, SPLIT_NUM, DEFAULT_SPLIT_BOLT_NUM);
  final int cntBoltNum = BenchmarkUtils.getInt(config, COUNT_NUM, DEFAULT_COUNT_BOLT_NUM);

  TopologyBuilder builder = new TopologyBuilder();

  builder.setSpout(SPOUT_ID, spout, spoutNum);
  builder.setBolt(SPLIT_ID, new SplitSentence(), spBoltNum).localOrShuffleGrouping(
          SPOUT_ID);
  builder.setBolt(COUNT_ID, new Count(), cntBoltNum).fieldsGrouping(SPLIT_ID,
    new Fields(SplitSentence.FIELDS));

  return builder.createTopology();
}
 
Example 9
Source Project: jstorm   Source File: WordCountTopology.java    License: Apache License 2.0 6 votes vote down vote up
public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    
    builder.setSpout("spout", new RandomSentenceSpout(), 5);
    
    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));
    
    Config conf = new Config();
    conf.setDebug(true);
    
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    
    try {
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60,
                new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
 
Example 10
Source Project: jstorm   Source File: ClojureSpout.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    for (String stream : _fields.keySet()) {
        StreamInfo info = _fields.get(stream);
        declarer.declareStream(stream, info.is_direct(), new Fields(info.get_output_fields()));
    }
}
 
Example 11
Source Project: jstorm   Source File: ContextMaker.java    License: Apache License 2.0 5 votes vote down vote up
public WorkerTopologyContext makeWorkerTopologyContext(StormTopology topology) {
    Map stormConf = workerData.getStormConf();
    String topologyId = workerData.getTopologyId();

    HashMap<String, Map<String, Fields>> componentToStreamToFields =
            workerData.generateComponentToStreamToFields(topology);

    return new WorkerTopologyContext(topology, stormConf, workerData.getTasksToComponent(),
            workerData.getComponentToSortedTasks(), componentToStreamToFields,
            topologyId, resourcePath, workerId, workerData.getPort(), workerTasks,
            workerData.getDefaultResources(), workerData.getUserResources());
}
 
Example 12
Source Project: jstorm   Source File: ClojureBolt.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    for (String stream : _fields.keySet()) {
        StreamInfo info = _fields.get(stream);
        declarer.declareStream(stream, info.is_direct(), new Fields(info.get_output_fields()));
    }
}
 
Example 13
Source Project: storm-benchmark   Source File: FileReadSpoutTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDeclareOutputFields() {
  FileReadSpout spout = new FileReadSpout(false, reader);

  spout.declareOutputFields(declarer);

  verify(declarer, times(1)).declare(any(Fields.class));
}
 
Example 14
Source Project: jstorm   Source File: Stream.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Stream each(Fields inputFields, Function function, Fields functionFields) {
    projectionValidation(inputFields);
    return _topology.addSourcedNode(this,
            new ProcessorNode(_topology.getUniqueStreamId(),
                    _name,
                    TridentUtils.fieldsConcat(getOutputFields(), functionFields),
                    functionFields,
                    new EachProcessor(inputFields, function)));
}
 
Example 15
Source Project: storm-cassandra-cql   Source File: SalesTopology.java    License: Apache License 2.0 5 votes vote down vote up
public static StormTopology buildTopology() {
    LOG.info("Building topology.");
    TridentTopology topology = new TridentTopology();
    SalesSpout spout = new SalesSpout();
    Stream inputStream = topology.newStream("sales", spout);
    SalesMapper mapper = new SalesMapper();
    inputStream.partitionPersist(
            new CassandraCqlIncrementalStateFactory<String, Number>(new Sum(), mapper),
            new Fields("price", "state", "product"),
            new CassandraCqlIncrementalStateUpdater<String, Number>());
    return topology.build();
}
 
Example 16
Source Project: StormCV   Source File: TileGrouping.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) {
	this.targetTasks = targetTasks;
	
	Fields tupleFields = context.getComponentOutputFields(stream);
	for(int i=0; i<tupleFields.size(); i++){
		if(tupleFields.get(i).equals(CVParticleSerializer.STREAMID)){
			streamIdIndex = i;
		}else if(tupleFields.get(i).equals(CVParticleSerializer.SEQUENCENR)){
			sequenceNrIndex = i;
		}
	}
}
 
Example 17
Source Project: jstorm   Source File: MasterBatchCoordinator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    // in partitioned example, in case an emitter task receives a later transaction than it's emitted so far,
    // when it sees the earlier txid it should know to emit nothing
    declarer.declareStream(BATCH_STREAM_ID, new Fields("tx"));
    declarer.declareStream(COMMIT_STREAM_ID, new Fields("tx"));
    declarer.declareStream(SUCCESS_STREAM_ID, new Fields("tx"));
}
 
Example 18
Source Project: jstorm   Source File: Stream.java    License: Apache License 2.0 5 votes vote down vote up
public TridentState persistentAggregate(StateSpec spec, Fields inputFields, CombinerAggregator agg, Fields functionFields) {
    projectionValidation(inputFields);
    // replaces normal aggregation here with a global grouping because it needs to be consistent across batches 
    return new ChainedAggregatorDeclarer(this, new GlobalAggScheme())
            .aggregate(inputFields, agg, functionFields)
            .chainEnd()
           .partitionPersist(spec, functionFields, new CombinerAggStateUpdater(agg), functionFields);
}
 
Example 19
Source Project: eagle   Source File: CorrelationSpout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * the only output field is for StreamEvent.
 *
 * @param declarer
 */
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    for (int i = 0; i < numOfRouterBolts; i++) {
        String streamId = StreamIdConversion.generateStreamIdBetween(spoutName, routeBoltName + i);
        declarer.declareStream(streamId, new Fields(AlertConstants.FIELD_0));
        LOG.info("declare stream between spout and streamRouterBolt " + streamId);
    }
}
 
Example 20
Source Project: jstorm   Source File: Node.java    License: Apache License 2.0 5 votes vote down vote up
public Node(String streamId, String name, Fields allOutputFields) {
    this.nodeId = UUID.randomUUID().toString();
    this.allOutputFields = allOutputFields;
    this.streamId = streamId;
    this.name = name;
    this.creationIndex = INDEX.incrementAndGet();
}
 
Example 21
Source Project: jstorm   Source File: TransactionalWordsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_transaction_word() {
    try {
        MemoryTransactionalSpout spout = new MemoryTransactionalSpout(DATA, new Fields("word"), PARTITION_TAKE_PER_BATCH);
        TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder("top-n-words", "spout", spout, 2);
        builder.setBolt("count", new KeyedCountUpdater(), 5).fieldsGrouping("spout", new Fields("word"));
        builder.setBolt("bucketize", new Bucketize()).shuffleGrouping("count");
        builder.setBolt("buckets", new BucketCountUpdater(), 5).fieldsGrouping("bucketize", new Fields("bucket"));

        LocalCluster cluster = new LocalCluster();

        Config config = new Config();
        config.setDebug(true);
        config.setMaxSpoutPending(3);

        cluster.submitTopology("top-n-topology", config, builder.buildTopology());

        JStormUtils.sleepMs(60 * 1000);
        
        
        assertEquals(false, outOfOrder.get() );
        assertNotSame(0, receiveCounter1.get());
        assertNotSame(0, receiveCounter2.get());
        
        //cluster.killTopology("top-n-topology");
        //cluster.shutdown();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Failed to run simple transaction");
    }

}
 
Example 22
Source Project: flink-perf   Source File: Latency.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ParameterTool pt = ParameterTool.fromArgs(args);

	int par = pt.getInt("para");

	TopologyBuilder builder = new TopologyBuilder();

	builder.setSpout("source0", new Generator(pt), pt.getInt("sourceParallelism"));
	int i = 0;
	for(; i < pt.getInt("repartitions", 1) - 1;i++) {
		System.out.println("adding source"+i+" --> source"+(i+1));
		builder.setBolt("source"+(i+1), new PassThroughBolt(pt), pt.getInt("sinkParallelism")).fieldsGrouping("source" + i, new Fields("id"));
	}
	System.out.println("adding final source"+i+" --> sink");

	builder.setBolt("sink", new Sink(pt), pt.getInt("sinkParallelism")).fieldsGrouping("source"+i, new Fields("id"));


	Config conf = new Config();
	conf.setDebug(false);
	//System.exit(1);

	if (!pt.has("local")) {
		conf.setNumWorkers(par);

		StormSubmitter.submitTopologyWithProgressBar("throughput-"+pt.get("name", "no_name"), conf, builder.createTopology());
	}
	else {
		conf.setMaxTaskParallelism(par);

		LocalCluster cluster = new LocalCluster();
		cluster.submitTopology("throughput", conf, builder.createTopology());

		Thread.sleep(300000);

		cluster.shutdown();
	}

}
 
Example 23
Source Project: jstorm   Source File: GeneralTopologyContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the declared output fields for the specified component/stream.
 */
public Fields getComponentOutputFields(String componentId, String streamId) {
    Fields ret = _componentToStreamToFields.get(componentId).get(streamId);
    if (ret == null) {
        throw new IllegalArgumentException("No output fields defined for component:stream " + componentId + ":" + streamId);
    }
    return ret;
}
 
Example 24
Source Project: StormCV   Source File: FeatureGrouping.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a featureGrouping for the specified feature name. Features with this name will be routed
 * randomly.
 * @param featureName
 * @throws InstantiationException
 */
public FeatureGrouping(String featureName) throws InstantiationException{
	this.featureName = featureName;
	FeatureSerializer serializer = new FeatureSerializer();
	Fields fields = serializer.getFields();
	indexes = new ArrayList<Integer>();
	for(int i=0; i<fields.size(); i++){
		if(fields.get(i).equals(FeatureSerializer.NAME)){
			nameIndex = i;
		}
	}
	if(nameIndex == -1)throw new InstantiationException("No index found for feature name: "+featureName);
}
 
Example 25
Source Project: eagle   Source File: SparkRunningJobApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StormTopology execute(Config config, StormEnvironment environment) {
    //1. trigger prepare conf
    SparkRunningJobAppConfig sparkRunningJobAppConfig = SparkRunningJobAppConfig.newInstance(config);

    //2. prepare topology
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    final String spoutName = SparkRunningJobAppConfig.JOB_FETCH_SPOUT_NAME;
    final String boltName = SparkRunningJobAppConfig.JOB_PARSE_BOLT_NAME;
    int parallelism = sparkRunningJobAppConfig.getJobExtractorConfig().jobFetchSpoutParallism;
    int tasks = sparkRunningJobAppConfig.getJobExtractorConfig().jobFetchSpoutTasksNum;
    if (parallelism > tasks) {
        parallelism = tasks;
    }
    topologyBuilder.setSpout(
            spoutName,
            new SparkRunningJobFetchSpout(
                    sparkRunningJobAppConfig.getJobExtractorConfig(),
                    sparkRunningJobAppConfig.getEndpointConfig(),
                    sparkRunningJobAppConfig.getZkStateConfig()),
            parallelism
    ).setNumTasks(tasks);

    parallelism = sparkRunningJobAppConfig.getJobExtractorConfig().jobParseBoltParallism;
    tasks = sparkRunningJobAppConfig.getJobExtractorConfig().jobParseBoltTasksNum;
    if (parallelism > tasks) {
        parallelism = tasks;
    }
    topologyBuilder.setBolt(boltName,
            new SparkRunningJobParseBolt(
                    sparkRunningJobAppConfig.getZkStateConfig(),
                    sparkRunningJobAppConfig.getEagleServiceConfig(),
                    sparkRunningJobAppConfig.getEndpointConfig(),
                    sparkRunningJobAppConfig.getJobExtractorConfig()),
            parallelism).setNumTasks(tasks).fieldsGrouping(spoutName, new Fields("appId"));

    return topologyBuilder.createTopology();
}
 
Example 26
Source Project: jstorm   Source File: TridentMinMaxOfVehiclesTopology.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a topology which demonstrates min/max operations on tuples of
 * stream which contain vehicle and driver fields with values
 * {@link TridentMinMaxOfVehiclesTopology.Vehicle} and
 * {@link TridentMinMaxOfVehiclesTopology.Driver} respectively.
 */
public static StormTopology buildVehiclesTopology() {
    Fields driverField = new Fields(Driver.FIELD_NAME);
    Fields vehicleField = new Fields(Vehicle.FIELD_NAME);
    Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME);
    
    FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20));
    spout.setCycle(true);
    
    TridentTopology topology = new TridentTopology();
    Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles"));
    
    Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField,
            new Debug("#### slowest vehicle"));
            
    Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField,
            new Debug("##### slowest driver"));
            
    vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle"))
            .project(driverField).each(driverField, new Debug("##### fastest driver"));
            
    vehiclesStream.minBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField,
            new Debug("#### least efficient vehicle"));
            
    vehiclesStream.maxBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField,
            new Debug("#### most efficient vehicle"));
            
    return topology.build();
}
 
Example 27
Source Project: jstorm   Source File: TridentFastWordCount.java    License: Apache License 2.0 4 votes vote down vote up
public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3,
            new Values("the cow jumped over the moon"),
            new Values("the man went to the store and bought some candy"),
            new Values("four score and seven years ago"), new Values("how many apples can you eat"),
            new Values("to be or not to be the person"),
            new Values("marry had a little lamb whos fleese was white as snow"),
            new Values("and every where that marry went the lamb was sure to go"),
            new Values("one two three four five six seven eight nine ten"),
            new Values("this is a test of the emergency broadcast system this is only a test"),
            new Values("peter piper picked a peck of pickeled peppers"),
            new Values("JStorm is a distributed and fault-tolerant realtime computation system."),
            new Values(
                    "Inspired by Apache Storm, JStorm has been completely rewritten in Java and provides many more enhanced features."),
            new Values("JStorm has been widely used in many enterprise environments and proved robust and stable."),
            new Values("JStorm provides a distributed programming framework very similar to Hadoop MapReduce."),
            new Values(
                    "The developer only needs to compose his/her own pipe-lined computation logic by implementing the JStorm API"),
            new Values(" which is fully compatible with Apache Storm API"),
            new Values("and submit the composed Topology to a working JStorm instance."),
            new Values("Similar to Hadoop MapReduce, JStorm computes on a DAG (directed acyclic graph)."),
            new Values("Different from Hadoop MapReduce, a JStorm topology runs 24 * 7"),
            new Values("the very nature of its continuity abd 100% in-memory architecture "),
            new Values(
                    "has been proved a particularly suitable solution for streaming data and real-time computation."),
            new Values("JStorm guarantees fault-tolerance."), new Values("Whenever a worker process crashes, "),
            new Values(
                    "the scheduler embedded in the JStorm instance immediately spawns a new worker process to take the place of the failed one."),
            new Values(" The Acking framework provided by JStorm guarantees that every single piece of data will be processed at least once.") );
    spout.setCycle(true);
    
    
    int spout_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
    int split_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPLIT_PARALLELISM_HINT), 2);
    int count_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 2);
    
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(spout_Parallelism_hint)
            .each(new Fields("sentence"), new Split(), new Fields("word")).parallelismHint(split_Parallelism_hint).groupBy(new Fields("word"))
            .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
            .parallelismHint(count_Parallelism_hint);
            
    return topology.build();
}
 
Example 28
Source Project: jstorm   Source File: MapProcessor.java    License: Apache License 2.0 4 votes vote down vote up
public MapProcessor(Fields inputFields, Function function) {
    _function = function;
    _inputFields = inputFields;
}
 
Example 29
Source Project: eagle   Source File: TestStormStreamIdRouting.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declareStream("green-bolt-stream-1", new Fields("a"));
    declarer.declareStream("green-bolt-stream-2", new Fields("a"));
}
 
Example 30
Source Project: jstorm   Source File: GroupedStream.java    License: Apache License 2.0 4 votes vote down vote up
public TridentState persistentAggregate(StateSpec spec, ReducerAggregator agg, Fields functionFields) {
    return persistentAggregate(spec, null, agg, functionFields);
}