⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crbtreloadprocess.java

📁 中国联通炫铃业务接口开发
💻 JAVA
字号:
package com.wireless.crbt.gwif.workthread;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.log4j.Logger;

import com.wireless.crbt.gwif.function.CrbtScanDB;
import com.wireless.crbt.gwif.global.CrbtGWIFGlobal;
import com.wireless.crbt.gwif.global.GetCRBTGlobalForUsual;
import com.wireless.crbt.gwif.global.LoggerConstant;
import com.wireless.crbt.gwif.global.pub.CRBTQueue;
import com.wireless.crbt.gwif.global.pub.CRBTServerSocket;
import com.wireless.crbt.gwif.global.pub.RespQueue;
import com.wireless.gwif.socketconn.ConnManageInterface;

public class CrbtReloadProcess {
//	private CrbtGWIFGlobal smsagent = CrbtGWIFGlobal.getInstance();
	CRBTQueue crbtqueue = GetCRBTGlobalForUsual.crbtqueue;
    RespQueue respqueue = GetCRBTGlobalForUsual.respqueue;
    String[] mtflowfilepath = {};
    String moflowfilepath = "";
    Logger statlog = LoggerConstant.statlog;
    private static CrbtReloadProcess instance = null;

    public static synchronized CrbtReloadProcess getInstance(){
        if( instance == null ){
            instance = new CrbtReloadProcess();
        }
        return instance;
    }

    private CrbtReloadProcess() {
    }

    public void setLog(Logger log) {
        this.statlog = log;
    }
    
    /**
     * 停止与运营商的连接
     *
     */
    public void stopForConnect(){

        boolean opeFlag = false;
        //停止与运营商的连接
        for(int i=0; i<CrbtGWIFGlobal.vManage.size(); i++){
            ConnManageInterface oct =
                          (ConnManageInterface)CrbtGWIFGlobal.vManage.elementAt(i);
            oct.stop();

            for( int j=0; !(opeFlag = oct.isFinishStop()) && j<600; j++ ){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }

            statlog.info("停止与运营商连接 - "+(i+1) + (opeFlag?"正常退出":"强制退出"));
        }
    }
    
    /** 停止客户端控制线程 */
    public void stopForClientController(){
      CrbtClientController.stop();
    }

    /** 停止监控线程 */
    public void stopForSendMonitor(){
      CrbtSendMonitor.getInstance().stop();
    }
    
    /** 停止监听其他机器CRBT请求线程 */
    public void stopForCRBTServerSocket(){
    	int size = CrbtGWIFGlobal.MTserverSocketVec.size();
  	  for(int i=0;i<size;i++){
  		  Object templt = CrbtGWIFGlobal.MTserverSocketVec.elementAt(i);
  		  if(templt instanceof CRBTServerSocket){
  			  CRBTServerSocket temp = (CRBTServerSocket)templt;
  			  temp.stop();
  		  }
  	  }
    }
    
    /** 停止扫描数据库线程 */
    public void stopForCrbtScanDB(){
    	CrbtScanDB.stop();
    }
    
    /** 保存数据 */
    public void stopForSaveData(){
    	int count = 2;//保存数据失败重试次数
    	statlog.info("开始保存数据....crbtqueue.size = "+GetCRBTGlobalForUsual.crbtqueue.size()+
    			"   respqueue.size = "+GetCRBTGlobalForUsual.respqueue.size());
    	
    	/**保存CrbtQueue队列中的数据*/
    	while(GetCRBTGlobalForUsual.crbtqueue.size()>0 && (--count)>=0){
        	if(!CrbtScanDB.backCrbt()){
        		//失败处理
        	}
    	}
    	
    	/** 保存RespQueue队列中的数据 */
    	while(GetCRBTGlobalForUsual.respqueue.size()>0 && (--count)>=0){
    		if(CrbtScanDB.backResp()){
    			//失败处理
    		}
    	}
    	
//        statlog.info("保存数据完毕");
    }
    /**
     * 执行停止接口机步骤!
     *
     */
    public void stopInterface() {
        try {
    		stopForCrbtScanDB();
    		statlog.info("停止扫描数据库线程完毕------");
    	} catch (RuntimeException e2) {
    		LoggerConstant.statlog.error("停止扫描数据库线程异常:", e2);
    	}
    	
    	try{
    		Thread.sleep(50);
            stopForSaveData();
            statlog.info("保存数据完毕------");
          }catch(Exception e){
            LoggerConstant.statlog.error("保存数据异常 :", e);
          }

          try{
        	  stopForConnect();
        	  statlog.info("停止与运营商连接完毕------");
          }catch(Exception e){
        	  statlog.error("停止与运营商连接异常 :", e);
          }

          try{
        	  stopForClientController();
        	  statlog.info("连接控制器停止完毕------");
          }catch(Exception e){
        	  statlog.error("StopController Exception :", e);
          }
          
          try{
        	  stopForSendMonitor();
        	  statlog.info("停止监控线程完毕------");
          }catch(Exception e){
        	  statlog.error("停止监控线程异常 :", e);
          }
      
      
          try {
        	  stopForCRBTServerSocket();
        	  statlog.info("停止从其他机器接收CRBT线程完毕------");
          } catch (RuntimeException e1) {
        	  // TODO Auto-generated catch block
        	  e1.printStackTrace();
          }
      

          try{
        	  CrbtGWIFGlobal.vManage.clear();
        	  CrbtGWIFGlobal.MTserverSocketVec.clear();
        	  statlog.info("程序成功退出!");
          }catch(Exception e){
        	  statlog.error("Clear Exception :", e);
          }

          statlog.info("Stop Interface Framework Over !!! ");
    }

    /**
     * 重新启动 当运营商断开连接时调用
     */
    public void restartInterface(){
        stopInterface();

        /**
         * Write more code here.
         */
        }

    public String getStackTrace(Exception e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      e.printStackTrace(pw);
      return sw.toString();
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -