Esempio n. 1
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;
  }
Esempio n. 2
0
 public boolean createPackage(Pack pack) {
   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 mDTHPack = pack.toDTHPackages();
     LOG.info("message building time: " + (System.currentTimeMillis() - time));
     time = System.currentTimeMillis();
     try {
       if (dthmq.send(mDTHPack, Constants.Web2AppServ.SEND_CREATE_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("Create Package successfully");
         } else {
           Common.DTHCommon.ACKMessage mess = Common.DTHCommon.ACKMessage.parseFrom(core.content);
           LOG.error("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;
 }