public function __construct($addr = '127.0.0.1', $port = 8305, $listenQueue = 512)
 {
     if (is_null(self::$_logger)) {
         self::$_logger = \Zopt\Base\Logger::getLogger(__CLASS__);
     }
     if (!extension_loaded('libevent')) {
         self::$_logger->crit('FATAL: Please firstly install libevent extension.');
         die;
     }
     $this->_addr = $addr;
     $this->_port = $port;
     $this->_listenQueue = $listenQueue;
     $this->_started = FALSE;
     $this->_sock = NULL;
     // Init the event machine using libevent c extension
     $this->_listenEvent = NULL;
     $this->_eventBase = event_base_new();
     $this->_streams = array();
     // Register signal handlers
     $this->_signalEvents = array();
     foreach (array(SIGTERM, SIGHUP, SIGINT, SIGQUIT) as $signo) {
         $event = event_new();
         event_set($event, $signo, EV_SIGNAL | EV_PERSIST, array($this, 'handleSignalEvent'), $signo);
         event_base_set($event, $this->_eventBase);
         event_add($event);
         $this->_signalEvents[$signo] = $event;
     }
 }
 /**
  * new datastore client
  *
  * @param string $dsName The data store's name
  * @param PDO[int] $shardDbs An associate array with id=>database PDO objects,
  *                           and each PDO has "meta_table_of_table" table in it.
  * @param CacheInterface $metaCache The cache for datastore metadata
  */
 public function __construct($dsName, $shardDbs, $metaCache)
 {
     if (is_null(self::$_logger)) {
         self::$_logger = \Zopt\Base\Logger::getLogger(__CLASS__);
     }
     // signatures etc.
     $this->_dsName = $dsName;
     // sort the shared dbs
     ksort($shardDbs);
     $this->_shardDbs = $shardDbs;
     foreach ($this->_shardDbs as $key => $db) {
         $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         // set to exception mode
     }
     // meta data cache
     $this->_metaCache = $metaCache;
 }
 public function __construct($sock, $eventBase, &$name = NULL, $closeCallback = NULL)
 {
     if (is_null(self::$_logger)) {
         self::$_logger = \Zopt\Base\Logger::getLogger(__CLASS__);
     }
     $this->_sock = $sock;
     $this->_eventBase = $eventBase;
     $name = is_null($name) ? SockUtil::getUniqueName($sock) : $name;
     $this->_name = $name;
     $this->_closeCallback = $closeCallback;
     if (is_null($sock) || is_null($eventBase)) {
         self::$_logger->warning("IOStream initialized with null socket {$sock} or event base {$eventBase}.");
         $this->_closeCallback && call_user_func($this->_closeCallback, $this->_name);
         return;
     }
     socket_set_nonblock($sock);
     $this->_recvEvent = event_new();
     event_set($this->_recvEvent, $this->_sock, EV_READ, array($this, '_handleRecvEvent'));
     event_base_set($this->_recvEvent, $this->_eventBase);
     $this->_sendEvent = event_new();
     event_set($this->_sendEvent, $this->_sock, EV_WRITE, array($this, '_handleSendEvent'));
     event_base_set($this->_sendEvent, $this->_eventBase);
 }