// Path: src/main/java/storm/benchmark/lib/spout/pageview/PageView.java
// public class PageView {
//   private static Logger LOG = Logger.getLogger(PageView.class);
//   public final String url;
//   public final int status;
//   public final int zipCode;
//   public final int userID;
// 
//   public PageView(String url, int status, int zipCode, int userID) {
//     this.url = url;
//     this.status = status;
//     this.zipCode = zipCode;
//     this.userID = userID;
//   }
// 
//   @Override
//   public String toString() {
//     return String.format("%s\t%d\t%d\t%d", url, status, zipCode, userID);
//   }
// 
//   public static PageView fromString(String pv) {
//     LOG.debug("get string '" + pv + "'");
//     String[] parts = pv.split("\t");
//     if (parts.length < 4) {
//       return null;
//     }
//     for (int i = 0; i < parts.length; i++) {
//       parts[i] = parts[i].trim();
//     }
//     return new PageView(parts[0],
//             Integer.parseInt(parts[1]),
//             Integer.parseInt(parts[2]),
//             Integer.parseInt(parts[3]));
//   }
// 
//   public Object getValue(Item field) {
//     switch (field) {
//       case URL:
//         return url;
//       case STATUS:
//         return status;
//       case ZIP:
//         return zipCode;
//       case USER:
//         return userID;
//       case ONE:
//         return 1;
//       default:
//         return toString();
//     }
//   }
// 
//   public static enum Item {
//     ALL("page_view"),
//     URL("url"),
//     STATUS("http_status"),
//     ZIP("zip_code"),
//     USER("user_id"),
//     ONE("count_one");
// 
//     private final String name;
// 
//     Item(String name) {
//       this.name = name;
//     }
// 
//     @Override
//     public String toString() {
//       return name;
//     }
//   }
// 
//   public static class Extract extends BaseFunction {
// 
//     private final List<Item> fields;
// 
//     public Extract(List<Item> fields) {
//       this.fields = fields;
//     }
// 
//     @Override
//     public void execute(TridentTuple tuple, TridentCollector collector) {
//       String pvString = tuple.getString(0);
//       PageView pageView = PageView.fromString(pvString);
//       if (null == pageView) {
//         LOG.error("invalid pageview string '" + pvString + "'");
//         return;
//       }
//       List<Object> values = new ArrayList<Object>();
//       for (Item field : fields) {
//         values.add(pageView.getValue(field));
//       }
//       collector.emit(values);
//     }
//   }
// }
// 
// Path: src/main/java/storm/benchmark/lib/spout/pageview/PageView.java
// public static enum Item {
//   ALL("page_view"),
//   URL("url"),
//   STATUS("http_status"),
//   ZIP("zip_code"),
//   USER("user_id"),
//   ONE("count_one");
// 
//   private final String name;
// 
//   Item(String name) {
//     this.name = name;
//   }
// 
//   @Override
//   public String toString() {
//     return name;
//   }
// }


import backtype.storm.topology.BasicOutputCollector;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseBasicBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;
import storm.benchmark.lib.spout.pageview.PageView;
import static storm.benchmark.lib.spout.pageview.PageView.Item;
/*
 * 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
 */

package storm.benchmark.lib.bolt;


/**
 * the incoming tuple has a single pageview field consisting
 * of URL, (http) STATUS, ZIP and USER.
 * the outgoing tuple is composed of two fields, where each field
 * could be one of the above, the pageview itself or a count ONE.
 * This is flexible enough to feed downstream bolts for such use cases as
 * PageViewCount(URL, ONE) and UniqueVisitorCount(URL, USER)
 *
 */

public class PageViewBolt extends BaseBasicBolt {

  private static final long serialVersionUID = -523726932372993856L;
  public final Item field1;
  public final Item field2;

  public PageViewBolt(Item field1, Item field2) {
    this.field1 = field1;
    this.field2 = field2;
  }

