本文整理汇总了Java中org.apache.storm.utils.Utils类的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Utils类属于org.apache.storm.utils包,在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Override
public List<Object> deserialize(ByteBuffer ser) {
String jsonStr = null;
if (ser.hasArray()) {
int base = ser.arrayOffset();
jsonStr = new String(ser.array(), base + ser.position(), ser.remaining());
} else {
jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET);
}
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
Values values = new Values();
for (String outputField : outputFields) {
if("jsonBody".equals(outputField)) {
values.add(jsonStr);
} else {
if(!jsonObject.containsKey(outputField)) {
JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para"));
values.add(rcMsgpara.get(outputField));
} else {
values.add(jsonObject.get(outputField));
}
}
}
return values;
}
示例2: testFail
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Test
public void testFail() throws Exception {
setupExpectationsForTuple();
setupExpectationsForTopologyContextNoEmit();
EventCorrelatingOutputCollector sut = getSystemUnderTest();
Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(PARENT_STREAMLINE_EVENT), TASK_0,
Utils.DEFAULT_STREAM_ID);
sut.fail(anchor);
new Verifications() {{
mockedOutputCollector.fail(anchor); times = 1;
}};
}
示例3: setupOnce
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@BeforeClass
public static void setupOnce() throws Exception {
AbstractStormTest.setupOnce();
////////
Properties overlay = new Properties();
overlay.setProperty("filter.directory", server.tempDir.getAbsolutePath());
LaunchEnvironment env = makeLaunchEnvironment(overlay);
manager = new OFEventWFMTopology(env);
cluster.submitTopology(manager.makeTopologyName(), stormConfig(), manager.createTopology());
discoFiler = new KafkaFilerTopology(env, manager.getConfig().getKafkaTopoDiscoTopic());
cluster.submitTopology("utils-1", stormConfig(), discoFiler.createTopology());
Utils.sleep(5 * 1000);
////////
}
示例4: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("integer", new RandomIntegerSpout(), 1);
builder.setBolt("slidingsum", new SlidingWindowSumBolt().withWindow(new Count(30), new Count(10)), 1)
.shuffleGrouping("integer");
builder.setBolt("tumblingavg", new TumblingWindowAvgBolt().withTumblingWindow(new Count(3)), 1)
.shuffleGrouping("slidingsum");
builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("tumblingavg");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
} else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Utils.sleep(40000);
cluster.killTopology("test");
cluster.shutdown();
}
}
示例5: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new WordSpout(), 1);
builder.setBolt("exclaim", new ExclamationBolt(), 1).shuffleGrouping("word"); // Tuple流向:word 》 exclaim
builder.setBolt("print", new PrintBolt(), 1).shuffleGrouping("exclaim"); // exclaim 》 print
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(); // storm依赖,<scope>provided</scope>--> 本地开发是注释掉 -->
cluster.submitTopology("test3", conf, builder.createTopology());
Utils.sleep(60 * 1000);
cluster.killTopology("test3");
cluster.shutdown();
}
}
示例6: nextTuple
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Override
public void nextTuple() {
// Sleep for 1 second so the data rate
// is slower.
Utils.sleep(1000);
// Randomly emit device info
int temperature = _rand.nextInt(11) + 68; // There is a war over whether it's warm or cool in the house
int humidity = _rand.nextInt(11) + 35; // 35-45 being the recommended humitity in a house
int co2 = _rand.nextInt(600); // Indoor CO2 range
//Create a JSON document to send to Event Hub
// BECAUSE, I learned the hard way that if you don't
// put it in a nice format that things can interop with,
// then you have problems later when someone wants
// to read it into a C# app that uses a framework that
// expects JSON.
JSONObject message = new JSONObject();
message.put("temperature", temperature);
message.put("humidity", humidity);
message.put("co2level", co2);
//Emit the device
_collector.emit(new Values(message.toString()));
}
示例7: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(String[] args){
TopologyBuilder topologyBuilder = new TopologyBuilder();
topologyBuilder.setSpout(SPOUT_ID,new SentenceSpout());
topologyBuilder.setBolt(BOLT_ID_SENTENCE_SPLIT,new SentenceSplitBolt()).shuffleGrouping(SPOUT_ID);
topologyBuilder.setBolt(BOLT_ID_WORD_COUNT,new WordCountBlot()).fieldsGrouping(BOLT_ID_SENTENCE_SPLIT,new Fields("word"));
topologyBuilder.setBolt(BOLT_ID_COUNT_REPORT,new WordsReportBolt()).globalGrouping(BOLT_ID_WORD_COUNT);
Config config = new Config();
LocalCluster localCluster = new LocalCluster();
localCluster.submitTopology(TOPOLOGY_ID,config,topologyBuilder.createTopology());
//
Utils.sleep(10000);
localCluster.killTopology(TOPOLOGY_ID);
localCluster.shutdown();
}
示例8: testDeclare
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Test
public void testDeclare() {
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
int numberOfAttributes = this.r.nextInt(26);
declarer.declare(createSchema(numberOfAttributes));
Assert.assertEquals(1, declarer.outputSchemas.size());
Assert.assertEquals(numberOfAttributes, declarer.outputSchemas.get(Utils.DEFAULT_STREAM_ID)
.intValue());
final String sid = "streamId";
numberOfAttributes = this.r.nextInt(26);
declarer.declareStream(sid, createSchema(numberOfAttributes));
Assert.assertEquals(2, declarer.outputSchemas.size());
Assert.assertEquals(numberOfAttributes, declarer.outputSchemas.get(sid).intValue());
}
示例9: testRawType
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testRawType() throws Exception {
IComponent boltOrSpout;
if (this.r.nextBoolean()) {
boltOrSpout = mock(IRichSpout.class);
} else {
boltOrSpout = mock(IRichBolt.class);
}
final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
declarer.declare(new Fields("dummy1", "dummy2"));
PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
WrapperSetupHelper.getNumberOfAttributes(boltOrSpout,
new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)));
}
示例10: getTextDataStream
import org.apache.storm.utils.Utils; //导入依赖的package包/类
private static DataStream<String> getTextDataStream(final StreamExecutionEnvironment env) {
if (fileOutput) {
final String[] tokens = textPath.split(":");
final String inputFile = tokens[tokens.length - 1];
// set Storm configuration
StormConfig config = new StormConfig();
config.put(FiniteFileSpout.INPUT_FILE_PATH, inputFile);
env.getConfig().setGlobalJobParameters(config);
return env.addSource(
new SpoutWrapper<String>(new FiniteFileSpout(),
new String[] { Utils.DEFAULT_STREAM_ID }),
TypeExtractor.getForClass(String.class)).setParallelism(1);
}
return env.addSource(
new SpoutWrapper<String>(new FiniteInMemorySpout(
WordCountData.WORDS), new String[] { Utils.DEFAULT_STREAM_ID }),
TypeExtractor.getForClass(String.class)).setParallelism(1);
}
示例11: getTextDataStream
import org.apache.storm.utils.Utils; //导入依赖的package包/类
private static DataStream<String> getTextDataStream(final StreamExecutionEnvironment env) {
if (fileOutput) {
// read the text file from given input path
final String[] tokens = textPath.split(":");
final String localFile = tokens[tokens.length - 1];
return env.addSource(
new SpoutWrapper<String>(new WordCountFileSpout(localFile),
new String[] { Utils.DEFAULT_STREAM_ID }, -1),
TypeExtractor.getForClass(String.class)).setParallelism(1);
}
return env.addSource(
new SpoutWrapper<String>(new WordCountInMemorySpout(),
new String[] { Utils.DEFAULT_STREAM_ID }, -1),
TypeExtractor.getForClass(String.class)).setParallelism(1);
}
示例12: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(final String[] args) throws AlreadyAliveException, InvalidTopologyException,
NotAliveException {
if (!WordCountTopology.parseParameters(args)) {
return;
}
// build Topology the Storm way
final TopologyBuilder builder = WordCountTopology.buildTopology();
// execute program on Flink cluster
final Config conf = new Config();
// can be changed to remote address
conf.put(Config.NIMBUS_HOST, "localhost");
// use default flink jobmanger.rpc.port
conf.put(Config.NIMBUS_THRIFT_PORT, 6123);
final FlinkClient cluster = FlinkClient.getConfiguredClient(conf);
cluster.submitTopology(topologyId, uploadedJarLocation, FlinkTopology.createTopology(builder));
Utils.sleep(5 * 1000);
cluster.killTopology(topologyId);
}
示例13: testProgram
import org.apache.storm.utils.Utils; //导入依赖的package包/类
@Override
protected void testProgram() throws Exception {
final TopologyBuilder builder = new TopologyBuilder();
builder.setSpout(spoutId, new MetaDataSpout(), 2);
builder.setBolt(boltId1, new VerifyMetaDataBolt(), 2).localOrShuffleGrouping(spoutId,
MetaDataSpout.STREAM_ID);
builder.setBolt(boltId2, new VerifyMetaDataBolt()).shuffleGrouping(boltId1,
VerifyMetaDataBolt.STREAM_ID);
final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster();
cluster.submitTopology(topologyId, null, FlinkTopology.createTopology(builder));
// run topology for 5 seconds
Utils.sleep(5 * 1000);
cluster.shutdown();
Assert.assertFalse(VerifyMetaDataBolt.errorOccured);
}
示例14: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
if (!SplitSpoutTopology.parseParameters(args)) {
return;
}
// build Topology the Storm way
final TopologyBuilder builder = SplitSpoutTopology.buildTopology();
final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster();
cluster.submitTopology(topologyId, null, FlinkTopology.createTopology(builder));
// run topology for 5 seconds
Utils.sleep(5 * 1000);
cluster.shutdown();
}
示例15: main
import org.apache.storm.utils.Utils; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
if (!SplitBoltTopology.parseParameters(args)) {
return;
}
// build Topology the Storm way
final TopologyBuilder builder = SplitBoltTopology.buildTopology();
final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster();
cluster.submitTopology(topologyId, null, FlinkTopology.createTopology(builder));
// run topology for 5 seconds
Utils.sleep(5 * 1000);
cluster.shutdown();
}