Exemplo n.º 1
0
 /**
  * 从存储中删除删除连不上的gateway通讯端口
  * @param string $addr
  * @param string $errstr
  */
 public function tryToDeleteGatewayAddress($addr, $errstr)
 {
     $key = 'GLOBAL_GATEWAY_ADDRESS';
     if (!isset($this->_badGatewayAddress[$addr])) {
         $this->_badGatewayAddress[$addr] = 0;
     }
     // 删除连不上的端口
     if ($this->_badGatewayAddress[$addr]++ > self::MAX_RETRY_COUNT) {
         Lock::get();
         $addresses_list = Store::instance('gateway')->get($key);
         unset($addresses_list[$addr]);
         Store::instance('gateway')->set($key, $addresses_list);
         Lock::release();
         $this->log("tcp://{$addr} " . $errstr . " del {$addr} from store", false);
     }
 }
Exemplo n.º 2
0
 /**
  * 删除当前Gateway的内部通信地址
  * @param string $address
  * @return bool
  */
 protected function unregisterAddress()
 {
     $address = $this->lanIp . ':' . $this->lanPort;
     $key = 'GLOBAL_GATEWAY_ADDRESS';
     try {
         $store = Store::instance('gateway');
     } catch (\Exception $msg) {
         $this->log($msg);
         return false;
     }
     // 为保证原子性,需要加锁
     Lock::get();
     $addresses_list = $store->get($key);
     if (empty($addresses_list)) {
         $addresses_list = array();
     }
     unset($addresses_list[$address]);
     if (!$store->set($key, $addresses_list)) {
         Lock::release();
         $msg = "unregisterAddress fail";
         if (get_class($store) == 'Memcached') {
             $msg .= " reason:" . $store->getResultMessage();
         }
         $this->log($msg);
         return;
     }
     Lock::release();
     return true;
 }
Exemplo n.º 3
0
 /**
  * 删除当前Gateway的内部通信地址
  * @param string $address
  * @return bool
  */
 protected function unregisterAddress()
 {
     $address = $this->lanIp . ':' . $this->lanPort;
     $key = 'GLOBAL_GATEWAY_ADDRESS';
     try {
         $store = Store::instance('gateway');
     } catch (\Exception $msg) {
         $this->log($msg);
         return false;
     }
     // 为保证原子性,需要加锁
     Lock::get();
     if (!$store->hDel($key, $address)) {
         Lock::release();
         $msg = "unregisterAddress fail";
         $this->log($msg);
         return;
     }
     Lock::release();
     return true;
 }