Пример #1
0
  public ProbeRequest(SimpleFieldSet fs) throws MessageInvalidException {
    /* If not defined in the field set Identifier will be null. As adding a null value to the field set does
     * not actually add something under the key, it will also be omitted in the response messages.
     */
    this.identifier = fs.get(IDENTIFIER);

    try {
      this.type = Type.valueOf(fs.get(TYPE));

      // If HTL is not specified default to MAX_HTL.
      this.htl = fs.get(HTL) == null ? Probe.MAX_HTL : fs.getByte(HTL);

      if (this.htl < 0) {
        throw new MessageInvalidException(
            ProtocolErrorMessage.INVALID_MESSAGE, "hopsToLive cannot be negative.", null, false);
      }

    } catch (IllegalArgumentException e) {
      throw new MessageInvalidException(
          ProtocolErrorMessage.INVALID_MESSAGE,
          "Unrecognized parse probe type \"" + fs.get(TYPE) + "\": " + e,
          null,
          false);
    } catch (FSParseException e) {
      // Getting a String from a SimpleFieldSet does not throw - it can at worst return null.
      throw new MessageInvalidException(
          ProtocolErrorMessage.INVALID_MESSAGE,
          "Unable to parse hopsToLive \"" + fs.get(HTL) + "\": " + e,
          null,
          false);
    }
  }