Пример #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>();
 }
Пример #2
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;
 }