protected static function _getSchema() { if (!self::$schema instanceof Ak_Schema) { $def = array('mc_expire' => array('base' => 'int', 'min' => 0, 'default' => 0), 'zk_expire' => array('base' => 'int', 'min' => 1, 'default' => 60), 'bool_true' => array('base' => 'bool', 'default' => true), 'bool_false' => array('base' => 'bool', 'default' => false), 'zk_host' => array('base' => 'string', 'optional' => true), 'ctimeoutopt' => array('base' => 'int', 'max' => 1000, 'optional' => true), 'ptimeoutopt' => array('base' => 'int', 'max' => 1000, 'optional' => true), 'wtimeoutopt' => array('base' => 'int', 'max' => 5000, 'optional' => true), 'rtimeoutopt' => array('base' => 'int', 'max' => 5000, 'optional' => true), 'backfill_key_count' => array('base' => 'int', 'default' => 0), 'ctimeoutdef' => array('base' => 'int', 'max' => 1000, 'default' => 20), 'ptimeoutdef' => array('base' => 'int', 'max' => 1000, 'default' => 20), 'wtimeoutdef' => array('base' => 'int', 'max' => 5000, 'default' => 100), 'rtimeoutdef' => array('base' => 'int', 'max' => 5000, 'default' => 500), 'acm_ctimeout' => array('base' => 'int', 'max' => 10000, 'default' => 20), 'acm_rtimeout' => array('base' => 'int', 'max' => 10000, 'default' => 500), 'acm_wtimeout' => array('base' => 'int', 'max' => 10000, 'default' => 100), 'strategy_index' => array('base' => 'int', 'default' => 0), 'mc_conf' => array('base' => 'object', 'members' => array('pid' => 'string', 'zk_host' => 'zk_host', 'zk_path' => 'string', 'zk_expire' => 'zk_expire', 'default_expire' => 'mc_expire', 'span_idc_strategy_index' => 'strategy_index', 'delete_directly' => 'bool_true', 'delete_delay' => 'bool_true', 'log_failed_server' => 'bool_false', 'connect_timeout' => 'ctimeoutopt', 'poll_timeout' => 'ptimeoutopt', 'send_timeout' => 'wtimeoutopt', 'recv_timeout' => 'rtimeoutopt', 'acm_connect_timeout' => 'acm_ctimeout', 'acm_read_timeout' => 'acm_rtimeout', 'acm_write_timeout' => 'acm_wtimeout')), 'idc_type' => array('base' => 'string', 'in' => array('none', 'self', 'all')), 'server' => array('base' => 'object', 'members' => array('ip' => 'string', 'port' => 'int'), 'alias' => array('Port' => 'port', 'host' => 'ip')), 'servers' => array('base' => 'dict', 'key_type' => 'string', 'value_type' => 'server'), 'servers_omit_key_type' => array('base' => 'dict', 'key_type' => 'any', 'value_type' => 'server', 'min_size' => 1), 'server_list' => array('base' => 'object', 'members' => array('idc' => 'string', 'children' => 'servers')), 'server_lists' => array('base' => 'dict', 'key_type' => 'string', 'value_type' => 'server_list'), 'zk_conf' => array('base' => 'object', 'members' => array('delete_cmd' => 'int', 'idc_type' => 'idc_type', 'idc_num' => 'int', 'connect_timeout' => 'ctimeoutopt', 'poll_timeout' => 'ptimeoutopt', 'send_timeout' => 'wtimeoutopt', 'recv_timeout' => 'rtimeoutopt', 'max_backfill_key_count' => 'backfill_key_count', 'children' => 'server_lists')), 'zk_global_conf' => array('base' => 'object', 'members' => array('connect_timeout' => 'ctimeoutdef', 'poll_timeout' => 'ptimeoutdef', 'send_timeout' => 'wtimeoutdef', 'recv_timeout' => 'rtimeoutdef')), 'idcs_type' => array('base' => 'dict', 'key_type' => 'int', 'value_type' => 'string', 'min_size' => 1), 'idcs_list' => array('base' => 'dict', 'key_type' => 'int', 'value_type' => 'idcs_type', 'min_size' => 1), 'idc_strategy' => array('base' => 'dict', 'key_type' => 'string', 'value_type' => 'idcs_list', 'min_size' => 1), 'idc_strategy_array' => array('base' => 'dict', 'key_type' => 'int', 'value_type' => 'idc_strategy', 'min_size' => 1), 'idc_strategy_conf' => array('base' => 'object', 'members' => array('span_idc_strategy' => 'idc_strategy_array')), 'acm_idc_num' => array('base' => 'int', 'min' => 1, 'default' => 1), 'acm_server_list' => array('base' => 'dict', 'key_type' => 'string', 'value_type' => 'server', 'min_size' => 1), 'acm_service' => array('base' => 'object', 'members' => array('idc' => 'string', 'children' => 'acm_server_list')), 'acm_service_list' => array('base' => 'dict', 'key_type' => 'string', 'value_type' => 'acm_service', 'min_size' => 1), 'acm_conf' => array('base' => 'object', 'members' => array('acm_idc_num' => 'int', 'children' => 'acm_service_list'))); self::$schema = Ak_Schema::create($def); } return self::$schema; }
/** * @brief 此接口封装了Ak_McClient初始化的过程 * * @return 初始化成功返回Ak_McClient对象实例,失败则返回false * @retval object/boolean * @author chenyijie * @date 2012/09/27 20:53:48 **/ public function create() { $zkHost = array(); $zkhostFromConf = Bd_Conf::getConf('cacheproxy/AkCache/zkhost'); if ($zkhostFromConf === false) { Bd_Log::warning('Get conf form cache.conf failed when create AkCacheClient'); return false; } //装配ip和port foreach ($zkhostFromConf as $value) { $content = $value['ip'] . ':' . $value['port']; $zkHost[] = $content; } Ak_Zookeeper::setHost($zkHost); Ak_AClient::SetGlobalConf(array('ZookeeperHost' => $zkHost)); //创建cache客户端实例 $keyArray = array('pid', 'zk_path', 'default_expire', 'curr_idc', 'delete_directly', 'delete_delay', 'connect_timeout', 'poll_timeout', 'send_timeout', 'recv_timeout', 'acm_connect_timeout', 'acm_read_timeout', 'acm_write_timeout'); $mcConf = array(); $confArray = Bd_Conf::getConf('cacheproxy/AkCache/mc_conf/'); //去除confArray中读取到的空项 foreach ($keyArray as $key) { if (isset($confArray[$key]) && $confArray[$key] !== '') { $mcConf[$key] = $confArray[$key]; } } if (empty($mcConf)) { //错误号参见CacheProxyAbstract.php中的定义 Bd_Log::warning('Get conf form cache.conf failed when create AkCacheClient', 6, null); return false; } //去除不需要进行string -> int类型转换的项 array_splice($keyArray, 0, 2); array_splice($keyArray, 1, 1); //记录需要进行string -> bool转换的项 $boolArray = array_splice($keyArray, 1, 2); foreach ($keyArray as $key) { if (array_key_exists($key, $mcConf)) { $mcConf[$key] = intval($mcConf[$key]); } } foreach ($boolArray as $key) { if ($mcConf[$key] === 'true') { $mcConf[$key] = true; } else { $mcConf[$key] = false; } } /* 装配后的mcConf的具体示例 $mcConf = array( 'pid' => $pid, 'zk_path' => $zk_path, 'default_expire' => 86400, 'curr_idc' => 'tc', 'delete_directly' => true, 'delete_delay' => true, 'connect_timeout' => 10, 'poll_timeout' => 20, 'send_timeout' => 100, 'recv_timeout' => 500, 'acm_connect_timeout' => 30, 'acm_read_timeout' => 500, 'acm_write_timeout' => 100, ); */ $objMcClient = Ak_McClient::create($mcConf); if (is_null($objMcClient)) { Bd_Log::debug("create AkCacheClient failed", 2, $mcConf); return false; } return $objMcClient; }