Пример #1
0
 /**
  * 主动输出接口
  * 
  * 功能:解析本地的序列文件向指定的被动输入接口发送数据
  * 
  * 参数:无
  * 返回值:无
  */
 public static function InitiativeOutput()
 {
     //echo microtime()."<br>";
     $loger = new Pft_Log_File('sync');
     //访问权限判断
     if (!Pft_Sync_MessageListManage::interfaceAuth('InitiativeOutput')) {
         //写日志
         $str = '没有访问此接口的权限';
         $loger = new Pft_Log_File('sync');
         $loger->log($str);
         exit;
     }
     //判断是否锁定
     if (Pft_Sync_MessageListManage::isLock('output')) {
         //如果锁定
         exit;
     }
     //锁定接口
     Pft_Sync_MessageListManage::AddLock('output');
     //调用消息序列管理器,获取消息序列
     /*
     $msg = new MSG();
     $msg->openMsgPool();
     while( $msg->getMsg() ){
     	
     }
     */
     //获取所有的SQL消息
     $msgSqlArray = Pft_Sync_MessageListManage::getAllMessageSql();
     $msgSqlValue = array();
     if (is_array($msgSqlArray) && count($msgSqlArray)) {
         foreach ($msgSqlArray as $k => $v) {
             $rev = Pft_Sync_MessageListManage::executeMessageSql($v);
             if ($rev) {
                 //获取外部被动输入接口地址
                 $passiveInputAddress = Pft_Sync_MessageListManage::getPassiveInputInterface('INSIDE_TPM');
                 if ($passiveInputAddress) {
                     //获取地址成功
                     //以post的方式向接口提交数据
                     $data = array('obj' => 'msgSqlValue', 'msgList' => urlencode(serialize($rev)), 'msgSign' => urlencode(serialize($k)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     if (BaseOption::postToHost($passiveInputAddress, $data)) {
                         //成功
                         //删除消息SQL
                         Pft_Sync_MessageListManage::delMessageSql($k);
                     } else {
                         //移动消息SQL
                         Pft_Sync_MessageListManage::moveMsgSql($k);
                     }
                 }
             }
         }
     }
     //消息序列的处理
     //------------外部unknown中的数据处理  start---------------//
     //获取外部被动输入接口地址
     $passiveInputAddress = Pft_Sync_MessageListManage::getPassiveInputInterface('INSIDE_TPM');
     $passiveOutputAddress = Pft_Sync_MessageListManage::getPassiveOutputInterface();
     if ($passiveOutputAddress) {
         //获取外部unknown目录中的数据
         $data = array('msgType' => 'msglist', 'msgListDir' => 'unknown', 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
         $msgList_unknown = BaseOption::postToHost($passiveOutputAddress, $data);
         $msgSign_outsite_unknown = unserialize($msgList_unknown);
         if (is_array($msgSign_outsite_unknown) && count($msgSign_outsite_unknown)) {
             //unknown目录中存在数据
             $msgSignArr = array_keys($msgSign_outsite_unknown);
             //删除本地的消息
             //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr)
             $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
             if ($result) {
                 //删除成功
                 //告诉外部,将序列从unknown中移动到outside
                 $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                 $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                 if ($rev1) {
                 } else {
                     $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                     //解除锁定
                     Pft_Sync_MessageListManage::DelLock('output');
                     exit;
                 }
             } else {
                 $loger->log('删除内部消息序列失败');
                 //解除锁定
                 Pft_Sync_MessageListManage::DelLock('output');
                 exit;
             }
         }
     }
     //------------外部unknown中的数据处理  end---------------//
     //获取所有的消息序列
     $msgListArray = Pft_Sync_MessageListManage::getAllMessageList();
     $msgList_execute = array();
     $num_del = Pft_Sync_MessageListManage::getNumOnceDel();
     //一次删除消息序列的个数
     if (is_array($msgListArray) && count($msgListArray) && $passiveInputAddress) {
         $str = "访问的被动输入接口:" . $passiveInputAddress;
         $loger = new Pft_Log_File('sync');
         $loger->log($str);
         foreach ($msgListArray as $key => $val) {
             foreach ($val as $k => $v) {
                 //--------------------- 数据过滤器  start---------------------//
                 //根据创建消息序列的服务器类型获取过滤器
                 $filterNameList = Pft_Sync_MessageListManage::getMsgListFilter($v['syncServerType']);
                 //调用过滤器过滤数据
                 if (is_array($filterNameList) && count($filterNameList)) {
                     foreach ($filterNameList as $filterName) {
                         $aFilter = Pft_Sync_Filter::filterFactory($filterName);
                         if ($aFilter) {
                             $v = $aFilter->filter($v);
                         }
                     }
                 }
                 //如果字段为空,删除消息序列
                 if (($v['operate'] == 'UPDATE' || $v['operate'] == 'INSERT') && !count($v['cols']) || !count($v)) {
                     //删除序列
                     //Pft_Sync_MessageListManage::delMessageList($key);
                     unset($val[$k]);
                     continue;
                 }
                 //--------------------- 数据过滤器  end---------------------//
                 if (count($msgList_execute) < $num_del - 1) {
                     $msgList_execute[$key] = $val;
                 } else {
                     //满足个数
                     $msgList_execute[$key] = $val;
                     $msgSignArr = array_keys($msgList_execute);
                     //向被动输入接口传数据,移动到未明目录
                     $data = array('obj' => 'file', 'msgList' => urlencode(serialize($msgList_execute)), 'msgListDir' => 'unknown', 'msgSign' => urlencode(serialize('')), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     $rev = BaseOption::postToHost($passiveInputAddress, $data);
                     if ($rev == '1') {
                         //删除
                         //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr)
                         $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
                         if ($result) {
                             //删除成功
                             //以post的方式向接口提交数据
                             $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                             $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                             if ($rev1 == '1') {
                                 //清空数组
                                 $msgList_execute = array();
                             } else {
                                 //移动失败
                                 $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                                 //解除锁定
                                 Pft_Sync_MessageListManage::DelLock('output');
                                 exit;
                             }
                         } else {
                             //删除失败
                             $loger->log('删除内部消息序列失败');
                             //解除锁定
                             Pft_Sync_MessageListManage::DelLock('output');
                             exit;
                         }
                     } else {
                         $loger->log('移动消息序列到unknown目录失败,访问接口:' . $passiveInputAddress);
                         //解除锁定
                         Pft_Sync_MessageListManage::DelLock('output');
                         exit;
                     }
                 }
             }
             /*
             				//--------------------- 数据过滤器  start---------------------//
             				//根据创建消息序列的服务器类型获取过滤器
             				$filterNameList = Pft_Sync_MessageListManage::getMsgListFilter($val['syncServerType']);				
             				//调用过滤器过滤数据				
             				if(is_array($filterNameList) && count($filterNameList))
             				{
             					foreach ( $filterNameList as $filterName )
             					{
             						$aFilter = Pft_Sync_Filter::filterFactory( $filterName );
             						if( $aFilter ){
             							$val = $aFilter->filter( $val );
             						}
             					}
             				}
             				
             				//如果字段为空,删除消息序列
             				if((($val['operate']=='UPDATE'||$val['operate']=='INSERT') && !count($val['cols'])) || !count($val)){
             					//删除序列
             					Pft_Sync_MessageListManage::delMessageList($key);
             					continue;
             				}	
             				//--------------------- 数据过滤器  end---------------------//
             				
             				if (count($msgList_execute)<($num_del-1))
             				{
             					$msgList_execute[$key] = $val;
             				}else
             				{//满足个数
             					$msgList_execute[$key] = $val;
             					$msgSignArr = array_keys($msgList_execute);	
             					//向被动输入接口传数据,移动到未明目录
             					$data = array(
             									'obj' =>'file',
             									'msgList' => urlencode(serialize($msgList_execute)),
             									'msgListDir' => 'unknown',
             									'msgSign' => urlencode(serialize('')),
             									'validatePassword'=>Pft_Sync_MessageListManage::getValidatePassword()
             								);	
             					$rev = BaseOption::postToHost($passiveInputAddress,$data);	
             					if ($rev == '1'){
             						//删除
             						if (Pft_Sync_MessageListManage::delMessageList($msgSignArr))
             						{//删除成功
             							//以post的方式向接口提交数据
             							$data = array(
             											'obj' =>'file',
             											'msgList' => urlencode(serialize('')),
             											'msgListDir' => 'outside',
             											'msgSign' => urlencode(serialize($msgSignArr)),
             											'validatePassword'=>Pft_Sync_MessageListManage::getValidatePassword()
             										);		
             														
             							$rev1 = BaseOption::postToHost($passiveInputAddress,$data);	
             							if ($rev1 == '1'){
             								//清空数组
             								$msgList_execute=array();	
             							}else{//移动失败								
             								$loger->log( '移动消息序列到outside目录失败,访问接口:'.$passiveInputAddress );
             								//解除锁定
             								Pft_Sync_MessageListManage::DelLock('output');
             								exit;
             							}
             						}else
             						{//删除失败
             							$loger->log( '删除内部消息序列失败' );
             							//解除锁定
             							Pft_Sync_MessageListManage::DelLock('output');
             							exit;
             						}
             					}else
             					{
             						$loger->log( '移动消息序列到unknown目录失败,访问接口:'.$passiveInputAddress );
             						//解除锁定
             						Pft_Sync_MessageListManage::DelLock('output');
             						exit;
             					}	
             				}*/
         }
         //最后不满足个数的操作
         if (is_array($msgList_execute) && count($msgList_execute)) {
             $msgSignArr = array_keys($msgList_execute);
             //向被动输入接口传数据,移动到未明目录
             $data = array('obj' => 'file', 'msgList' => urlencode(serialize($msgList_execute)), 'msgListDir' => 'unknown', 'msgSign' => urlencode(serialize('')), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
             $rev = BaseOption::postToHost($passiveInputAddress, $data);
             if ($rev) {
                 //删除
                 //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr);
                 $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
                 if ($result) {
                     //删除成功
                     //以post的方式向接口提交数据
                     $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                     if ($rev1 == '1') {
                         //清空数组
                         $msgList_execute = array();
                     } else {
                         //移动失败
                         $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                         //解除锁定
                         Pft_Sync_MessageListManage::DelLock('output');
                         exit;
                     }
                 } else {
                     //删除失败
                     $loger->log('删除内部消息序列失败');
                     //解除锁定
                     Pft_Sync_MessageListManage::DelLock('output');
                     exit;
                 }
             } else {
                 $loger->log('移动消息序列到unknown目录失败,访问接口:' . $passiveInputAddress);
                 //解除锁定
                 Pft_Sync_MessageListManage::DelLock('output');
                 exit;
             }
         }
     }
     //解除锁定
     Pft_Sync_MessageListManage::DelLock('output');
     //echo microtime()."<br>";
 }