Ejemplo n.º 1
0
 private List<Card> getListCard(int start, int itemPerPage) {
   DTHMQ dthmq = getDTHMQ();
   if (dthmq.connect()) {
     try {
       Common.DTHCommon.DTHGetRequest get =
           Common.DTHCommon.DTHGetRequest.newBuilder()
               .setStart(start)
               .setNumber(itemPerPage)
               .build();
       if (dthmq.send(get, Constants.Web2AppServ.SEND_GET_LIST_CARD, 0, false, 30)) {
         CoreMessage core = dthmq.getResponseMessage();
         if (core.type == Constants.AppServ2Web.RET_GET_LIST_CARD_SUCCESS) {
           Service.DTHService.RetDTHCards cards =
               Service.DTHService.RetDTHCards.parseFrom(core.content);
           List<Card> lCards = new ArrayList<Card>();
           for (DTHCards cs : cards.getCardsList()) {
             Card c = new Card(cs);
             lCards.add(c);
           }
           return lCards;
         }
       }
     } catch (InvalidProtocolBufferException ex) {
     } catch (SendTcpException ex) {
     }
   }
   return new ArrayList<Card>();
 }
Ejemplo n.º 2
0
  public boolean updatePackage(Pack pack, List<Integer> channelList) {
    LOG.info("(_ __\")");
    boolean result = false;
    DTHMQ dthmq = getDTHMQ();
    long time = System.currentTimeMillis();
    if (dthmq.connect()) {
      LOG.info("connect time: " + (System.currentTimeMillis() - time));
      time = System.currentTimeMillis();
      Service.DTHService.DTHPackages.Builder bld = Service.DTHService.DTHPackages.newBuilder();
      bld.setId(pack.getId()).setTitle(pack.getTitle()).setDescription(pack.getDescription());
      if (channelList != null) {
        LOG.info("size of channel list: " + channelList.size());
        // Service.DTHService.DTHListGroupChannel.Builder builder =
        // Service.DTHService.DTHListGroupChannel.newBuilder();
        LOG.info("WTH");
        Service.DTHService.DTHListGroupChannel.Builder builder =
            Service.DTHService.DTHListGroupChannel.newBuilder();
        for (Integer i : channelList) {
          LOG.info("Group: " + i.toString());
          Service.DTHService.DTHGroupChannel gChannel =
              Service.DTHService.DTHGroupChannel.newBuilder().setId(i.intValue()).build();
          // builder.addGroupChannel(gChannel);
          bld.addGroups(gChannel);
        }
        // Service.DTHService.DTHListGroupChannel listGcn = builder.build();
        // bld.addAllGroups(listGcn.getGroupChannelList());
      }
      Service.DTHService.DTHPackages sendPack = bld.build();
      LOG.info("<==[=================>" + pack.getId());
      LOG.info("message building time: " + (System.currentTimeMillis() - time));
      time = System.currentTimeMillis();
      try {
        if (dthmq.send(sendPack, Constants.Web2AppServ.SEND_UPDATE_PACKAGE, 0, false, 30)) {
          LOG.info("send and response: " + (System.currentTimeMillis() - time));
          time = System.currentTimeMillis();

          CoreMessage core = dthmq.getResponseMessage();
          if (core.type == Constants.AppServ2Web.COMMON_SUCCESS) {
            // Others.DTHOthers.DTHListFaq mDTHFaqList =
            // Others.DTHOthers.DTHListFaq.parseFrom(core.content);
            result = true;
            LOG.info("Update package successfully");
          } else {
            Common.DTHCommon.ACKMessage mess = Common.DTHCommon.ACKMessage.parseFrom(core.content);
            LOG.info("Error code " + mess.getCode() + ": " + mess.getMessage());
          }
        } else {
          LOG.error("DTHMQ connection time out.");
        }
      } catch (SendTcpException e) {
        DTHLog.getInstance().logErr(e, "Parse error");
        LOG.error("Response parse error");
      } catch (InvalidProtocolBufferException e) {
        DTHLog.getInstance().logErr(e, "Send error");
        LOG.error("Send package resquest error.");
      }
    }
    return result;
  }
