├── index.php ├── log └── rpc.log ├── Jsonrpc ├── autoload.php ├── Services │ ├── User.php │ └── MyRedis.php ├── Config │ └── Server.php ├── Protocols │ └── Json.php └── Server.php ├── client ├── client.php └── RpcClient.php ├── README.md └── LICENSE /index.php: -------------------------------------------------------------------------------- 1 | $uid, 13 | 'name' => '小萝莉', 14 | 'age' => 18, 15 | 'sex' => '女' 16 | ); 17 | } 18 | 19 | public static function getEmail($uid) 20 | { 21 | return 'test@test.com'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Jsonrpc/Services/MyRedis.php: -------------------------------------------------------------------------------- 1 | redis = new \Redis(); 13 | $this->redis->connect('127.0.0.1',6379); 14 | } 15 | 16 | 17 | 18 | public function get($key) 19 | { 20 | if (empty($key)) { 21 | return '参数不能为空'; 22 | } 23 | return $this->redis->get($key); 24 | } 25 | 26 | public function set($key, $data, $expire=0) 27 | { 28 | if (empty($key)) { 29 | return '参数不能为空'; 30 | } 31 | return $this->redis->set($key, $data, $expire); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Jsonrpc/Config/Server.php: -------------------------------------------------------------------------------- 1 | 4, 19 | 'open_eof_check' => true, 20 | 'package_eof' => "\r\n", 21 | 'task_ipc_mode' => 2, 22 | 'task_worker_num' => 2, 23 | 'user' => 'xmc', 24 | 'group' => 'xmc', 25 | 'log_file' => 'log/rpc.log', 26 | 'heartbeat_check_interval' => 300, 27 | 'heartbeat_idle_time' => 300, 28 | 'daemonize' => false // 守护进程改成true 29 | ); 30 | } 31 | } -------------------------------------------------------------------------------- /Jsonrpc/Protocols/Json.php: -------------------------------------------------------------------------------- 1 | getInfoByUid($uid); 21 | var_dump($ret_sync); 22 | //通过rpc操作redis的例子 23 | $redis_client = RpcClient::instance('MyRedis'); 24 | $set_res = $redis_client->set('jsonrpc','hello json rpc654', 30); 25 | var_dump($set_res); 26 | $get_res = $redis_client->get('jsonrpc'); 27 | var_dump($get_res); 28 | //调用不存在的函数 29 | $list_res = $redis_client->list('jsonrpc'); 30 | var_dump($list_res); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swoole-JsonRPC 2 | use swoole for jsonRpc(运用swoole简单实现jsonRPC) 3 | ## Requirements 4 | 5 | * PHP 5.3+ 6 | * Swoole 1.7.16 7 | * Linux, OS X and basic Windows support (Thinks to cygwin) 8 | 9 | ## Installation Swoole 10 | 11 | 1. Install from pecl 12 | 13 | ``` 14 | pecl install swoole 15 | ``` 16 | 17 | 2. Install from source 18 | 19 | ``` 20 | sudo apt-get install php5-dev 21 | git clone https://github.com/swoole/swoole-src.git 22 | cd swoole-src 23 | phpize 24 | ./configure 25 | make && make install 26 | ``` 27 | 28 | ## 使用 29 | 30 | * 下载swoole-JsonRPC 31 | * 解压swoole-JsonRPC并进入目录 32 | * 服务端执行命令php index.php 33 | * 客户端例子见client/client.php 34 | ``` 35 | getInfoByUid($uid); 54 | var_dump($ret_sync); 55 | //通过rpc操作redis的例子 56 | $redis_client = RpcClient::instance('MyRedis'); 57 | $set_res = $redis_client->set('jsonrpc','hello json rpc654', 30); 58 | var_dump($set_res); 59 | $get_res = $redis_client->get('jsonrpc'); 60 | var_dump($get_res); 61 | //调用不存在的函数 62 | $list_res = $redis_client->list('jsonrpc'); 63 | var_dump($list_res); 64 | ``` 65 | 66 | -------------------------------------------------------------------------------- /client/RpcClient.php: -------------------------------------------------------------------------------- 1 | true, 24 | 'package_eof' => "\r\n" 25 | ); 26 | 27 | /** 28 | * 服务端地址 29 | * @var array 30 | */ 31 | protected static $addressArray = array(); 32 | 33 | /** 34 | * 异步调用实例 35 | * @var string 36 | */ 37 | protected static $asyncInstances = array(); 38 | 39 | /** 40 | * 同步调用实例 41 | * @var string 42 | */ 43 | protected static $instances = array(); 44 | 45 | /** 46 | * 到服务端的socket连接 47 | * @var resource 48 | */ 49 | protected $connection = null; 50 | 51 | /** 52 | * 到服务端的swoole client连接 53 | * @var resource 54 | */ 55 | protected $swooleClient = null; 56 | 57 | /** 58 | * 实例的服务名 59 | * @var string 60 | */ 61 | protected $serviceName = ''; 62 | 63 | /** 64 | * 使用swoole方式 65 | * @var string 66 | */ 67 | protected static $useSwoole = false; 68 | 69 | /** 70 | * 设置/获取服务端地址 71 | * @param array $address_array 72 | */ 73 | public static function config($address_array = array()) 74 | { 75 | if (! empty($address_array)) { 76 | self::$addressArray = $address_array; 77 | } 78 | return self::$addressArray; 79 | } 80 | 81 | /** 82 | * 获取一个实例 83 | * @param string $service_name 84 | * @return instance of RpcClient 85 | */ 86 | public static function instance($service_name) 87 | { 88 | if (! isset(self::$instances[$service_name])) { 89 | self::$instances[$service_name] = new self($service_name); 90 | } 91 | return self::$instances[$service_name]; 92 | } 93 | 94 | /** 95 | * 构造函数 96 | * @param string $service_name 97 | */ 98 | protected function __construct($service_name) 99 | { 100 | $this->serviceName = $service_name; 101 | } 102 | 103 | public static function setSwooleClient() 104 | { 105 | self::$useSwoole = true; 106 | } 107 | 108 | /** 109 | * 调用 110 | * 111 | * @param string $method 112 | * @param array $arguments 113 | * @throws Exception 114 | * @return 115 | * 116 | */ 117 | public function __call($method, $arguments) 118 | { 119 | // 同步发送接收 120 | $this->sendData($method, $arguments); 121 | return $this->recvData(); 122 | } 123 | 124 | /** 125 | * 发送数据给服务端 126 | * 127 | * @param string $method 128 | * @param array $arguments 129 | */ 130 | public function sendData($method, $arguments) 131 | { 132 | $bin_data = JsonProtocol::encode(array( 133 | 'class' => $this->serviceName, 134 | 'method' => $method, 135 | 'param_array' => $arguments 136 | ))."\r\n"; 137 | $this->openConnection(); 138 | if (self::$useSwoole) { 139 | return $this->swooleClient->send($bin_data); 140 | } else { 141 | return fwrite($this->connection, $bin_data) == strlen($bin_data); 142 | } 143 | } 144 | 145 | /** 146 | * 从服务端接收数据 147 | * @throws Exception 148 | */ 149 | public function recvData() 150 | { 151 | if (self::$useSwoole) { 152 | $res = $this->swooleClient->recv(); 153 | $this->swooleClient->close(); 154 | } else { 155 | $res = fgets($this->connection); 156 | $this->closeConnection(); 157 | } 158 | if (! $res) { 159 | throw new Exception("recvData empty"); 160 | } 161 | return JsonProtocol::decode($res); 162 | } 163 | 164 | /** 165 | * 打开到服务端的连接 166 | * @return void 167 | */ 168 | protected function openConnection() 169 | { 170 | $address = self::$addressArray[array_rand(self::$addressArray)]; 171 | if (self::$useSwoole) { 172 | $address = explode(':', $address); 173 | $this->swooleClient = new swoole_client(SWOOLE_SOCK_TCP); 174 | $this->swooleClient->set($this->swooleClientSets); 175 | if (!$this->swooleClient->connect($address[0], $address[1], self::TIME_OUT)) { 176 | exit("connect failed. Error: {$this->swooleClient->errCode}\n"); 177 | } 178 | } else { 179 | $this->connection = stream_socket_client($address, $err_no, $err_msg); 180 | if (! $this->connection) { 181 | throw new Exception("can not connect to $address , $err_no:$err_msg"); 182 | } 183 | stream_set_blocking($this->connection, true); 184 | stream_set_timeout($this->connection, self::TIME_OUT); 185 | } 186 | } 187 | 188 | /** 189 | * 关闭到服务端的连接 190 | * 191 | * @return void 192 | */ 193 | protected function closeConnection() 194 | { 195 | fclose($this->connection); 196 | $this->connection = null; 197 | } 198 | } 199 | 200 | function createJsonProtocol() 201 | { 202 | 203 | /** 204 | * RPC 协议解析 相关 205 | * 协议格式为 [json字符串\n] 206 | */ 207 | class JsonProtocol 208 | { 209 | /** 210 | * 将数据打包成Rpc协议数据 211 | * 212 | * @param mixed $data 213 | * @return string 214 | */ 215 | public static function encode($data) 216 | { 217 | return json_encode($data); 218 | } 219 | 220 | /** 221 | * 解析Rpc协议数据 222 | * 223 | * @param string $bin_data 224 | * @return mixed 225 | */ 226 | public static function decode($bin_data) 227 | { 228 | return json_decode(trim($bin_data), true); 229 | } 230 | } 231 | } -------------------------------------------------------------------------------- /Jsonrpc/Server.php: -------------------------------------------------------------------------------- 1 | config = \Jsonrpc\Config\Server::getConfig(); 32 | $serv->set($serv->config); 33 | $serv->on('Start', array($this, 'onStart')); 34 | $serv->on('Connect', array($this, 'onConnect')); 35 | $serv->on('Receive', array($this, 'onReceive')); 36 | $serv->on('Close', array($this, 'onClose')); 37 | $serv->on('Shutdown', array($this, 'onShutdown')); 38 | $serv->on('Timer', array($this, 'onTimer')); 39 | $serv->on('WorkerStart', array($this, 'onWorkerStart')); 40 | $serv->on('WorkerStop', array($this, 'onWorkerStop')); 41 | $serv->on('Task', array($this, 'onTask')); 42 | $serv->on('Finish', array($this, 'onFinish')); 43 | $serv->on('WorkerError', array($this, 'onWorkerError')); 44 | $serv->on('ManagerStart', function ($serv) { 45 | global $argv; 46 | swoole_set_process_name("php {$argv[0]}: manager"); 47 | }); 48 | $serv->start(); 49 | } 50 | 51 | public function onStart(\swoole_server $serv) 52 | { 53 | global $argv; 54 | swoole_set_process_name("php {$argv[0]}: master"); 55 | echo "\033[1A\n\033[K-----------------------\033[47;30m SWOOLE \033[0m-----------------------------\n\033[0m"; 56 | echo 'swoole version:' . swoole_version() . " PHP version:".PHP_VERSION."\n"; 57 | echo "------------------------\033[47;30m WORKERS \033[0m---------------------------\n"; 58 | echo "\033[47;30mMasterPid\033[0m", str_pad('', self::$_maxMasterPidLength + 2 - strlen('MasterPid')), "\033[47;30mManagerPid\033[0m", str_pad('', self::$_maxManagerPidLength + 2 - strlen('ManagerPid')), "\033[47;30mWorkerId\033[0m", str_pad('', self::$_maxWorkerIdLength + 2 - strlen('WorkerId')), "\033[47;30mWorkerPid\033[0m\n"; 59 | } 60 | 61 | public function log($msg) 62 | { 63 | echo "#" . $msg . PHP_EOL; 64 | } 65 | 66 | public function processRename($serv, $worker_id) 67 | { 68 | global $argv; 69 | $worker_num = isset($serv->setting['worker_num']) ? $serv->setting['worker_num'] : 1; 70 | $task_worker_num = isset($serv->setting['task_worker_num']) ? $serv->setting['task_worker_num'] : 0; 71 | 72 | if ($worker_id >= $worker_num) { 73 | swoole_set_process_name("php {$argv[0]}: task"); 74 | } else { 75 | swoole_set_process_name("php {$argv[0]}: worker"); 76 | } 77 | echo str_pad($serv->master_pid, self::$_maxMasterPidLength+2), 78 | str_pad($serv->manager_pid, self::$_maxManagerPidLength+2), 79 | str_pad($serv->worker_id, self::$_maxWorkerIdLength+2), 80 | str_pad($serv->worker_pid, self::$_maxWorkerIdLength), "\n"; 81 | } 82 | 83 | public function setTimerInWorker(\swoole_server $serv, $worker_id) 84 | { 85 | if ($worker_id == 0) { 86 | echo "Start: " . microtime(true) . "\n"; 87 | $serv->addtimer(3000); 88 | } 89 | } 90 | 91 | 92 | public function onTimer($serv, $interval) 93 | { 94 | echo "Timer#$interval: " . microtime(true) . "\n"; 95 | $serv->task("hello"); 96 | } 97 | 98 | 99 | public function onConnect(\swoole_server $serv, $fd, $from_id) 100 | { 101 | echo "Worker#{$serv->worker_pid} Client[$fd@$from_id]: Connect.\n"; 102 | } 103 | 104 | public function onWorkerStart($serv, $worker_id) 105 | { 106 | $this->processRename($serv, $worker_id); 107 | // setTimerInWorker($serv, $worker_id); 108 | } 109 | 110 | 111 | public function onReceive(\swoole_server $serv, $fd, $from_id, $data) 112 | { 113 | $protocal = new Protocols\Json(); 114 | $data = $protocal->decode($data); 115 | // 判断数据是否正确 116 | if(empty($data['class']) || empty($data['method']) || !isset($data['param_array'])) { 117 | // 发送数据给客户端,请求包错误 118 | return $serv->send($fd,$protocal->encode(array('code'=>400, 'msg'=>'bad request', 'data'=>null))); 119 | } 120 | // 获得要调用的类、方法、及参数 121 | $class = $data['class']; 122 | $method = $data['method']; 123 | $param_array = $data['param_array']; 124 | 125 | $success = false; 126 | // 判断类对应文件是否载入 127 | if (!isset($this->services[$class]) OR empty($this->services[$class])) { 128 | if (! class_exists($class)) { 129 | $include_file = __DIR__ . "/Services/$class.php"; 130 | if (is_file($include_file)) { 131 | require_once $include_file; 132 | } 133 | if (! class_exists($class)) { 134 | $code = 404; 135 | $msg = "class $class not found"; 136 | // 发送数据给客户端 类不存在 137 | return $serv->send($fd,$protocal->encode(array('code' => $code, 'msg' => $msg, 'data' => null))); 138 | } 139 | $this->services[$class] = new $class(); 140 | } 141 | } 142 | 143 | // 调用类的方法 144 | if (method_exists($this->services[$class], $method)) { 145 | $ret = call_user_func_array(array($this->services[$class], $method), $param_array); 146 | // 发送数据给客户端,调用成功,data下标对应的元素即为调用结果 147 | return $serv->send($fd,$protocal->encode(array('code' => 0, 'msg' => 'ok', 'data' => $ret))); 148 | } else { 149 | return $serv->send($fd,$protocal->encode(array('code' => 404, 'msg' => "method $method not found", 'data' => null))); 150 | } 151 | 152 | } 153 | 154 | public function onTask(\swoole_server $serv, $task_id, $from_id, $data) 155 | { 156 | //这里是task任务的回调函数 157 | //一些处理时间比较长的流程可以放在这里执行 158 | echo "this is onTask\n"; 159 | var_dump($data); 160 | } 161 | 162 | public function onFinish(\swoole_server $serv, $task_id, $data) 163 | { 164 | //ontask执行完毕自动调用onFinish 165 | echo "taskid={$task_id} is over\n"; 166 | } 167 | 168 | public function onClose($serv, $fd, $from_id) 169 | { 170 | $this->log("Worker#{$serv->worker_pid} Client[$fd@$from_id]: fd=$fd is closed"); 171 | } 172 | 173 | public function onWorkerError(\swoole_server $serv, $worker_id, $worker_pid, $exit_code) 174 | { 175 | echo "worker abnormal exit. WorkerId=$worker_id|Pid=$worker_pid|ExitCode=$exit_code\n"; 176 | } 177 | 178 | public function onWorkerStop($serv, $worker_id) 179 | { 180 | echo "WorkerStop[$worker_id]|pid=" . $serv->worker_pid . ".\n"; 181 | } 182 | 183 | 184 | public function onShutdown($serv) 185 | { 186 | echo "Server: onShutdown\n"; 187 | } 188 | 189 | 190 | } -------------------------------------------------------------------------------- /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 | 203 | --------------------------------------------------------------------------------