1. 程式人生 > >dubbo-php-framework的請求回覆實體解析

dubbo-php-framework的請求回覆實體解析

經過前面Protocol的分析,我們已經知道框架在處理請求和回覆時都是通過封裝為DubboRequest和DubboResponse來做,這篇我們就開始分析DubboRequest和DubboResponse的流程。

class DubboRequest
{
    //包頭欄位
    private $twoWay = true;
    private $heartbeatEvent = false;
    private $sn;                    //請求序號
    private $serialization;
    private $fullData;                   //報文(包含訊息頭)
    private $dataLen;    //資料報文長度
    private $requestLen; //請求報文總長度(即訊息頭+訊息體的長度)

    //包體欄位
    private $dubboVersion = "2.0.0";       //dubbo 版本
    private $service;                      //服務名稱
    private $version;                      //服務版本
    private $group;             //服務group
    private $method;                //方法名
    private $timeout;             //超時時間(ms)
    private $types;              //引數型別
    private $paramNum = 0;        //引數個數
    private $params = array();    //呼叫$method時的引數
    private $attach = array();

    /**
     * @return boolean
     */
    public function isTwoWay()
    {
        return $this->twoWay;
    }

    /**
     * @param boolean $twoWay
     */
    public function setTwoWay($twoWay)
    {
        $this->twoWay = $twoWay;
    }

    /**
     * @return mixed
     */
    public function getDataLen()
    {
        return $this->dataLen;
    }

    /**
     * @param mixed $dataLen
     */
    public function setDataLen($dataLen)
    {
        $this->dataLen = $dataLen;
    }

    /**
     * @return mixed
     */
    public function getRequestLen()
    {
        return $this->requestLen;
    }

    /**
     * @param mixed $requestLen
     */
    public function setRequestLen($requestLen)
    {
        $this->requestLen = $requestLen;
    }



    /**
     * @return boolean
     */
    public function isHeartbeatEvent()
    {
        return $this->heartbeatEvent;
    }

    /**
     * @param boolean $heartbeatEvent
     */
    public function setHeartbeatEvent($heartbeatEvent)
    {
        $this->heartbeatEvent = $heartbeatEvent;
    }




    /**
     * @return mixed
     */
    public function getSn()
    {
        return $this->sn;
    }

    /**
     * @param mixed $sn
     */
    public function setSn($sn)
    {
        $this->sn = $sn;
    }

    /**
     * @return mixed
     */
    public function getTimeout()
    {
        return $this->timeout;
    }

    /**
     * @param mixed $timeout
     */
    public function setTimeout($timeout)
    {
        $this->timeout = $timeout;
    }



    /**
     * @return mixed
     */
    public function getFullData()
    {
        return $this->fullData;
    }

    /**
     * @param mixed $fullData
     */
    public function setFullData($fullData)
    {
        $this->fullData = $fullData;
    }

    /**
     * @return string
     */
    public function getDubboVersion()
    {
        return $this->dubboVersion;
    }

    /**
     * @param string $dubboVersion
     */
    public function setDubboVersion($dubboVersion)
    {
        $this->dubboVersion = $dubboVersion;
    }

    /**
     * @return mixed
     */
    public function getService()
    {
        return $this->service;
    }

    /**
     * @param mixed $service
     */
    public function setService($service)
    {
        $this->service = $service;
    }

    /**
     * @return mixed
     */
    public function getVersion()
    {
        return $this->version;
    }

    /**
     * @param mixed $version
     */
    public function setVersion($version)
    {
        $this->version = $version;
    }

    /**
     * @return mixed
     */
    public function getGroup()
    {
        return $this->group;
    }

    /**
     * @param mixed $group
     */
    public function setGroup($group)
    {
        $this->group = $group;
    }

    /**
     * @return mixed
     */
    public function getMethod()
    {
        return $this->method;
    }

    /**
     * @param mixed $method
     */
    public function setMethod($method)
    {
        $this->method = $method;
    }

    /**
     * @return mixed
     */
    public function getTypes()
    {
        return $this->types;
    }