Ejemplo n.º 3
0
 public List<Pack> getPackageList(int start, int end) {
   List<Pack> list = null;
   DTHMQ dthmq = getDTHMQ();
   long time = System.currentTimeMillis();
   if (dthmq.connect()) {
     LOG.info("connect time: " + (System.currentTimeMillis() - time));
     time = System.currentTimeMillis();
     Common.DTHCommon.DTHGetRequest sendList =
         Common.DTHCommon.DTHGetRequest.newBuilder().setStart(start).setNumber(end).build();
     LOG.info("message building time: " + (System.currentTimeMillis() - time));
     time = System.currentTimeMillis();
     try {
       if (dthmq.send(sendList, Constants.Web2AppServ.SEND_GET_LIST_PACKAGE, 0, false, 30)) {
         LOG.info("send and response: " + (System.currentTimeMillis() - time));
         time = System.currentTimeMillis();
         CoreMessage core = dthmq.getResponseMessage();
         if (core.type == Constants.AppServ2Web.RET_GET_LIST_PACK_SUCCESS) {
           Service.DTHService.DTHListPackage rsList =
               Service.DTHService.DTHListPackage.parseFrom(core.content);
           list = new ArrayList<Pack>();
           for (Service.DTHService.DTHPackages p : rsList.getPackageList()) {
             Pack pack = new Pack(p);
             list.add(pack);
           }
           LOG.info("Get Package successfully, total: " + rsList.getPackageCount());
         } else {
           Common.DTHCommon.ACKMessage mess = Common.DTHCommon.ACKMessage.parseFrom(core.content);
           LOG.info("Account " + mess.getCode() + ": " + mess.getMessage());
         }
       } else {
         LOG.error("DTHMQ connection time out.");
       }
     } catch (SendTcpException e) {
       DTHLog.getInstance().logErr(e, "Parse error");
       LOG.error("Response parse error");
     } catch (InvalidProtocolBufferException e) {
       DTHLog.getInstance().logErr(e, "Send error");
       LOG.error("Send Package resquest error.");
     }
   }
   return list;
 }
Ejemplo n.º 4
0
  public boolean updateLogo(int id, String logo) {
    boolean result = false;
    DTHMQ dthmq = getDTHMQ();
    long time = System.currentTimeMillis();
    if (dthmq.connect()) {
      LOG.info("connect time: " + (System.currentTimeMillis() - time));
      time = System.currentTimeMillis();

      Service.DTHService.DTHPackages sendPack =
          Service.DTHService.DTHPackages.newBuilder().setId(id).setLogo(logo).build();
      LOG.info("message building time: " + (System.currentTimeMillis() - time));
      time = System.currentTimeMillis();
      try {
        if (dthmq.send(sendPack, Constants.Web2AppServ.SEND_UPDATE_PACKAGE, 0, false, 30)) {
          LOG.info("send and response: " + (System.currentTimeMillis() - time));
          time = System.currentTimeMillis();

          CoreMessage core = dthmq.getResponseMessage();
          if (core.type == Constants.AppServ2Web.COMMON_SUCCESS) {
            // Others.DTHOthers.DTHListFaq mDTHFaqList =
            // Others.DTHOthers.DTHListFaq.parseFrom(core.content);
            result = true;
            LOG.info("Update pack logo channel successfully");
          } else {
            Common.DTHCommon.ACKMessage mess = Common.DTHCommon.ACKMessage.parseFrom(core.content);
            LOG.info("Error code " + mess.getCode() + ": " + mess.getMessage());
          }
        } else {
          LOG.error("DTHMQ connection time out.");
        }
      } catch (SendTcpException e) {
        DTHLog.getInstance().logErr(e, "Parse error");
        LOG.error("Response parse error");
      } catch (InvalidProtocolBufferException e) {
        DTHLog.getInstance().logErr(e, "Send error");
        LOG.error("Send pack channel resquest error.");
      }
    }
    return result;
  }
Ejemplo n.º 5
0
 public Pack getPackageById(int id) {
   Pack pack = null;
   DTHMQ dthmq = getDTHMQ();
   long time = System.currentTimeMillis();
   if (dthmq.connect()) {
     LOG.info("connect time: " + (System.currentTimeMillis() - time));
     time = System.currentTimeMillis();
     Service.DTHService.DTHPackages sendMess =
         Service.DTHService.DTHPackages.newBuilder().setId(id).build();
     LOG.info("message building time: " + (System.currentTimeMillis() - time));
     time = System.currentTimeMillis();
     try {
       if (dthmq.send(sendMess, Constants.Web2AppServ.SEND_GET_PACKAGE, 0, false, 30)) {
         LOG.info("send and response: " + (System.currentTimeMillis() - time));
         time = System.currentTimeMillis();
         CoreMessage core = dthmq.getResponseMessage();
         if (core.type == Constants.AppServ2Web.RET_GET_PACK_SUCCESS) {
           Service.DTHService.DTHPackages ret =
               Service.DTHService.DTHPackages.parseFrom(core.content);
           if (ret.getId() != 0) {
             pack = new Pack(ret);
             LOG.info("Get package successfully");
           }
         } else {
           Common.DTHCommon.ACKMessage mess = Common.DTHCommon.ACKMessage.parseFrom(core.content);
           LOG.info("Error code " + mess.getCode() + ": " + mess.getMessage());
         }
       } else {
         LOG.error("DTHMQ connection time out.");
       }
     } catch (SendTcpException e) {
       DTHLog.getInstance().logErr(e, "Parse error");
       LOG.error("Response parse error");
     } catch (InvalidProtocolBufferException e) {
       DTHLog.getInstance().logErr(e, "Send error");
       LOG.error("Send package resquest error.");
     }
   }
   return pack;
 }