Package backtype.storm

Examples of backtype.storm.LocalDRPC


  }

  public static void main(String[] args) {
    TopologyBuilder builder = new TopologyBuilder();
    LocalDRPC drpc = new LocalDRPC();

    DRPCSpout spout = new DRPCSpout("exclamation", drpc);
    builder.setSpout("drpc", spout);
    builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
    builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");

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

    System.out.println(drpc.execute("exclamation", "aaa"));
    System.out.println(drpc.execute("exclamation", "bbb"));

  }
View Full Code Here


  public static void main(String[] args) throws Exception {
    Config conf = new Config();
    conf.setMaxSpoutPending(20);

    // This topology can only be run as local because it is a toy example
    LocalDRPC drpc = new LocalDRPC();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("hashtagCounter", conf, buildTopology(drpc));
    // Query 100 times for hashtag "california" for illustrating the effect of the lambda architecture
    for(int i = 0; i < 100; i++) {
      System.out.println("Result for hashtag 'california' -> " + drpc.execute("hashtags", "california"));
      Thread.sleep(1000);
    }
  }
View Full Code Here

    Config conf = new Config();

    if (args == null || args.length == 0) {
      conf.setMaxTaskParallelism(3);
      LocalDRPC drpc = new LocalDRPC();
      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("reach-drpc", conf, builder.createLocalTopology(drpc));

      String[] urlsToTry = new String[]{ "foo.com/blog/1", "engineering.twitter.com/blog/5", "notaurl.com" };
      for (String url : urlsToTry) {
        System.out.println("Reach of " + url + ": " + drpc.execute("reach", url));
      }

      cluster.shutdown();
      drpc.shutdown();
    }
    else {
      conf.setNumWorkers(6);
      StormSubmitter.submitTopology(args[0], conf, builder.createRemoteTopology());
    }
View Full Code Here

    builder.addBolt(new ExclaimBolt(), 3);

    Config conf = new Config();

    if (args == null || args.length == 0) {
      LocalDRPC drpc = new LocalDRPC();
      LocalCluster cluster = new LocalCluster();

      cluster.submitTopology("drpc-demo", conf, builder.createLocalTopology(drpc));

      for (String word : new String[]{ "hello", "goodbye" }) {
        System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word));
      }

      cluster.shutdown();
      drpc.shutdown();
    }
    else {
      conf.setNumWorkers(3);
      StormSubmitter.submitTopology(args[0], conf, builder.createRemoteTopology());
    }
View Full Code Here

  public static void main(String[] args) throws Exception {
    Config conf = new Config();
    conf.setMaxSpoutPending(20);
    if (args.length == 0) {
      LocalDRPC drpc = new LocalDRPC();
      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("wordCounter", conf, buildTopology(drpc));
      for (int i = 0; i < 100; i++) {
        System.out.println("DRPC RESULT: " + drpc.execute("words", "cat the dog jumped"));
        Thread.sleep(1000);
      }
    }
    else {
      conf.setNumWorkers(3);
View Full Code Here

        "one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
    return topology.build();
  }

  public static void main(String[] args) throws Exception {
    LocalDRPC drpc = new LocalDRPC();

    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();

    cluster.submitTopology("reach", conf, buildTopology(drpc));

    Thread.sleep(2000);

    System.out.println("REACH: " + drpc.execute("reach", "aaa"));
    System.out.println("REACH: " + drpc.execute("reach", "foo.com/blog/1"));
    System.out.println("REACH: " + drpc.execute("reach", "engineering.twitter.com/blog/5"));


    cluster.shutdown();
    drpc.shutdown();
  }
View Full Code Here

  @Test
  public void testInTopology() throws InterruptedException {
    // Start local cluster
    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // Classification stream
      toppology.newDRPCStream("classify", localDRPC)
        // Query classifier with text instance
        .each(new Fields("args"), new TwitterSentimentClassifier(), new Fields("sentiment")).project(new Fields("sentiment"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      // Query with DRPC
      test(false, "RT @JazminBianca: I hate Windows 8. I hate Windows 8. I hate Windows 8.", localDRPC);
      test(false, "I don't like Windows 8, I think it's overrated =))", localDRPC);
      test(false, "Windows 8 is stupid as fuck ! Shit is confusing <<", localDRPC);
      test(false, "not a big fan of Windows 8", localDRPC);
      test(false, "Forever hating apple for changing the chargers #wanks", localDRPC);
      test(false, "#CSRBlast #CSRBlast That moment you pull out a book because the customer service at apple is horrible and takes wa... http://t.co/WxqyGR9a85", localDRPC);

      test(true, "Windows 8 is awesome :D", localDRPC);
      test(true, "God Windows 8 is amazing. Finally", localDRPC);
      test(true, "Register for the AWESOME Windows 8 western US regional events all in the next few weeks! http://t.co/7lfqaHSxfs #w8appfactor @w8appfactor", localDRPC);
      test(true, "Windows 8 is fun to use. I like it better then mac lion.", localDRPC);
      test(true, "Good morning loves 😁😁 apple jacks doe http://t.co/nOfi42enoQ", localDRPC);
      test(true, "@Saad_khan33 No i prefer apple anyday", localDRPC);

    } finally {
      cluster.shutdown();
      localDRPC.shutdown();
    }
  }
View Full Code Here

  @Test
  public void testInTopology() throws InterruptedException {
    // Start local cluster
    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // "Training" stream
      TridentState classifierState = toppology.newStream("reutersData", new ReutersBatchSpout())
      // Transform raw data to text instance
          .each(new Fields("label", "text"), new TextInstanceCreator<Integer>(), new Fields("instance"))

          // Update text classifier
          .partitionPersist(new MemoryMapState.Factory(), new Fields("instance"), new TextClassifierUpdater<Integer>("newsClassifier", new KLDClassifier(9)));

      // Classification stream
      toppology.newDRPCStream("classify", localDRPC)
      // Convert DRPC args to text instance
          .each(new Fields("args"), new TextInstanceCreator<Integer>(false), new Fields("instance"))

          // Query classifier with text instance
          .stateQuery(classifierState, new Fields("instance"), new ClassifyTextQuery<Integer>("newsClassifier"), new Fields("prediction")).project(new Fields("prediction"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      // Query with DRPC
      for (Integer realClass : ReutersBatchSpout.REUTEURS_EVAL_SAMPLES.keySet()) {
        Integer prediction = extractPrediction(localDRPC.execute("classify", ReutersBatchSpout.REUTEURS_EVAL_SAMPLES.get(realClass)));
        assertEquals(realClass, prediction);
      }

    } finally {
      cluster.shutdown();
      localDRPC.shutdown();
    }
  }
View Full Code Here

  @Test
  public void testInTopology() throws InterruptedException {
    // Start local cluster
    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      // Build topology
      TridentTopology toppology = new TridentTopology();

      // Training stream
      TridentState kmeansState = toppology
        // Emit tuples with a instance containing an integer as label and 3
        // double features named (x0, x1 and x2)
        .newStream("samples", new RandomFeaturesForClusteringSpout())

        // Convert trident tuple to instance
        .each(new Fields("label", "x0", "x1", "x2"), new InstanceCreator<Integer>(), new Fields("instance"))

        // Update a 3 classes kmeans
        .partitionPersist(new MemoryMapState.Factory(), new Fields("instance"), new ClusterUpdater("kmeans", new KMeans(3)));

      // Cluster stream
      toppology.newDRPCStream("predict", localDRPC)
        // Convert DRPC args to instance
        .each(new Fields("args"), new DRPCArgsToInstance(), new Fields("instance"))

        // Query kmeans to classify instance
        .stateQuery(kmeansState, new Fields("instance"), new ClusterQuery("kmeans"), new Fields("prediction"))
         
        .project(new Fields("prediction"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());

      Thread.sleep(10000);

      Integer result11 = extractPrediction(localDRPC.execute("predict", "1.0 1.0 1.0"));
      Integer result12 = extractPrediction(localDRPC.execute("predict", "0.8 1.1 0.9"));
      assertEquals(result11, result12);

      Integer result21 = extractPrediction(localDRPC.execute("predict", "1.0 -1.0 1.0"));
      Integer result22 = extractPrediction(localDRPC.execute("predict", "0.8 -1.1 0.9"));
      assertEquals(result21, result22);

      Integer result31 = extractPrediction(localDRPC.execute("predict", "1.0 -1.0 -1.0"));
      Integer result32 = extractPrediction(localDRPC.execute("predict", "0.8 -1.1 -0.9"));
      assertEquals(result31, result32);
    } finally {
      cluster.shutdown();
      localDRPC.shutdown();
    }
  }
View Full Code Here

  @Test
  public void should_test_then_train() throws InterruptedException {
    // Start local cluster
    LocalCluster cluster = new LocalCluster();
    LocalDRPC localDRPC = new LocalDRPC();

    try {
      TridentTopology toppology = new TridentTopology();
      MemoryMapState.Factory evaluationStateFactory = new MemoryMapState.Factory();
      MemoryMapState.Factory perceptronModelStateFactory = new MemoryMapState.Factory();
      TridentState perceptronModel = toppology.newStaticState(perceptronModelStateFactory);
      TridentState perceptronEvaluation = toppology.newStaticState(evaluationStateFactory);

      // Predict
      Stream predictionStream = toppology.newStream("nandsamples", new NANDSpout()) //
          .stateQuery(perceptronModel, new Fields("instance"), new ClassifyQuery<Boolean>("perceptron"), new Fields("prediction"));

      // Update evaluation
      predictionStream //
          .persistentAggregate(evaluationStateFactory, new Fields("instance", "prediction"), new AccuracyAggregator<Boolean>(), new Fields("accuracy"));

      // Update model
      predictionStream.partitionPersist(perceptronModelStateFactory, new Fields("instance"), new ClassifierUpdater<Boolean>("perceptron", new PerceptronClassifier()));

      // Classification stream
      toppology.newDRPCStream("predict", localDRPC)
      // convert DRPC args to instance
          .each(new Fields("args"), new DRPCArgsToInstance(), new Fields("instance"))

          // Query classifier to classify instance
          .stateQuery(perceptronModel, new Fields("instance"), new ClassifyQuery<Boolean>("perceptron"), new Fields("prediction")).project(new Fields("prediction"));

      // Evaluation stream
      toppology.newDRPCStream("evaluate", localDRPC) //
          .stateQuery(perceptronEvaluation, new EvaluationQuery<Boolean>(), new Fields("eval")) //
          .project(new Fields("eval"));

      cluster.submitTopology(this.getClass().getSimpleName(), new Config(), toppology.build());
      Thread.sleep(4000);

      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 0.0 0.0")));
      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 0.0 1.0")));
      assertEquals(Boolean.TRUE, extractPrediction(localDRPC.execute("predict", "1.0 1.0 0.0")));
      assertEquals(Boolean.FALSE, extractPrediction(localDRPC.execute("predict", "1.0 1.0 1.0")));

      Double evaluation = extractEvaluation(localDRPC.execute("evaluate", ""));
      assertTrue(evaluation > 0.9);
      assertTrue(evaluation < 1);
    } finally {
      cluster.shutdown();
      localDRPC.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of backtype.storm.LocalDRPC

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.