Esempio n. 1
0
 private static void sendDirect(List<byte[]> buff) {
   switch (buff.size()) {
     case 1:
       udpNet.write(buff.get(0));
       break;
     default:
       udpNet.write(buff);
       break;
   }
 }
Esempio n. 2
0
 public static void sendHeartBeat(ObjectPack p) {
   try {
     udpCollect.write(new DataOutputX().writePack(p).toByteArray());
   } catch (Exception e) {
   }
   if (conf.debug_udp_object) {
     Logger.info(p.toString());
   }
 }
Esempio n. 3
0
 public static void sendError(int hash, String message) {
   if (errText.contains(hash)) {
     return;
   }
   errText.put(hash);
   try {
     udpCollect.write(
         new DataOutputX().writePack(new TextPack(TextTypes.ERROR, hash, message)).toByteArray());
   } catch (Exception e) {
   }
 }
Esempio n. 4
0
 private static void sendDirect(Pack p) {
   try {
     udpNet.write(new DataOutputX().writePack(p).toByteArray());
   } catch (IOException e) {
   }
 }
Esempio n. 5
0
public class DataProxy {
  private static DataUdpAgent udpCollect = DataUdpAgent.getInstance();

  static Configure conf = Configure.getInstance();

  public static void sendAlert(byte level, String title, String message, MapValue tags) {
    AlertPack p = new AlertPack();
    p.objType = conf.scouter_type;
    p.objHash = conf.objHash;
    p.level = level;
    p.title = title;
    p.message = message;
    if (tags != null) {
      p.tags = tags;
    }

    sendDirect(p);
  }

  private static IntLinkedSet errText = new IntLinkedSet().setMax(10000);

  public static void sendError(int hash, String message) {
    if (errText.contains(hash)) {
      return;
    }
    errText.put(hash);
    try {
      udpCollect.write(
          new DataOutputX().writePack(new TextPack(TextTypes.ERROR, hash, message)).toByteArray());
    } catch (Exception e) {
    }
  }

  public static void reset() {
    errText.clear();
  }

  static DataUdpAgent udpNet = DataUdpAgent.getInstance();

  private static void sendDirect(Pack p) {
    try {
      udpNet.write(new DataOutputX().writePack(p).toByteArray());
    } catch (IOException e) {
    }
  }

  private static void sendDirect(List<byte[]> buff) {
    switch (buff.size()) {
      case 1:
        udpNet.write(buff.get(0));
        break;
      default:
        udpNet.write(buff);
        break;
    }
  }

  static DataUdpAgent udpDirect = DataUdpAgent.getInstance();

  public static void sendCounter(PerfCounterPack[] p) {
    // udp.add(p);
    try {
      List<byte[]> buff = new ArrayList<byte[]>();
      int bytes = 0;
      for (int k = 0; k < p.length; k++) {
        byte[] b = new DataOutputX().writePack(p[k]).toByteArray();
        if (bytes + b.length >= conf.udp_packet_max) {
          sendDirect(buff); // buff.size가 0일수도 있다.
          bytes = 0; // bytes 값 초기화..
          buff.clear();
        }
        bytes += b.length;
        buff.add(b);
      }
      sendDirect(buff);
    } catch (Exception e) {
    }
  }

  public static void sendHeartBeat(ObjectPack p) {
    try {
      udpCollect.write(new DataOutputX().writePack(p).toByteArray());
    } catch (Exception e) {
    }
    if (conf.debug_udp_object) {
      Logger.info(p.toString());
    }
  }
}