Android Open Source - msghandle Init Requ Message Server






From Project

Back to project page msghandle.

License

The source code is released under:

GNU General Public License

If you think the Android project msghandle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.anlong.msghandle.message;
//  ww w . jav a 2  s . c  om
import java.util.Timer;
import java.util.TimerTask;

import android.util.Log;

import com.anlong.msghandle.common.HandleStaticValue;
import com.anlong.msghandle.handle.MsgRequestHandle;
import com.anlong.msghandle.service.InitServerManager;
import com.anlong.msghandle.socket.InitMsgSocketServer;
import com.anlong.msghandle.util.Utils;


/**
 * @Title: InitRequMessageServer.java 
 * @Package com.anlong.msghandle.message
 * @company ShenZhen AnLong Technology CO.,LTD.   
 * @author lixl   
 * @date 2014-3-12 ????5:17:10 
 * @version V1.0   
 * @Description: ??????????????????
 */
public class InitRequMessageServer implements Runnable{
  // ????
  private Object request = null;
  // ???
  private static Timer timer = null;
  // ??????????????
  private static boolean timerCancel = false;
  // ??????????
  private static long startTime = 0;
  // ??????????
  private static long endTime = 0;
  // ??????
  private static boolean timeOut = false;
  
  /**
   * ????????????    ????
   * @param object
   */
  public InitRequMessageServer(Object object){
    request = object;
  }
  
  
  @Override
  public void run() {
    try { 
      
      if(InitMsgSocketServer.getInstance()==null||! InitMsgSocketServer.getInstance().isConnected()){
          // TODO ????Socket??
          try {
            InitMsgSocketServer.init(HandleStaticValue.SERVER_IP,HandleStaticValue.SERVER_PORT);
          } catch (java.net.SocketTimeoutException e) {
            Log.e("test", "----?? InitRequMessageServer socket ??????????????????'???ip?????????????----------->");
            // TODO ???????????? 
            Utils.notifyMessage(8,HandleStaticValue.BCODE1000);
            return;
          }catch (Exception e) { 
            Log.e("test", "----?? InitRequMessageServer socket ?????????????----------->");
            // TODO ????????????
            Utils.notifyMessage(8,HandleStaticValue.BCODE1000);
          }
          // TODO ??Socket????
          getInstanceTimer();
          while(!timerCancel){
            //IMLog.anlong("??????Socket??...");
            // ??0.05?
            Thread.sleep(50);
          }  
          // TODO ??????
          if (timeOut){
            Log.e("test", "----??socket ???????????????????----------->");
            // TODO ????????????
            Utils.notifyMessage(8,HandleStaticValue.BCODE1000);
            return;
          }
          // TODO ???????????????????
          Utils.notifyMessage(5,HandleStaticValue.BCODE1000);
          
          // TODO ?????????????
          InitServerManager.startResponseMessageService();
          // TODO ???????????????
          InitServerManager.startMessageTimerService();
        }
        
      try {
        MsgRequestHandle.getInstance().encode(request);
      } catch (Exception e) {
        Utils.notifyMessage(6,HandleStaticValue.BCODE1000);
        e.printStackTrace();
      }
        
    } catch (Exception e) {
      InitMsgSocketServer.closeSocketConnection();
      // TODO ????????????
      Utils.notifyMessage(3,HandleStaticValue.BCODE1000);
      e.printStackTrace();
    }
  }
  
  /**
   * @Title: notifyMessage 
   * @Description: TODO ???????
   * @author anlong 
   * @throws
   */
  private static void getInstanceTimer(){
        if ( timer == null ){
            timer = new Timer();
            // ??????????
            startTime = System.currentTimeMillis();
            // ?1?????????,?????2?    
            timer.schedule(new RunTask(), 1000, 2000);
            //timer.cancel();
        }
    }
  
  /**
   * @Title: notifyMessage 
   * @Description: TODO ???
   * @author anlong 
   * @throws
   */
  static class RunTask extends TimerTask{
    public RunTask(){
      // ????????
      endTime = System.currentTimeMillis();
      // ??20???
      if((endTime - startTime) > HandleStaticValue.SERVER_CONNECTION_TIMEOUT){
        timeOut = true;
        timerCancel = true;
        timer.cancel();
      }
    }
    @Override
    public void run(){
      if ( InitMsgSocketServer.getInstance() != null ){
        timerCancel = true;
        timer.cancel();
      } 
    }
  }



}




Java Source Code List