    /**
     * @param mixed $types
     */
    public function setTypes($types)
    {
        $this->types = $types;
    }

    /**
     * @return array
     */
    public function getParams()
    {
        return $this->params;
    }

    /**
     * @param array $params
     */
    public function setParams($params)
    {
        $this->params = $params;
    }

    /**
     * @return array
     */
    public function getAttach()
    {
        return $this->attach;
    }

    /**
     * @param array $attach
     */
    public function setAttach($attach)
    {
        $this->attach = $attach;
    }

    /**
     * @return mixed
     */
    public function getSerialization()
    {
        return $this->serialization;
    }

    /**
     * @param mixed $serialization
     */
    public function setSerialization($serialization)
    {
        $this->serialization = $serialization;
    }

    /**
     * @return int
     */
    public function getParamNum()
    {
        return $this->paramNum;
    }

    /**
     * @param int $paramNum
     */
    public function setParamNum($paramNum)
    {
        $this->paramNum = $paramNum;
    }



    //用於監控service中各方法的效能
    public $startTime;            //開始處理請求的時間
    public $endTime;            //請求處理結束的時間

    public $host;                //記錄acc日誌中的目標IP
    public $port;                //記錄acc日誌中的目標埠

    public $reqInfo = null;            //swoole框架記錄的過載資訊

    public $environment = "prod";


    public function __toString()
    {
        $ret = sprintf("%s:%s:%s->%s", $this->service, $this->version, $this->group, $this->method);
        return $ret;
    }
}
class DubboResponse
{
    const OK = 20;
    const SERVICE_ERROR = 70;      //服務端框架層有異常

    private $fullData;				//返回報文(包含訊息頭)

    //包頭欄位
    private $sn;				//請求序號
    private $status = self::OK;
    private $heartbeatEvent = false;
    private $serialization;
    private $len;            //資料部分長度

    //包體欄位
    private $responseBody;    //包體資料
    private $result;           //呼叫$method的結果
    private $errorMsg;

    /**
     * @return mixed
     */
    public function getFullData()
    {
        return $this->fullData;
    }

    /**
     * @param mixed $fullData
     */
    public function setFullData($fullData)
    {
        $this->fullData = $fullData;
    }

    /**
     * @return int
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @return mixed
     */
    public function getLen()
    {
        return $this->len;
    }

    /**
     * @param mixed $len
     */
    public function setLen($len)
    {
        $this->len = $len;
    }

    /**
     * @param int $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * @return boolean
     */
    public function isHeartbeatEvent()
    {
        return $this->heartbeatEvent;
    }

    /**
     * @param boolean $heartbeatEvent
     */
    public function setHeartbeatEvent($heartbeatEvent)
    {
        $this->heartbeatEvent = $heartbeatEvent;
    }




    /**
     * @return mixed
     */
    public function getErrorMsg()
    {
        return $this->errorMsg;
    }

    /**
     * @param mixed $errorMsg
     */
    public function setErrorMsg($errorMsg)
    {
        $this->errorMsg = $errorMsg;
    }

    /**
     * @return mixed
     */
    public function getSn()
    {
        return $this->sn;
    }

    /**
     * @param mixed $sn
     */
    public function setSn($sn)
    {
        $this->sn = $sn;
    }

    /**
     * @return mixed
     */
    public function getResult()
    {
        return $this->result;
    }

    /**
     * @param mixed $result
     */
    public function setResult($result)
    {
        $this->result = $result;
    }

    /**
     * @return mixed
     */
    public function getSerialization()
    {
        return $this->serialization;
    }

    /**
     * @param mixed $serialization
     */
    public function setSerialization($serialization)
    {
        $this->serialization = $serialization;
    }

    /**
     * @return mixed
     */
    public function getResponseBody()
    {
        return $this->responseBody;
    }

    /**
     * @param mixed $responseBody
     */
    public function setResponseBody($responseBody)
    {
        $this->responseBody = $responseBody;
    }



	public function __toString()
	{
		$ret = sprintf("%s->%s",  $this->sn,$this->responseBody);
		return $ret;
	}		
}