  @Override
  public void execute(Tuple input, BasicOutputCollector collector) {
// Path: src/main/java/storm/benchmark/lib/spout/pageview/PageView.java
// public class PageView {
//   private static Logger LOG = Logger.getLogger(PageView.class);
//   public final String url;
//   public final int status;
//   public final int zipCode;
//   public final int userID;
// 
//   public PageView(String url, int status, int zipCode, int userID) {
//     this.url = url;
//     this.status = status;
//     this.zipCode = zipCode;
//     this.userID = userID;
//   }
// 
//   @Override
//   public String toString() {
//     return String.format("%s\t%d\t%d\t%d", url, status, zipCode, userID);
//   }
// 
//   public static PageView fromString(String pv) {
//     LOG.debug("get string '" + pv + "'");
//     String[] parts = pv.split("\t");
//     if (parts.length < 4) {
//       return null;
//     }
//     for (int i = 0; i < parts.length; i++) {
//       parts[i] = parts[i].trim();
//     }
//     return new PageView(parts[0],
//             Integer.parseInt(parts[1]),
//             Integer.parseInt(parts[2]),
//             Integer.parseInt(parts[3]));
//   }
// 
//   public Object getValue(Item field) {
//     switch (field) {
//       case URL:
//         return url;
//       case STATUS:
//         return status;
//       case ZIP:
//         return zipCode;
//       case USER:
//         return userID;
//       case ONE:
//         return 1;
//       default:
//         return toString();
//     }
//   }
// 
//   public static enum Item {
//     ALL("page_view"),
//     URL("url"),
//     STATUS("http_status"),
//     ZIP("zip_code"),
//     USER("user_id"),
//     ONE("count_one");
// 
//     private final String name;
// 
//     Item(String name) {
//       this.name = name;
//     }
// 
//     @Override
//     public String toString() {
//       return name;
//     }
//   }
// 
//   public static class Extract extends BaseFunction {
// 
//     private final List<Item> fields;
// 
//     public Extract(List<Item> fields) {
//       this.fields = fields;
//     }
// 
//     @Override
//     public void execute(TridentTuple tuple, TridentCollector collector) {
//       String pvString = tuple.getString(0);
//       PageView pageView = PageView.fromString(pvString);
//       if (null == pageView) {
//         LOG.error("invalid pageview string '" + pvString + "'");
//         return;
//       }
//       List<Object> values = new ArrayList<Object>();
//       for (Item field : fields) {
//         values.add(pageView.getValue(field));
//       }
//       collector.emit(values);
//     }
//   }
// }
// 
// Path: src/main/java/storm/benchmark/lib/spout/pageview/PageView.java
// public static enum Item {
//   ALL("page_view"),
//   URL("url"),
//   STATUS("http_status"),
//   ZIP("zip_code"),
//   USER("user_id"),
//   ONE("count_one");
// 
//   private final String name;
// 
//   Item(String name) {
//     this.name = name;
//   }
// 
//   @Override
//   public String toString() {
//     return name;
//   }
// }


// Path: src/main/java/storm/benchmark/lib/bolt/PageViewBolt.java
import backtype.storm.topology.BasicOutputCollector;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseBasicBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;
import storm.benchmark.lib.spout.pageview.PageView;
import static storm.benchmark.lib.spout.pageview.PageView.Item;

/*
 * 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
 */

package storm.benchmark.lib.bolt;


/**
 * the incoming tuple has a single pageview field consisting
 * of URL, (http) STATUS, ZIP and USER.
 * the outgoing tuple is composed of two fields, where each field
 * could be one of the above, the pageview itself or a count ONE.
 * This is flexible enough to feed downstream bolts for such use cases as
 * PageViewCount(URL, ONE) and UniqueVisitorCount(URL, USER)
 *
 */

public class PageViewBolt extends BaseBasicBolt {

  private static final long serialVersionUID = -523726932372993856L;
  public final Item field1;
  public final Item field2;

  public PageViewBolt(Item field1, Item field2) {
    this.field1 = field1;
    this.field2 = field2;
  }

  @Override
  public void execute(Tuple input, BasicOutputCollector collector) {
    PageView view = PageView.fromString(input.getString(0));