Fixing stylecheck problems with storm-hbase-examples
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/f4ba7c95 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/f4ba7c95 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/f4ba7c95 Branch: refs/heads/master Commit: f4ba7c952825ef7b0ee10bd1861dd0f288fe7761 Parents: 880d14f Author: Kishor Patil <[email protected]> Authored: Sun Apr 22 23:11:24 2018 -0400 Committer: Kishor Patil <[email protected]> Committed: Mon Apr 23 02:32:25 2018 -0400 ---------------------------------------------------------------------- examples/storm-hbase-examples/pom.xml | 5 +- .../storm/hbase/topology/LookupWordCount.java | 28 ++++------ .../hbase/topology/PersistentWordCount.java | 36 ++++++------- .../storm/hbase/topology/TotalWordCounter.java | 31 +++++------ .../storm/hbase/topology/WordCountClient.java | 21 +++----- .../hbase/topology/WordCountValueMapper.java | 43 +++++++-------- .../storm/hbase/topology/WordCounter.java | 22 +++----- .../apache/storm/hbase/topology/WordSpout.java | 28 ++++------ .../storm/hbase/trident/PrintFunction.java | 28 ++++------ .../storm/hbase/trident/WordCountTrident.java | 57 +++++++++----------- 10 files changed, 124 insertions(+), 175 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/pom.xml ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/pom.xml b/examples/storm-hbase-examples/pom.xml index 458d71d..16953e2 100644 --- a/examples/storm-hbase-examples/pom.xml +++ b/examples/storm-hbase-examples/pom.xml @@ -15,7 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -89,7 +90,7 @@ <artifactId>maven-checkstyle-plugin</artifactId> <!--Note - the version would be inherited--> <configuration> - <maxAllowedViolations>55</maxAllowedViolations> + <maxAllowedViolations>16</maxAllowedViolations> </configuration> </plugin> </plugins> http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/LookupWordCount.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/LookupWordCount.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/LookupWordCount.java index a10f34f..1c365c4 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/LookupWordCount.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/LookupWordCount.java @@ -1,25 +1,19 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; import java.util.HashMap; import java.util.Map; - import org.apache.storm.Config; import org.apache.storm.StormSubmitter; import org.apache.storm.hbase.bolt.HBaseLookupBolt; @@ -38,7 +32,7 @@ public class LookupWordCount { Config config = new Config(); Map<String, Object> hbConf = new HashMap<String, Object>(); - if(args.length > 0){ + if (args.length > 0) { hbConf.put("hbase.rootdir", args[0]); } config.put("hbase.conf", hbConf); @@ -53,8 +47,8 @@ public class LookupWordCount { WordCountValueMapper rowToTupleMapper = new WordCountValueMapper(); HBaseLookupBolt hBaseLookupBolt = new HBaseLookupBolt("WordCount", mapper, rowToTupleMapper) - .withConfigKey("hbase.conf") - .withProjectionCriteria(projectionCriteria); + .withConfigKey("hbase.conf") + .withProjectionCriteria(projectionCriteria); //wordspout -> lookupbolt -> totalCountBolt TopologyBuilder builder = new TopologyBuilder(); @@ -68,7 +62,7 @@ public class LookupWordCount { System.out.println("Usage: LookupWordCount <hbase.rootdir>"); return; } - + StormSubmitter.submitTopology(topoName, config, builder.createTopology()); } } http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/PersistentWordCount.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/PersistentWordCount.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/PersistentWordCount.java index 700a7cc..65de922 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/PersistentWordCount.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/PersistentWordCount.java @@ -1,26 +1,20 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; import java.util.HashMap; import java.util.Map; - import org.apache.storm.Config; import org.apache.storm.StormSubmitter; import org.apache.storm.hbase.bolt.HBaseBolt; @@ -40,7 +34,7 @@ public class PersistentWordCount { Config config = new Config(); Map<String, Object> hbConf = new HashMap<String, Object>(); - if(args.length > 0){ + if (args.length > 0) { hbConf.put("hbase.rootdir", args[0]); } config.put("hbase.conf", hbConf); @@ -49,13 +43,13 @@ public class PersistentWordCount { WordCounter bolt = new WordCounter(); SimpleHBaseMapper mapper = new SimpleHBaseMapper() - .withRowKeyField("word") - .withColumnFields(new Fields("word")) - .withCounterFields(new Fields("count")) - .withColumnFamily("cf"); + .withRowKeyField("word") + .withColumnFields(new Fields("word")) + .withCounterFields(new Fields("count")) + .withColumnFamily("cf"); HBaseBolt hbase = new HBaseBolt("WordCount", mapper) - .withConfigKey("hbase.conf"); + .withConfigKey("hbase.conf"); // wordSpout ==> countBolt ==> HBaseBolt @@ -69,8 +63,8 @@ public class PersistentWordCount { if (args.length == 2) { topoName = args[0]; } else if (args.length == 4) { - System.out.println("hdfs url: " + args[0] + ", keytab file: " + args[2] + - ", principal name: " + args[3] + ", toplogy name: " + args[1]); + System.out.println("hdfs url: " + args[0] + ", keytab file: " + args[2] + + ", principal name: " + args[3] + ", toplogy name: " + args[1]); hbConf.put(HBaseSecurityUtil.STORM_KEYTAB_FILE_KEY, args[2]); hbConf.put(HBaseSecurityUtil.STORM_USER_NAME_KEY, args[3]); config.setNumWorkers(3); http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/TotalWordCounter.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/TotalWordCounter.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/TotalWordCounter.java index c107282..313340a 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/TotalWordCounter.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/TotalWordCounter.java @@ -1,22 +1,20 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; +import java.math.BigInteger; +import java.util.Map; +import java.util.Random; import org.apache.storm.task.TopologyContext; import org.apache.storm.topology.BasicOutputCollector; import org.apache.storm.topology.IBasicBolt; @@ -26,17 +24,14 @@ import org.apache.storm.tuple.Tuple; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.Map; -import java.util.Random; - import static org.apache.storm.utils.Utils.tuple; public class TotalWordCounter implements IBasicBolt { - private BigInteger total = BigInteger.ZERO; private static final Logger LOG = LoggerFactory.getLogger(TotalWordCounter.class); private static final Random RANDOM = new Random(); + private BigInteger total = BigInteger.ZERO; + public void prepare(Map<String, Object> topoConf, TopologyContext context) { } @@ -48,7 +43,7 @@ public class TotalWordCounter implements IBasicBolt { total = total.add(new BigInteger(input.getValues().get(1).toString())); collector.emit(tuple(total.toString())); //prints the total with low probability. - if(RANDOM.nextInt(1000) > 995) { + if (RANDOM.nextInt(1000) > 995) { LOG.info("Running total = " + total); } } http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountClient.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountClient.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountClient.java index 33ce450..b7874bd 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountClient.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountClient.java @@ -1,20 +1,15 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; import org.apache.hadoop.conf.Configuration; @@ -33,7 +28,7 @@ public class WordCountClient { public static void main(String[] args) throws Exception { Configuration config = HBaseConfiguration.create(); - if(args.length > 0){ + if (args.length > 0) { config.set("hbase.rootdir", args[0]); } http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountValueMapper.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountValueMapper.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountValueMapper.java index 6c3301b..15ece78 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountValueMapper.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCountValueMapper.java @@ -1,39 +1,33 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; -import org.apache.storm.topology.OutputFieldsDeclarer; -import org.apache.storm.tuple.Fields; -import org.apache.storm.tuple.ITuple; -import org.apache.storm.tuple.Values; +import java.util.ArrayList; +import java.util.List; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.util.Bytes; import org.apache.storm.hbase.bolt.mapper.HBaseValueMapper; - -import java.util.ArrayList; -import java.util.List; +import org.apache.storm.topology.OutputFieldsDeclarer; +import org.apache.storm.tuple.Fields; +import org.apache.storm.tuple.ITuple; +import org.apache.storm.tuple.Values; /** - * Takes a Hbase result and returns a value list that has a value instance for each column and corresponding value. - * So if the result from Hbase was + * Takes a Hbase result and returns a value list that has a value instance for each column and corresponding value. So if the result from + * Hbase was * <pre> * WORD, COUNT * apple, 10 @@ -47,7 +41,6 @@ import java.util.List; * [WORD, banana] * [COUNT, 20] * </pre> - * */ public class WordCountValueMapper implements HBaseValueMapper { @@ -55,8 +48,8 @@ public class WordCountValueMapper implements HBaseValueMapper { public List<Values> toValues(ITuple tuple, Result result) throws Exception { List<Values> values = new ArrayList<Values>(); Cell[] cells = result.rawCells(); - for(Cell cell : cells) { - Values value = new Values (Bytes.toString(CellUtil.cloneQualifier(cell)), Bytes.toLong(CellUtil.cloneValue(cell))); + for (Cell cell : cells) { + Values value = new Values(Bytes.toString(CellUtil.cloneQualifier(cell)), Bytes.toLong(CellUtil.cloneValue(cell))); values.add(value); } return values; @@ -64,7 +57,7 @@ public class WordCountValueMapper implements HBaseValueMapper { @Override public void declareOutputFields(OutputFieldsDeclarer declarer) { - declarer.declare(new Fields("columnName","columnValue")); + declarer.declare(new Fields("columnName", "columnValue")); } } http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCounter.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCounter.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCounter.java index 5c71ade..933cc49 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCounter.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordCounter.java @@ -1,22 +1,18 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; +import java.util.Map; import org.apache.storm.task.TopologyContext; import org.apache.storm.topology.BasicOutputCollector; import org.apache.storm.topology.IBasicBolt; @@ -24,8 +20,6 @@ import org.apache.storm.topology.OutputFieldsDeclarer; import org.apache.storm.tuple.Fields; import org.apache.storm.tuple.Tuple; -import java.util.Map; - import static org.apache.storm.utils.Utils.tuple; public class WordCounter implements IBasicBolt { http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordSpout.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordSpout.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordSpout.java index bcc9642..3e407d6 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordSpout.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/topology/WordSpout.java @@ -1,22 +1,20 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.topology; +import java.util.Map; +import java.util.Random; +import java.util.UUID; import org.apache.storm.spout.SpoutOutputCollector; import org.apache.storm.task.TopologyContext; import org.apache.storm.topology.IRichSpout; @@ -24,14 +22,10 @@ import org.apache.storm.topology.OutputFieldsDeclarer; import org.apache.storm.tuple.Fields; import org.apache.storm.tuple.Values; -import java.util.Map; -import java.util.Random; -import java.util.UUID; - public class WordSpout implements IRichSpout { + public static final String[] words = new String[]{ "apple", "orange", "pineapple", "banana", "watermelon" }; boolean isDistributed; SpoutOutputCollector collector; - public static final String[] words = new String[] { "apple", "orange", "pineapple", "banana", "watermelon" }; public WordSpout() { this(true); http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/PrintFunction.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/PrintFunction.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/PrintFunction.java index cdc7690..7285e54 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/PrintFunction.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/PrintFunction.java @@ -1,29 +1,23 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.trident; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Random; import org.apache.storm.trident.operation.BaseFunction; import org.apache.storm.trident.operation.TridentCollector; import org.apache.storm.trident.tuple.TridentTuple; - -import java.util.Random; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PrintFunction extends BaseFunction { @@ -33,7 +27,7 @@ public class PrintFunction extends BaseFunction { @Override public void execute(TridentTuple tuple, TridentCollector tridentCollector) { - if(RANDOM.nextInt(1000) > 995) { + if (RANDOM.nextInt(1000) > 995) { LOG.info(tuple.toString()); } } http://git-wip-us.apache.org/repos/asf/storm/blob/f4ba7c95/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/WordCountTrident.java ---------------------------------------------------------------------- diff --git a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/WordCountTrident.java b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/WordCountTrident.java index c81512e..4861765 100644 --- a/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/WordCountTrident.java +++ b/examples/storm-hbase-examples/src/main/java/org/apache/storm/hbase/trident/WordCountTrident.java @@ -1,20 +1,15 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. */ + package org.apache.storm.hbase.trident; import org.apache.hadoop.hbase.client.Durability; @@ -39,21 +34,21 @@ import org.apache.storm.tuple.Fields; import org.apache.storm.tuple.Values; public class WordCountTrident { - public static StormTopology buildTopology(String hbaseRoot){ + public static StormTopology buildTopology(String hbaseRoot) { Fields fields = new Fields("word", "count"); FixedBatchSpout spout = new FixedBatchSpout(fields, 4, - new Values("storm", 1), - new Values("trident", 1), - new Values("needs", 1), - new Values("javadoc", 1) + new Values("storm", 1), + new Values("trident", 1), + new Values("needs", 1), + new Values("javadoc", 1) ); spout.setCycle(true); TridentHBaseMapper tridentHBaseMapper = new SimpleTridentHBaseMapper() - .withColumnFamily("cf") - .withColumnFields(new Fields("word")) - .withCounterFields(new Fields("count")) - .withRowKeyField("word"); + .withColumnFamily("cf") + .withColumnFields(new Fields("word")) + .withCounterFields(new Fields("count")) + .withRowKeyField("word"); HBaseValueMapper rowToStormValueMapper = new WordCountValueMapper(); @@ -61,23 +56,23 @@ public class WordCountTrident { projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count")); HBaseState.Options options = new HBaseState.Options() - .withConfigKey(hbaseRoot) - .withDurability(Durability.SYNC_WAL) - .withMapper(tridentHBaseMapper) - .withProjectionCriteria(projectionCriteria) - .withRowToStormValueMapper(rowToStormValueMapper) - .withTableName("WordCount"); + .withConfigKey(hbaseRoot) + .withDurability(Durability.SYNC_WAL) + .withMapper(tridentHBaseMapper) + .withProjectionCriteria(projectionCriteria) + .withRowToStormValueMapper(rowToStormValueMapper) + .withTableName("WordCount"); StateFactory factory = new HBaseStateFactory(options); TridentTopology topology = new TridentTopology(); Stream stream = topology.newStream("spout1", spout); - stream.partitionPersist(factory, fields, new HBaseUpdater(), new Fields()); + stream.partitionPersist(factory, fields, new HBaseUpdater(), new Fields()); TridentState state = topology.newStaticState(factory); - stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName","columnValue")); - stream.each(new Fields("word","columnValue"), new PrintFunction(), new Fields()); + stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName", "columnValue")); + stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields()); return topology.build(); } @@ -85,7 +80,7 @@ public class WordCountTrident { Config conf = new Config(); conf.setMaxSpoutPending(5); String topoName = "wordCounter"; - + if (args.length == 2) { topoName = args[1]; } else if (args.length > 2) {
