Esempio n. 1
0
 public static function create($conf)
 {
     $op = new Ak_Op();
     $op->conf = $conf;
     Ak_Zookeeper::setHost($conf['zk_host']);
     Ak_Log::setHandler('warning', 'Ak_Op::error');
     //mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX);
     //foreach ($conf['db'] as $name => $info) {
     //    $db = new mysqli($info['db_host'], $info['db_user'], $info['db_pass'], $info['db_name'], $info['db_port']);
     //    $db->set_charset("utf8");
     //    $op->db[$name] = $db;
     //}
     return $op;
 }
Esempio n. 2
0
 public static function SetGlobalConf($conf)
 {
     self::$global_conf = $conf;
     if (isset($conf['ZookeeperHost'])) {
         Ak_Zookeeper::setHost($conf['ZookeeperHost']);
     }
     if (isset($conf['ZookeeperBackupDir'])) {
         Ak_Zookeeper::setBackupDir($conf['ZookeeperBackupDir']);
     }
     if (isset($conf['ZookeeperDisabled']) && $conf['ZookeeperDisabled'] === true) {
         Ak_Zookeeper::useBackupOnly(true);
     }
 }
Esempio n. 3
0
 public static function create($conf)
 {
     if (!isset($conf['curr_idc'])) {
         $conf['curr_idc'] = 'tc';
     } else {
         if (!is_string($conf['curr_idc']) && !is_int($conf['curr_idc'])) {
             Ak_Log::warning("curr_idc format error! must be int(deperacated) or string(recommand)");
             return null;
         }
     }
     if (is_int($conf['curr_idc']) && array_key_exists($conf['curr_idc'], self::$s_idc_index_name_map)) {
         $conf['curr_idc'] = self::$s_idc_index_name_map[$conf['curr_idc']];
     }
     if (($server_lists = self::_get_server_lists($conf, $zk_conf)) == null) {
         self::_warning("get server_lists error!");
         return null;
     }
     if (is_string($conf['zk_host'])) {
         Ak_Zookeeper::setHost($conf['zk_host']);
     }
     $mcc = new Ak_McClient();
     $mcc->conf = $conf;
     $mcc->log_failed_server = $conf['log_failed_server'];
     $mcc->zk_conf = $zk_conf;
     $mcc->idc_type = $zk_conf['idc_type'];
     $mcc->span_idc = self::_initSpanIdcStrategy($conf);
     $mcc->server_lists = $server_lists;
     if ($mcc->span_idc == null) {
         Ak_Log::warning("create SpanIdcStrategy failed!");
         return null;
     }
     foreach ($server_lists as $server_list) {
         $mcc->span_idc->registerResource(self::CACHE_RESOURCE, $server_list['idc'], $server_list);
     }
     if (isset($conf['prefix'])) {
         $mcc->prefix = $conf['prefix'];
     }
     return $mcc;
 }
Esempio n. 4
0
 /**
  * @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;
 }