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

📄 .#message.java.1.6

📁 采用JAVA开发
💻 6
字号:
package com.gctech.sms.sp.cms.msg;
import java.io.*;
import com.gctech.sms.sp.cms.util.*;
import org.apache.log4j.Logger;
public abstract class Message implements java.io.Serializable{
  public int totalLength = 0;
  public int commandId = 0;
  public int commandStatus = 0;
  public  int sequenceId = 0;
  static Logger logger = Logger.getLogger(Message.class);
  public static IDGenerator idg = new IDGenerator(0,99999999);

  public Message()
  {
  }

  public static int nextSeqId()
  {
    return idg.nextId();
  }

  public String toString()
  {
    return "type:"+commandId+" seq:"+sequenceId+" status:"+commandStatus;
  }
  public abstract byte[] toBytes();



  public static void main(String[] args) {
//    Message message1 = new Message();
  }


  /**
   *
   * @param in
   * @return
   */
  public static Message create(InputStream in)
  {
    // 读取消息长度
    byte[] totalLengthByte = new byte[4];

    try
    {
      int realSize = in.read(totalLengthByte);
      if(realSize!=4)
      {
        if(logger.isDebugEnabled())logger.debug("read totalLength error "+realSize);
        return null;
      }
    }
    catch(Exception e)
    {
//      try
//      {
//        Thread.sleep(1000*5);
//      }
//      catch(Exception ex)
//      {
//
//      }

      logger.debug(e.getMessage());
      return null;
    }
    int totalLength = TypesTools.byte2int(totalLengthByte);
    //读取消息内容
    byte[] bs = new byte[totalLength-4];

    try
    {
      int  realSize = in.read(bs);
      if(realSize != bs.length) {
        if(logger.isDebugEnabled())logger.debug("read byte error ,"+totalLength+" expected but "+realSize);
        return null;
      }

    }
    catch(Exception ex)
    {
      logger.debug(ex.getMessage());
      return null;
    }


    int commandId = TypesTools.byte2int(bs,0);
    try
    {
      switch(commandId)
      {
        case LOGIN_RES:
        {
          Message m = LoginResMessage.createMessage(bs);
          return m;
        }
        case ACTIVE_TEST_RES:
        {
//          if(logger.isDebugEnabled())logger.debug("recive activityRes message ");
          Message m = ActiveTestResMessage.createMessage(bs);
          return m;
        }
        case DELIVER:
        {
//          if(logger.isDebugEnabled())logger.debug("recive deliver message ");
          Message m = DeliverMessage.createMessage(bs);
          return m;
        }
        case SUBMIT_RES:
        {
//          if(logger.isDebugEnabled())logger.debug("recive submit res message ");
          Message m = SubmitResMessage.createMessage(bs);
          return m;
        }
        case EXIT_RES:
        {
          Message m = ExitResMessage.createMessage(bs);
          return m;

        }
        default:
        {
          logger.info("不能识别 commandId : " + commandId);
          return null;
        }

      }

    }
    catch(Exception e)
    {
      if(logger.isDebugEnabled())logger.debug(e.getMessage());
      e.printStackTrace();
      return null;

    }

  }

  public static final int ERROR_MSG = 0x00000000;
  //登录
  public static final int LOGIN_REQ = 0x00000001;
  public static final int LOGIN_RES = 0x80000001;
//提交
  public static final int SUBMIT_REQ = 0x00000002;
  public static final int SUBMIT_RES = 0x80000002;
//订阅
  public static final int SUBSCRIBE_REQ = 0x00000003;
  public static final int SUBSCRIBE_RES = 0x80000003;
//退订
  public static final int UNSUBSCRIBE_REQ = 0x00000004;
  public static final int UNSUBSCRIBE_RES = 0x80000004;
//测试
  public static final int ACTIVE_TEST_REQ = 0x00000005;
  public static final int ACTIVE_TEST_RES = 0x80000005;
//退出
  public static final int EXIT_REQ = 0x00000006;
  public static final int EXIT_RES = 0x80000006;
//Deliver短信上行
  public static final int DELIVER = 0x00000010;
  public static final int DELIVER_RESP = 0x80000010;


}

⌨️ 快捷键说明

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