com.anlong.msghandle.common.BaseMessage.java
com.anlong.msghandle.common.HandleStaticValue.java
com.anlong.msghandle.common.HandleTimer.java
com.anlong.msghandle.common.MessageTimer.java
com.anlong.msghandle.event.MessageEventListener.java
com.anlong.msghandle.event.MessageEventSource.java
com.anlong.msghandle.event.MessageEvent.java
com.anlong.msghandle.file.InitImageFileServer.java
com.anlong.msghandle.handle.ImageRequestHandle.java
com.anlong.msghandle.handle.ImageResponseHandle.java
com.anlong.msghandle.handle.MsgRequestHandle.java
com.anlong.msghandle.handle.MsgResponseHandle.java
com.anlong.msghandle.impl.AppParamImpl.java
com.anlong.msghandle.impl.AppSystemMessageReportImpl.java
com.anlong.msghandle.impl.AuthenticationImpl.java
com.anlong.msghandle.impl.BroadcastImpl.java
com.anlong.msghandle.impl.CommonContactImpl.java
com.anlong.msghandle.impl.DepImpl.java
com.anlong.msghandle.impl.DepInfoListImpl.java
com.anlong.msghandle.impl.EditGroupImpl.java
com.anlong.msghandle.impl.EditGroupUserImpl.java
com.anlong.msghandle.impl.EditUserInfoImpl.java
com.anlong.msghandle.impl.ExitPreventGroupImpl.java
com.anlong.msghandle.impl.GetGroupInfoImpl.java
com.anlong.msghandle.impl.GetHistoryMessageImpl.java
com.anlong.msghandle.impl.GetUserInfoImpl105.java
com.anlong.msghandle.impl.GroupInfoListImpl.java
com.anlong.msghandle.impl.GroupShareImpl.java
com.anlong.msghandle.impl.HeartImpl103.java
com.anlong.msghandle.impl.LocationImpl.java
com.anlong.msghandle.impl.LoginImpl101.java
com.anlong.msghandle.impl.MessageStateReportImpl.java
com.anlong.msghandle.impl.OnlineStateImpl102.java
com.anlong.msghandle.impl.OnlineUserListImpl110.java
com.anlong.msghandle.impl.SendImageFile.java
com.anlong.msghandle.impl.SendMessageImpl203.java
com.anlong.msghandle.impl.SystemParaImpl.java
com.anlong.msghandle.impl.UnreadMessageImpl.java
com.anlong.msghandle.impl.UpdatePasswordImpl.java
com.anlong.msghandle.impl.UserInfoListImpl.java
com.anlong.msghandle.interfac.AbstractMsgHandle.java
com.anlong.msghandle.interfac.BaseActivity.java
com.anlong.msghandle.interfac.MessageHandleActivity.java
com.anlong.msghandle.interfac.MsgHandle.java
com.anlong.msghandle.message.InitRequMessageServer.java
com.anlong.msghandle.message.InitRespMessageServer.java
com.anlong.msghandle.request.BaseRequest.java
com.anlong.msghandle.request.Request100.java
com.anlong.msghandle.request.Request101.java
com.anlong.msghandle.request.Request102.java
com.anlong.msghandle.request.Request103.java
com.anlong.msghandle.request.Request105.java
com.anlong.msghandle.request.Request110.java
com.anlong.msghandle.request.Request203.java
com.anlong.msghandle.request.Request301.java
com.anlong.msghandle.response.BaseResponse.java
com.anlong.msghandle.response.Response1000.java
com.anlong.msghandle.response.Response1010.java
com.anlong.msghandle.response.Response1020.java
com.anlong.msghandle.response.Response1030.java
com.anlong.msghandle.response.Response1050.java
com.anlong.msghandle.response.Response1100.java
com.anlong.msghandle.response.Response2030.java
com.anlong.msghandle.response.Response3010.java
com.anlong.msghandle.service.InitServerManager.java
com.anlong.msghandle.service.ServerManager.java
com.anlong.msghandle.socket.InitFileSocketServer.java
com.anlong.msghandle.socket.InitMsgSocketServer.java
com.anlong.msghandle.util.ByteAndInt.java
com.anlong.msghandle.util.FormatTransfer.java
com.anlong.msghandle.util.IMLog.java
com.anlong.msghandle.util.ReflectionUtil.java
com.anlong.msghandle.util.Utils.java
com.anlong.msghandle.vo.AppMessage.java
com.anlong.msghandle.vo.Application.java
com.anlong.msghandle.vo.BroadcastMessage.java
com.anlong.msghandle.vo.DepInfo.java
com.anlong.msghandle.vo.GroupInfo.java
com.anlong.msghandle.vo.GroupShare.java
com.anlong.msghandle.vo.OnlineUser.java
com.anlong.msghandle.vo.ReportState.java
com.anlong.msghandle.vo.SimpleUserInfo.java
com.anlong.msghandle.vo.UserInfo.java
com.anlong.msghandle.vo.UserMessage.java