org.apache.storm.utils.Utils.sleep()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.apache.storm.utils.Utils.sleep()方法的一些代码示例,展示了Utils.sleep()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.sleep()方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:sleep

Utils.sleep介绍

暂无

代码示例

代码示例来源:origin: apache/storm

public void nextTuple() {
  Utils.sleep(100);
}

代码示例来源:origin: apache/storm

public void nextTuple() {
  if (_serveTuples.size() > 0) {
    FixedTuple ft = _serveTuples.remove(0);
    String id = UUID.randomUUID().toString();
    _pending.put(id, ft);
    _collector.emit(ft.stream, ft.values, id);
  } else {
    Utils.sleep(100);
  }
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Long now = System.currentTimeMillis();
  List<Object> tuple = Collections.singletonList(now);
  collector.emit(tuple, now);
  Utils.sleep(sleepTimeMs);
}

代码示例来源:origin: apache/storm

public void downloadResourcesAsSupervisorImpl(String key, String localFile,
                         ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException, IOException {
    final int MAX_RETRY_ATTEMPTS = 2;
    final int ATTEMPTS_INTERVAL_TIME = 100;
    for (int retryAttempts = 0; retryAttempts < MAX_RETRY_ATTEMPTS; retryAttempts++) {
      if (downloadResourcesAsSupervisorAttempt(cb, key, localFile)) {
        break;
      }
      Utils.sleep(ATTEMPTS_INTERVAL_TIME);
    }
  }
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(5000);
  for (Values v : values.get(index)) {
    collector.emit(v);
  }
  index = (index + 1) % values.size();
}

代码示例来源:origin: apache/storm

@Override
  public boolean isReady(long txid) {
    if (!_waitToEmit) {
      return true;
    }
    List allBatches = (List) RegisteredGlobalState.getState(_id);
    if (allBatches.size() > _masterEmitted) {
      _masterEmitted++;
      return true;
    } else {
      Utils.sleep(2);
      return false;
    }
  }
}

代码示例来源:origin: apache/storm

public void nextTuple() {
  Utils.sleep(100);
  final String[] words = new String[]{ "nathan", "mike", "jackson", "golda", "bertels" };
  final Random rand = new Random();
  final String word = words[rand.nextInt(words.length)];
  _collector.emit(new Values(word));
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(100);
  collector.emit(new Values(rand.nextInt(1000), System.currentTimeMillis() - (24 * 60 * 60 * 1000), ++msgId), msgId);
}

代码示例来源:origin: apache/storm

public void nextTuple() {
  String[] user = sentences[index].split(",");
  Values values = new Values(Integer.parseInt(user[0]),user[1],user[2],user[3],user[4],user[5]);
  UUID msgId = UUID.randomUUID();
  this.pending.put(msgId, values);
  this.collector.emit(values, msgId);
  index++;
  if (index >= sentences.length) {
    index = 0;
  }
  count++;
  total++;
  if(count > 1000){
Utils.sleep(1000);
    count = 0;
    System.out.println("Pending count: " + this.pending.size() + ", total: " + this.total);
  }
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(2000);
  for (String word : words) {
    collector.emit(new Values(word));
  }
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(100);
  _collector.emit(new Values(getRandomSentence()));
}

代码示例来源:origin: apache/storm

public void waitTopologyScheduled(String topoName, ILocalCluster cluster, int retryAttempts) throws TException {
  for (int i = 0; i < retryAttempts; i++) {
    if (checkTopologyScheduled(topoName, cluster)) {
      //sleep to prevent race conditions
      Utils.sleep(SLEEP_TIME_BETWEEN_RETRY);
      return;
    }
    Utils.sleep(SLEEP_TIME_BETWEEN_RETRY);
  }
  throw new RuntimeException("Error: Wait for topology " + topoName + " to be ACTIVE has timed out!");
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(990);
  collector.emit(new Values(i, function.apply(i)));
  i++;
}

代码示例来源:origin: apache/storm

