本文整理匯總了Java中backtype.storm.utils.Utils類的典型用法代碼示例。如果您正苦於以下問題:Java Utils類的具體用法?Java Utils怎麽用?Java Utils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Utils類屬於backtype.storm.utils包,在下文中一共展示了Utils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Override
public void run() {
try {
while (true) {
long now = System.currentTimeMillis();
if (!_supervisorViewOfAssignedPorts.get().isEmpty()) {
_lastTime = now;
}
if ((now - _lastTime) > 1000L * _timeoutSecs) {
LOG.info("Supervisor has not had anything assigned for {} secs. Committing suicide...", _timeoutSecs);
Runtime.getRuntime().halt(0);
}
Utils.sleep(5000);
}
} catch (Throwable t) {
LOG.error(t.getMessage());
Runtime.getRuntime().halt(2);
}
}
示例2: nextTuple
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Override
public void nextTuple() {
long thisSecond;
// find out if a new second has started and if so
thisSecond = System.currentTimeMillis() / 1000;
if (thisSecond != this.lastSecond) {
// a new second has started
this.lastSecond = thisSecond;
this.tuplesRemainingThisSecond = this.tuplesPerSecond;
}
this.tuplesRemainingThisSecond--; // bookkeeping
if (this.tuplesRemainingThisSecond > 0) { // emit if possible
super.nextTuple();
} else { // throttle if necessary
/** we should wait 1ms. {@see backtype.storm.spout.ISpout#nextTuple()} */
Utils.sleep(1);
}
}
示例3: main
import backtype.storm.utils.Utils; //導入依賴的package包/類
public static void main(String[] args) throws SQLException {
// tableName is the name of the table in splice to insert records to
// server is the server instance running splice
String tableName = "students";
String server = "localhost";
TopologyBuilder builder = new TopologyBuilder();
// set the spout for the topology
builder.setSpout("seedDataFromMySql", new MySqlSpout());
// dump the stream data into splice
builder.setBolt("dbRowProcessing", new MySqlSpliceBolt(server, tableName), 1).shuffleGrouping("seedDataFromMySql");
Config conf = new Config();
conf.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("mysql-splice-topology", conf, builder.createTopology());
Utils.sleep(3000);
cluster.shutdown();
}
示例4: nextTuple
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Override
public void nextTuple() {
Utils.sleep(1000);
String[] words = new String[]{"splice", "machine", "hadoop", "rdbms", "acid", "sql", "transactions"};
Integer[] numbers = new Integer[]{
1, 2, 3, 4, 5, 6, 7
};
if (count == numbers.length - 1) {
count = 0;
}
count++;
int number = numbers[count];
String word = words[count];
int randomNum = (int) (Math.random() * 1000);
System.out.println("Random Number: " + randomNum);
System.out.println("SpliceIntegerSpout emitting: " + number);
_collector.emit(new Values(word, number));
}
示例5: nextTuple
import backtype.storm.utils.Utils; //導入依賴的package包/類
public void nextTuple() {
if (bufferQueue.isEmpty()) {
// pass in mysql server, db name, user, password
seedBufferQueue("localhost", "test", "root", "");
Utils.sleep(100);
} else {
// Replace name with the data being extracted.
// This example expects only name to be returned in the sql/and thus is only item output by the spout.
// To add additional data add them to the values using new Values(value1, value2, etc) then emit the values
String name = bufferQueue.poll();
if (name != null) {
Values values = new Values();
values.add(name);
_collector.emit(values);
}
Utils.sleep(50);
}
}
示例6: testExecuteUnique
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Test
public void testExecuteUnique() {
IncSpout spout = new IncSpout(1);
TestSpoutOutputCollector collector = new TestSpoutOutputCollector();
spout.open(null, null, new SpoutOutputCollector(collector));
List<List<Object>> result = new LinkedList<List<Object>>();
for(int i = 0; i < 5; ++i) {
ArrayList<Object> attributes = new ArrayList<Object>();
attributes.add(new Long(i));
result.add(attributes);
spout.nextTuple();
}
Assert.assertEquals(result, collector.output.get(Utils.DEFAULT_STREAM_ID));
}
示例7: IdDictionary
import backtype.storm.utils.Utils; //導入依賴的package包/類
public IdDictionary(StormTopology topology) {
List<String> componentNames = new ArrayList<String>(topology
.get_spouts().keySet());
componentNames.addAll(topology.get_bolts().keySet());
componentNames.addAll(topology.get_state_spouts().keySet());
for (String name : componentNames) {
ComponentCommon common = Utils.getComponentCommon(topology,
name);
List<String> streams = new ArrayList<String>(common
.get_streams().keySet());
streamNametoId.put(name, idify(streams));
streamIdToName.put(name,
Utils.reverseMap(streamNametoId.get(name)));
}
}
示例8: update_storm
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Override
public void update_storm(String topologyId, StormStatus newElems)
throws Exception {
/**
* , not sure where the old exist error or not The raw code
* (set-data cluster-state (storm-path storm-id) (-> (storm-base this
* storm-id nil) (merge new-elems) Utils/serialize)))
*/
StormBase base = this.storm_base(topologyId, null);
if (base != null) {
base.setStatus(newElems);
cluster_state.set_data(Cluster.storm_path(topologyId),
Utils.serialize(base));
}
}
示例9: maxTopologyMessageTimeout
import backtype.storm.utils.Utils; //導入依賴的package包/類
public int maxTopologyMessageTimeout() {
Integer max = Utils.getInt(_stormConf
.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS));
for (String spout : getRawTopology().get_spouts().keySet()) {
ComponentCommon common = getComponentCommon(spout);
String jsonConf = common.get_json_conf();
if (jsonConf != null) {
Map conf = (Map) Utils.from_json(jsonConf);
Object comp = conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS);
if (comp != null) {
max = Math.max(Utils.getInt(comp), max);
}
}
}
return max;
}
示例10: submitRebalance
import backtype.storm.utils.Utils; //導入依賴的package包/類
public static void submitRebalance(String topologyName, RebalanceOptions options, Map conf) throws Exception {
Map stormConf = Utils.readStormConfig();
if (conf != null) {
stormConf.putAll(conf);
}
NimbusClient client = null;
try {
client = NimbusClient.getConfiguredClient(stormConf);
client.getClient().rebalance(topologyName, options);
} catch (Exception e) {
throw e;
} finally {
if (client != null) {
client.close();
}
}
}
示例11: open
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Override
public void open(Map conf, TopologyContext context,
SpoutOutputCollector collector) {
_collector = collector;
if (_local_drpc_id == null) {
int numTasks = context.getComponentTasks(
context.getThisComponentId()).size();
int index = context.getThisTaskIndex();
int port = Utils.getInt(conf.get(Config.DRPC_INVOCATIONS_PORT));
List<String> servers = (List<String>) conf.get(Config.DRPC_SERVERS);
if (servers == null || servers.isEmpty()) {
throw new RuntimeException(
"No DRPC servers configured for topology");
}
if (numTasks < servers.size()) {
for (String s : servers) {
_clients.add(new DRPCInvocationsClient(s, port));
}
} else {
int i = index % servers.size();
_clients.add(new DRPCInvocationsClient(servers.get(i), port));
}
}
}
示例12: genBoltIds
import backtype.storm.utils.Utils; //導入依賴的package包/類
private static Map<Group, String> genBoltIds(Collection<Group> groups) {
Map<Group, String> ret = new HashMap();
int ctr = 0;
for(Group g: groups) {
if(!isSpoutGroup(g)) {
List<String> name = new ArrayList();
name.add("b");
name.add("" + ctr);
String groupName = getGroupName(g);
if(groupName!=null && !groupName.isEmpty()) {
name.add(getGroupName(g));
}
ret.put(g, Utils.join(name, "-"));
ctr++;
}
}
return ret;
}
示例13: finishBatch
import backtype.storm.utils.Utils; //導入依賴的package包/類
private boolean finishBatch(TrackedBatch tracked, Tuple finishTuple) {
boolean success = true;
try {
_bolt.finishBatch(tracked.info);
String stream = COORD_STREAM(tracked.info.batchGroup);
for(Integer task: tracked.condition.targetTasks) {
_collector.emitDirect(task, stream, finishTuple, new Values(tracked.info.batchId, Utils.get(tracked.taskEmittedTuples, task, 0)));
}
if(tracked.delayedAck!=null) {
_collector.ack(tracked.delayedAck);
tracked.delayedAck = null;
}
} catch(FailedException e) {
failBatch(tracked, e);
success = false;
}
_batches.remove(tracked.info.batchId.getId());
return success;
}
示例14: main
import backtype.storm.utils.Utils; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new TestWordSpout(), 10);
builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("word");
builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(3);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
}
else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Utils.sleep(10000);
cluster.killTopology("test");
cluster.shutdown();
}
}
示例15: testExecuteMultipleStreams
import backtype.storm.utils.Utils; //導入依賴的package包/類
@Test
public void testExecuteMultipleStreams() {
int numberOfAttributes = 1 + this.r.nextInt(10);
String[] streamIds = new String[] {Utils.DEFAULT_STREAM_ID, "myStreamId"};
RandomSpout spout = new RandomSpout(numberOfAttributes, 100, streamIds);
TestSpoutOutputCollector collector = new TestSpoutOutputCollector();
spout.open(null, null, new SpoutOutputCollector(collector));
for(int i = 0; i < 50; ++i) {
spout.nextTuple();
for(String stream : streamIds) {
Assert.assertTrue(collector.output.get(stream).size() == i + 1); // size of result
Assert.assertTrue(collector.output.get(stream).get(i).size() == numberOfAttributes);
for(int j = 0; j < numberOfAttributes; ++j) {
Assert.assertTrue(0 < ((Integer)collector.output.get(stream).get(i).get(j)).intValue());
Assert.assertTrue(100 >= ((Integer)collector.output.get(stream).get(i).get(j)).intValue());
}
}
}
}