⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pduv1.java

📁 snmp4j
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @return
   *    nothing
   * @throws UnsupportedOperationException
   */
  public int getMaxRepetitions() {
    throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
  }

  /**
   * This method is not supported for SNMPv1 PDUs and will throw a
   * {@link java.lang.UnsupportedOperationException}
   * @param maxRepetitions int
   * @throws UnsupportedOperationException
   */
  public void setMaxRepetitions(int maxRepetitions) {
    throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
  }

  /**
   * This method is not supported for SNMPv1 PDUs and will throw a
   * {@link java.lang.UnsupportedOperationException}
   *
   * @param maxSizeScopedPDU int
   * @throws UnsupportedOperationException
   */
  public void setMaxSizeScopedPDU(int maxSizeScopedPDU) {
    throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
  }

  /**
   * This method is not supported for SNMPv1 PDUs and will throw a
   * {@link java.lang.UnsupportedOperationException}
   *
   * @param nonRepeaters int
   * @throws UnsupportedOperationException
   */
  public void setNonRepeaters(int nonRepeaters) {
    throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
  }

  private void checkV1TRAP() {
    if (getType() != PDU.V1TRAP) {
      throw new UnsupportedOperationException(
          "Operation is only supported for SNMPv1 trap PDUs (V1TRAP)");
    }
  }

  /**
   * Gets the "enterprise" OID of the SNMPv1 trap. The enterprise OID could be
   * any OID although the name could lead to the assumption that the
   * enterprise OID has to be an OID under the
   * iso(1).org(3).dod(6).internet(1).private(4).enterprises(1) node, but that's
   * not true.
   *
   * @return
   *    an OID instance.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public OID getEnterprise() {
    checkV1TRAP();
    return enterprise;
  }

  /**
   * Sets the "enterprise" OID of the SNMPv1 trap. The enterprise OID could be
   * any OID although the name could lead to the assumption that the
   * enterprise OID has to be an OID under the
   * iso(1).org(3).dod(6).internet(1).private(4).enterprises(1) node, but that's
   * not true.
   *
   * @param enterprise
   *    an OID instance.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public void setEnterprise(org.snmp4j.smi.OID enterprise) {
    checkV1TRAP();
    checkNull(enterprise);
    this.enterprise = (OID) enterprise.clone();
  }

  /**
   * Gets the IP address of the originator system of this SNMPv1 trap.
   * If this value is 0.0.0.0 (the recommended default), then the address
   * of the peer SNMP entity should be extracted from the {@link Target}
   * object associated with this PDU.
   *
   * @return
   *    an IpAddress instance.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public org.snmp4j.smi.IpAddress getAgentAddress() {
    checkV1TRAP();
    return agentAddress;
  }

  /**
   * Sets the IP address of the originator system of this SNMPv1 trap.
   * The default value is 0.0.0.0, which should be only overriden in special
   * cases, for example when forwarding SNMPv1 traps through a SNMP proxy.
   * @param agentAddress
   *    a <code>IpAddress</code> instance.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public void setAgentAddress(org.snmp4j.smi.IpAddress agentAddress) {
    checkV1TRAP();
    checkNull(agentAddress);
    this.agentAddress = agentAddress;
  }

  /**
   * Gets the generic trap ID. If this value is ENTERPRISE_SPECIFIC(6), then
   * {@link #getSpecificTrap()} will return the trap ID of the enterprise
   * specific trap.
   * @return
   *    an Integer32 instance with a value between 0 and 6.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public int getGenericTrap() {
    checkV1TRAP();
    return genericTrap.getValue();
  }

  /**
   * Sets the generic trap ID. If this value is ENTERPRISE_SPECIFIC(6), then
   * {@link #setSpecificTrap} must be used to set the trap ID of the enterprise
   * specific trap.
   * @param genericTrap
   *    an integer value >= 0 and <= 6.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public void setGenericTrap(int genericTrap) {
    checkV1TRAP();
    this.genericTrap.setValue(genericTrap);
  }

  /**
   * Gets the specific trap ID. If this value is set,
   * {@link #getGenericTrap()} must return ENTERPRISE_SPECIFIC(6).
   * @return
   *    an integer value > 0.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public int getSpecificTrap() {
    checkV1TRAP();
    return specificTrap.getValue();
  }
  /**
   * Sets the specific trap ID. If this value is set,
   * {@link #getGenericTrap()} must be called with value
   * {@link #ENTERPRISE_SPECIFIC}.
   *
   * @param specificTrap
   *    an integer value > 0.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public void setSpecificTrap(int specificTrap) {
    checkV1TRAP();
    this.specificTrap.setValue(specificTrap);
  }

  /**
   * Gets the <code>TimeTicks</code> value of the trap sender's notion of
   * its sysUpTime value when this trap has been generated.
   *
   * @return
   *    a long value.
   * @throws UnsupportedOperationException if the type of this PDU is not
   *    {@link PDU#V1TRAP}.
   */
  public long getTimestamp() {
    checkV1TRAP();
    return timestamp.getValue();
  }

  /**
   * Sets the <code>TimeTicks</code> value of the trap sender's notion of
   * its sysUpTime value when this trap has been generated.
   *
   * @param timeStamp
   *    a long value.
   */
  public void setTimestamp(long timeStamp) {
    checkV1TRAP();
    this.timestamp.setValue(timeStamp);
  }

  /**
   * Checks for null parameters.
   * @param parameter
   *    an Object instance.
   * @throws NullPointerException if <code>parameter</code> is null.
   */
  protected void checkNull(Object parameter) {
    if (parameter == null) {
      throw new NullPointerException("Members of PDUv1 must not be null");
    }
  }

  public String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append(getTypeString(type));
    buf.append("[reqestID=");
    buf.append(requestID);
    buf.append(", timestamp=");
    buf.append(timestamp);
    buf.append(", enterprise=");
    buf.append(enterprise);
    buf.append(", genericTrap=");
    buf.append(genericTrap);
    buf.append(", specificTrap=");
    buf.append(specificTrap);
    buf.append(", VBS[");
    for (int i=0; i<variableBindings.size(); i++) {
      buf.append(variableBindings.get(i));
      if (i+1 < variableBindings.size()) {
        buf.append("; ");
      }
    }
    buf.append("]]");
    return buf.toString();
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -