Exemplo 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;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
 }