├── target └── classes │ ├── log4j.properties │ └── redis.properties ├── src └── main │ ├── resources │ ├── log4j.properties │ └── redis.properties │ └── java │ └── cn │ └── xpleaf │ └── bigdata │ └── storm │ ├── constants │ └── JedisConstants.java │ ├── statistic │ ├── ConvertIPBolt.java │ ├── StatisticTopology.java │ └── StatisticBolt.java │ └── utils │ └── JedisUtil.java ├── .gitignore ├── README.md ├── storm-statistic.iml ├── pom.xml └── LICENSE /target/classes/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xpleaf/storm-statistic/HEAD/target/classes/log4j.properties -------------------------------------------------------------------------------- /target/classes/redis.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xpleaf/storm-statistic/HEAD/target/classes/redis.properties -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xpleaf/storm-statistic/HEAD/src/main/resources/log4j.properties -------------------------------------------------------------------------------- /src/main/resources/redis.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xpleaf/storm-statistic/HEAD/src/main/resources/redis.properties -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # storm-statistic 2 | The real time project of storm for counting the pv and uv of a web site. 3 | 4 | 对应我在51cto上发表的博文:http://blog.51cto.com/xpleaf/2104160 5 | 其基本架构如下: 6 | ![Flume+Kafka+Storm+Redis构建大数据实时处理系统:实时统计网站PV、UV+展示](http://i2.51cto.com/images/blog/201804/16/4213a5c3a29741e40cfb323622fc955d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 7 | -------------------------------------------------------------------------------- /src/main/java/cn/xpleaf/bigdata/storm/constants/JedisConstants.java: -------------------------------------------------------------------------------- 1 | package cn.xpleaf.bigdata.storm.constants; 2 | 3 | /** 4 | * 专门用于存放Jedis的常量类 5 | */ 6 | public interface JedisConstants { 7 | 8 | //表示jedis的服务器主机名 9 | String JEDIS_HOST = "jedis.host"; 10 | //表示jedis的服务的端口 11 | String JEDIS_PORT = "jedis.port"; 12 | //表示jedis的服务密码 13 | String JEDIS_PASSWORD = "jedis.password"; 14 | 15 | //jedis连接池中最大的连接个数 16 | String JEDIS_MAX_TOTAL = "jedis.max.total"; 17 | //jedis连接池中最大的空闲连接个数 18 | String JEDIS_MAX_IDLE = "jedis.max.idle"; 19 | //jedis连接池中最小的空闲连接个数 20 | String JEDIS_MIN_IDLE = "jedis.min.idle"; 21 | 22 | //jedis连接池最大的等待连接时间 ms值 23 | String JEDIS_MAX_WAIT_MILLIS = "jedis.max.wait.millis"; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/cn/xpleaf/bigdata/storm/statistic/ConvertIPBolt.java: -------------------------------------------------------------------------------- 1 | package cn.xpleaf.bigdata.storm.statistic; 2 | 3 | import cn.xpleaf.bigdata.storm.utils.JedisUtil; 4 | import org.apache.storm.topology.BasicOutputCollector; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseBasicBolt; 7 | import org.apache.storm.tuple.Fields; 8 | import org.apache.storm.tuple.Tuple; 9 | import org.apache.storm.tuple.Values; 10 | import redis.clients.jedis.Jedis; 11 | 12 | /** 13 | * 日志数据预处理Bolt,实现功能: 14 | * 1.提取实现业务需求所需要的信息:ip地址、客户端唯一标识mid 15 | * 2.查询IP地址所属地,并发送到下一个Bolt 16 | */ 17 | public class ConvertIPBolt extends BaseBasicBolt { 18 | @Override 19 | public void execute(Tuple input, BasicOutputCollector collector) { 20 | byte[] binary = input.getBinary(0); 21 | String line = new String(binary); 22 | String[] fields = line.split("\t"); 23 | 24 | if(fields == null || fields.length < 10) { 25 | return; 26 | } 27 | 28 | // 获取ip和mid 29 | String ip = fields[1]; 30 | String mid = fields[2]; 31 | 32 | // 根据ip获取其所属地(省份) 33 | String province = null; 34 | if (ip != null) { 35 | Jedis jedis = JedisUtil.getJedis(); 36 | province = jedis.hget("ip_info_en", ip); 37 | // 需要释放jedis的资源,否则会报can not get resource from the pool 38 | JedisUtil.returnJedis(jedis); 39 | } 40 | 41 | // 发送数据到下一个bolt,只发送实现业务功能需要的province和mid 42 | collector.emit(new Values(province, mid)); 43 | 44 | } 45 | 46 | /** 47 | * 定义了发送到下一个bolt的数据包含两个域:province和mid 48 | */ 49 | @Override 50 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 51 | declarer.declare(new Fields("province", "mid")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/xpleaf/bigdata/storm/utils/JedisUtil.java: -------------------------------------------------------------------------------- 1 | package cn.xpleaf.bigdata.storm.utils; 2 | 3 | import cn.xpleaf.bigdata.storm.constants.JedisConstants; 4 | import redis.clients.jedis.Jedis; 5 | import redis.clients.jedis.JedisPool; 6 | import redis.clients.jedis.JedisPoolConfig; 7 | 8 | import java.io.IOException; 9 | import java.util.Properties; 10 | 11 | /** 12 | * Redis Java API 操作的工具类 13 | * 主要为我们提供 Java操作Redis的对象Jedis 模仿类似的数据库连接池 14 | * 15 | * JedisPool 16 | */ 17 | public class JedisUtil { 18 | 19 | private JedisUtil() {} 20 | private static JedisPool jedisPool; 21 | static { 22 | Properties prop = new Properties(); 23 | try { 24 | prop.load(JedisUtil.class.getClassLoader().getResourceAsStream("redis.properties")); 25 | JedisPoolConfig poolConfig = new JedisPoolConfig(); 26 | 27 | //jedis连接池中最大的连接个数 28 | poolConfig.setMaxTotal(Integer.valueOf(prop.getProperty(JedisConstants.JEDIS_MAX_TOTAL))); 29 | //jedis连接池中最大的空闲连接个数 30 | poolConfig.setMaxIdle(Integer.valueOf(prop.getProperty(JedisConstants.JEDIS_MAX_IDLE))); 31 | //jedis连接池中最小的空闲连接个数 32 | poolConfig.setMinIdle(Integer.valueOf(prop.getProperty(JedisConstants.JEDIS_MIN_IDLE))); 33 | //jedis连接池最大的等待连接时间 ms值 34 | poolConfig.setMaxWaitMillis(Long.valueOf(prop.getProperty(JedisConstants.JEDIS_MAX_WAIT_MILLIS))); 35 | 36 | //表示jedis的服务器主机名 37 | String host = prop.getProperty(JedisConstants.JEDIS_HOST); 38 | String JEDIS_PORT = "jedis.port"; 39 | int port = Integer.valueOf(prop.getProperty(JedisConstants.JEDIS_PORT)); 40 | //表示jedis的服务密码 41 | String password = prop.getProperty(JedisConstants.JEDIS_PASSWORD); 42 | 43 | // jedisPool = new JedisPool(poolConfig, host, port, 10000, password); 44 | jedisPool = new JedisPool(poolConfig, host, port, 10000); 45 | } catch (IOException e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | /** 51 | * 提供了Jedis的对象 52 | * @return 53 | */ 54 | public static Jedis getJedis() { 55 | return jedisPool.getResource(); 56 | } 57 | 58 | /** 59 | * 资源释放 60 | * @param jedis 61 | */ 62 | public static void returnJedis(Jedis jedis) { 63 | jedis.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/cn/xpleaf/bigdata/storm/statistic/StatisticTopology.java: -------------------------------------------------------------------------------- 1 | package cn.xpleaf.bigdata.storm.statistic; 2 | 3 | import kafka.api.OffsetRequest; 4 | import org.apache.storm.Config; 5 | import org.apache.storm.LocalCluster; 6 | import org.apache.storm.StormSubmitter; 7 | import org.apache.storm.generated.StormTopology; 8 | import org.apache.storm.kafka.BrokerHosts; 9 | import org.apache.storm.kafka.KafkaSpout; 10 | import org.apache.storm.kafka.SpoutConfig; 11 | import org.apache.storm.kafka.ZkHosts; 12 | import org.apache.storm.topology.TopologyBuilder; 13 | 14 | /** 15 | * 构建topology 16 | */ 17 | public class StatisticTopology { 18 | public static void main(String[] args) throws Exception { 19 | TopologyBuilder builder = new TopologyBuilder(); 20 | /** 21 | * 设置spout和bolt的dag(有向无环图) 22 | */ 23 | KafkaSpout kafkaSpout = createKafkaSpout(); 24 | builder.setSpout("id_kafka_spout", kafkaSpout); 25 | builder.setBolt("id_convertIp_bolt", new ConvertIPBolt()).shuffleGrouping("id_kafka_spout"); // 通过不同的数据流转方式,来指定数据的上游组件 26 | builder.setBolt("id_statistic_bolt", new StatisticBolt()).shuffleGrouping("id_convertIp_bolt"); // 通过不同的数据流转方式,来指定数据的上游组件 27 | // 使用builder构建topology 28 | StormTopology topology = builder.createTopology(); 29 | String topologyName = KafkaStormTopology.class.getSimpleName(); // 拓扑的名称 30 | Config config = new Config(); // Config()对象继承自HashMap,但本身封装了一些基本的配置 31 | 32 | // 启动topology,本地启动使用LocalCluster,集群启动使用StormSubmitter 33 | if (args == null || args.length < 1) { // 没有参数时使用本地模式,有参数时使用集群模式 34 | LocalCluster localCluster = new LocalCluster(); // 本地开发模式,创建的对象为LocalCluster 35 | localCluster.submitTopology(topologyName, config, topology); 36 | } else { 37 | StormSubmitter.submitTopology(topologyName, config, topology); 38 | } 39 | } 40 | 41 | /** 42 | * BrokerHosts hosts kafka集群列表 43 | * String topic 要消费的topic主题 44 | * String zkRoot kafka在zk中的目录(会在该节点目录下记录读取kafka消息的偏移量) 45 | * String id 当前操作的标识id 46 | */ 47 | private static KafkaSpout createKafkaSpout() { 48 | String brokerZkStr = "uplooking01:2181,uplooking02:2181,uplooking03:2181"; 49 | BrokerHosts hosts = new ZkHosts(brokerZkStr); // 通过zookeeper中的/brokers即可找到kafka的地址 50 | String topic = "f-k-s"; 51 | String zkRoot = "/" + topic; 52 | String id = "consumer-id"; 53 | SpoutConfig spoutConf = new SpoutConfig(hosts, topic, zkRoot, id); 54 | // 本地环境设置之后,也可以在zk中建立/f-k-s节点,在集群环境中,不用配置也可以在zk中建立/f-k-s节点 55 | //spoutConf.zkServers = Arrays.asList(new String[]{"uplooking01", "uplooking02", "uplooking03"}); 56 | //spoutConf.zkPort = 2181; 57 | spoutConf.startOffsetTime = OffsetRequest.LatestTime(); // 设置之后,刚启动时就不会把之前的消息也进行读取,会从最新的偏移量开始读取 58 | return new KafkaSpout(spoutConf); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /storm-statistic.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | cn.xpleaf.bigdata 8 | storm-statistic 9 | 1.0-SNAPSHOT 10 | 11 | storm-statistic 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 4.12 25 | test 26 | 27 | 28 | 29 | 30 | org.apache.storm 31 | storm-core 32 | 1.0.2 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.storm 40 | storm-kafka 41 | 1.0.2 42 | 43 | 44 | 45 | 46 | org.apache.kafka 47 | kafka-clients 48 | 0.10.0.1 49 | 50 | 51 | 52 | org.slf4j 53 | slf4j-log4j12 54 | 55 | 56 | org.apache.zookeeper 57 | zookeeper 58 | 59 | 60 | 61 | 62 | org.apache.kafka 63 | kafka_2.10 64 | 0.10.0.1 65 | 66 | 67 | 68 | org.apache.zookeeper 69 | zookeeper 70 | 71 | 72 | org.slf4j 73 | slf4j-log4j12 74 | 75 | 76 | 77 | 78 | 79 | 80 | redis.clients 81 | jedis 82 | 2.9.0 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-compiler-plugin 93 | 2.3.2 94 | 95 | UTF-8 96 | 1.8 97 | 1.8 98 | true 99 | 100 | 101 | 102 | 103 | maven-assembly-plugin 104 | 105 | 106 | 107 | jar-with-dependencies 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | make-assembly 121 | package 122 | 123 | single 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/main/java/cn/xpleaf/bigdata/storm/statistic/StatisticBolt.java: -------------------------------------------------------------------------------- 1 | package cn.xpleaf.bigdata.storm.statistic; 2 | 3 | import cn.xpleaf.bigdata.storm.utils.JedisUtil; 4 | import org.apache.storm.Config; 5 | import org.apache.storm.Constants; 6 | import org.apache.storm.topology.BasicOutputCollector; 7 | import org.apache.storm.topology.OutputFieldsDeclarer; 8 | import org.apache.storm.topology.base.BaseBasicBolt; 9 | import org.apache.storm.tuple.Tuple; 10 | import redis.clients.jedis.Jedis; 11 | 12 | import java.text.SimpleDateFormat; 13 | import java.util.*; 14 | 15 | /** 16 | * 日志数据统计Bolt,实现功能: 17 | * 1.统计各省份的PV、UV 18 | * 2.以天为单位,将省份对应的PV、UV信息写入Redis 19 | */ 20 | public class StatisticBolt extends BaseBasicBolt { 21 | 22 | Map pvMap = new HashMap<>(); 23 | Map> midsMap = null; 24 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 25 | 26 | @Override 27 | public void execute(Tuple input, BasicOutputCollector collector) { 28 | if (!input.getSourceComponent().equalsIgnoreCase(Constants.SYSTEM_COMPONENT_ID)) { // 如果收到非系统级别的tuple,统计信息到局部变量mids 29 | String province = input.getStringByField("province"); 30 | String mid = input.getStringByField("mid"); 31 | pvMap.put(province, pvMap.get(province) + 1); // pv+1 32 | if(mid != null) { 33 | midsMap.get(province).add(mid); // 将mid添加到该省份所对应的set中 34 | } 35 | } else { // 如果收到系统级别的tuple,则将数据更新到Redis中,释放JVM堆内存空间 36 | /* 37 | * 以 广东 为例,其在Redis中保存的数据格式如下: 38 | * guangdong_pv(Redis数据结构为hash) 39 | * --20180415 40 | * --pv数 41 | * --20180416 42 | * --pv数 43 | * guangdong_mids_20180415(Redis数据结构为set) 44 | * --mid 45 | * --mid 46 | * --mid 47 | * ...... 48 | * guangdong_mids_20180415(Redis数据结构为set) 49 | * --mid 50 | * --mid 51 | * --mid 52 | * ...... 53 | */ 54 | Jedis jedis = JedisUtil.getJedis(); 55 | String dateStr = sdf.format(new Date()); 56 | // 更新pvMap数据到Redis中 57 | String pvKey = null; 58 | for(String province : pvMap.keySet()) { 59 | int currentPv = pvMap.get(province); 60 | if(currentPv > 0) { // 当前map中的pv大于0才更新,否则没有意义 61 | pvKey = province + "_pv"; 62 | String oldPvStr = jedis.hget(pvKey, dateStr); 63 | if(oldPvStr == null) { 64 | oldPvStr = "0"; 65 | } 66 | Long oldPv = Long.valueOf(oldPvStr); 67 | jedis.hset(pvKey, dateStr, oldPv + currentPv + ""); 68 | pvMap.replace(province, 0); // 将该省的pv重新设置为0 69 | } 70 | } 71 | // 更新midsMap到Redis中 72 | String midsKey = null; 73 | HashSet midsSet = null; 74 | for(String province: midsMap.keySet()) { 75 | midsSet = midsMap.get(province); 76 | if(midsSet.size() > 0) { // 当前省份的set的大小大于0才更新到,否则没有意义 77 | midsKey = province + "_mids_" + dateStr; 78 | jedis.sadd(midsKey, midsSet.toArray(new String[midsSet.size()])); 79 | midsSet.clear(); 80 | } 81 | } 82 | // 释放jedis资源 83 | JedisUtil.returnJedis(jedis); 84 | System.out.println(System.currentTimeMillis() + "------->写入数据到Redis"); 85 | } 86 | } 87 | 88 | @Override 89 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 90 | 91 | } 92 | 93 | /** 94 | * 设置定时任务,只对当前bolt有效,系统会定时向StatisticBolt发送一个系统级别的tuple 95 | */ 96 | @Override 97 | public Map getComponentConfiguration() { 98 | Map config = new HashMap<>(); 99 | config.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 10); 100 | return config; 101 | } 102 | 103 | /** 104 | * 初始化各个省份的pv和mids信息(用来临时存储统计pv和uv需要的数据) 105 | */ 106 | public StatisticBolt() { 107 | pvMap = new HashMap<>(); 108 | midsMap = new HashMap>(); 109 | String[] provinceArray = {"shanxi", "jilin", "hunan", "hainan", "xinjiang", "hubei", "zhejiang", "tianjin", "shanghai", 110 | "anhui", "guizhou", "fujian", "jiangsu", "heilongjiang", "aomen", "beijing", "shaanxi", "chongqing", 111 | "jiangxi", "guangxi", "gansu", "guangdong", "yunnan", "sicuan", "qinghai", "xianggang", "taiwan", 112 | "neimenggu", "henan", "shandong", "shanghai", "hebei", "liaoning", "xizang"}; 113 | for(String province : provinceArray) { 114 | pvMap.put(province, 0); 115 | midsMap.put(province, new HashSet()); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------