public void nextTuple() {
  Utils.sleep(100);
  final String[] words = new String[]{ "nathan", "mike", "jackson", "golda", "bertels" };
  final Random rand = new Random();
  final String word = words[rand.nextInt(words.length)];
  _collector.emit(new Values(word));
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(100);
  String[] sentences = new String[]{
    sentence("the cow jumped over the moon"), sentence("an apple a day keeps the doctor away"),
    sentence("four score and seven years ago"), sentence("snow white and the seven dwarfs"), sentence("i am at two with nature")
  };
  final String sentence = sentences[_rand.nextInt(sentences.length)];
  LOG.debug("Emitting tuple: {}", sentence);
  _collector.emit(new Values(sentence));
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  Utils.sleep(10);
  String[] sentences = new String[]{
    sentence("the cow jumped over the moon"), sentence("an apple a day keeps the doctor away"),
    sentence("four score and seven years ago"),
    sentence("snow white and the seven dwarfs"), sentence("i am at two with nature")
  };
  final String sentence = sentences[random.nextInt(sentences.length)];
  this.collector.emit(new Values(sentence), UUID.randomUUID());
}

代码示例来源:origin: apache/storm

public void nextTuple() {
  Utils.sleep(100);
  final String[] words = new String[]{"nathan", "mike", "jackson", "golda", "bertels"};
  final Random rand = new Random();
  final String word = words[rand.nextInt(words.length)];
  _collector.emit(new Values(word));
}

代码示例来源:origin: apache/storm

@Override
public void nextTuple() {
  if (shouldRecover()) {
    handleRecovery();
    startProgress();
  } else if (shouldCheckpoint()) {
    doCheckpoint();
    startProgress();
  } else {
    Utils.sleep(sleepInterval);
  }
}

代码示例来源:origin: apache/storm

@Test(timeout = 10000)
public void testConcurrentGet() throws Exception {
  List<Integer> loaded = new ArrayList<>();
  SimpleWindowPartitionCache<Integer, Object> cache =
    SimpleWindowPartitionCache.<Integer, Object>newBuilder()
      .maximumSize(1)
      .build(key -> {
        Utils.sleep(1000);
        loaded.add(key);
        return new Object();
      });
  FutureTask<Object> ft1 = new FutureTask<>(() -> cache.pinAndGet(1));
  FutureTask<Object> ft2 = new FutureTask<>(() -> cache.pinAndGet(1));
  Thread t1 = new Thread(ft1);
  Thread t2 = new Thread(ft2);
  t1.start();
  t2.start();
  t1.join();
  t2.join();
  Assert.assertEquals(Collections.singletonList(1), loaded);
  Assert.assertEquals(ft1.get(), ft2.get());
}

代码示例来源:origin: apache/storm

/**
 * Create a new topology that writes random UUIDs to Kafka.
 *
 * @param brokerUrl Kafka broker URL
 * @param topicName Topic to which publish sentences
 * @return A Storm topology that produces random UUIDs using a {@link LambdaSpout} and uses a {@link KafkaBolt} to publish the UUIDs to
 *     the kafka topic specified
 */
public static StormTopology newTopology(String brokerUrl, String topicName) {
  final TopologyBuilder builder = new TopologyBuilder();
  builder.setSpout("spout", () -> {
    Utils.sleep(1000); //Throttle this spout a bit to avoid maxing out CPU
    return UUID.randomUUID().toString();
  });
  /* The output field of the spout ("lambda") is provided as the boltMessageField
   so that this gets written out as the message in the kafka topic.
   The tuples have no key field, so the messages are written to Kafka without a key.*/
  final KafkaBolt<String, String> bolt = new KafkaBolt<String, String>()
    .withProducerProperties(newProps(brokerUrl, topicName))
    .withTopicSelector(new DefaultTopicSelector(topicName))
    .withTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper<>("key", "lambda"));
  builder.setBolt("forwardToKafka", bolt, 1).shuffleGrouping("spout");
  return builder.createTopology();
}

相关文章

微信公众号

最新文章

更多

Utils类方法