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

📄 abstractrequest.java

📁 你个snmp的源码
💻 JAVA
字号:
package org.snmp4j.agent.request;import java.util.*;import org.snmp4j.smi.*;import org.snmp4j.mp.SnmpConstants;import org.snmp4j.PDU;/** * The <code>AbstractRequest</code> implements common elements of SNMP and * AgentX requests and might be also used for other sub-agent request types. * * @author Frank Fock * @version 1.0 */public abstract class AbstractRequest implements Request {  protected List subrequests;  protected int phase = PHASE_INIT;  protected int errorStatus = 0;  protected int repeaterStartIndex;  protected int repeaterRowSize;  protected int reprocessCounter = 0;  protected int transactionID;  public AbstractRequest() {  }  public abstract boolean isBulkRequest();  public SubRequest find(OID prefix) {    for (Iterator it = iterator(); it.hasNext(); ) {      SubRequest sreq = (SubRequest) it.next();      if (sreq.getVariableBinding().getOid().startsWith(prefix)) {        return sreq;      }    }    return null;  }  protected synchronized void initSubRequests() {    if (subrequests == null) {      setupSubRequests();    }  }  abstract protected void setupSubRequests();  abstract protected int getMaxPhase();  public int nextPhase() {    if (phase >= getMaxPhase()) {      throw new NoSuchElementException("Requested phase does not exists");    }    resetCompletionStatus();    switch (phase) {      case Request.PHASE_2PC_PREPARE: {        if (getErrorStatus() != PDU.noError) {          phase = Request.PHASE_2PC_CLEANUP;        }        else {          phase = Request.PHASE_2PC_COMMIT;        }        break;      }      case Request.PHASE_2PC_COMMIT: {        if (getErrorStatus() != PDU.noError) {          phase = Request.PHASE_2PC_UNDO;        }        else {          phase = Request.PHASE_2PC_CLEANUP;        }        break;      }      case Request.PHASE_2PC_UNDO: {        phase = Request.PHASE_2PC_CLEANUP;        break;      }      default: {        phase = Request.PHASE_2PC_PREPARE;        break;      }    }    return phase;  }  public boolean isComplete() {    if (getPhase() >= getMaxPhase()) {      return isPhaseComplete();    }    return false;  }  public SubRequest get(int index) {    return (SubRequest) subrequests.get(index);  }  public int getPhase() {    return phase;  }  public int getErrorIndex() {    if (errorStatus == SnmpConstants.SNMP_ERROR_SUCCESS) {      return 0;    }    initSubRequests();    int index = 1;    for (Iterator it = subrequests.iterator(); it.hasNext(); index++) {      SubRequest sreq = (SubRequest) it.next();      if (sreq.getStatus().getErrorStatus() !=          SnmpConstants.SNMP_ERROR_SUCCESS) {        return index;      }    }    return 0;  }  public int getErrorStatus() {    initSubRequests();    if (errorStatus == SnmpConstants.SNMP_ERROR_SUCCESS) {      for (Iterator it = subrequests.iterator(); it.hasNext();) {        SubRequest sreq = (SubRequest) it.next();        if (sreq.getStatus().getErrorStatus() !=            SnmpConstants.SNMP_ERROR_SUCCESS) {          return sreq.getStatus().getErrorStatus();        }      }    }    return errorStatus;  }  public int getTransactionID() {    return transactionID;  }  public void setPhase(int phase) throws NoSuchElementException {    if ((phase < 0) || (phase > getMaxPhase())) {      throw new NoSuchElementException("Illegal phase identifier: "+phase);    }    if (this.phase != phase) {      resetCompletionStatus();    }    this.phase = phase;  }  protected void resetCompletionStatus() {    initSubRequests();    for (Iterator it = subrequests.iterator(); it.hasNext();) {      SubRequest subReq = (SubRequest) it.next();      subReq.getStatus().setPhaseComplete(false);      subReq.getStatus().setProcessed(false);    }  }  public synchronized void resetProcessedStatus() {    for (Iterator it = subrequests.iterator(); it.hasNext(); ) {      SubRequest sreq = (SubRequest) it.next();      sreq.getStatus().setProcessed(sreq.getStatus().isPhaseComplete());    }  }  public void setErrorStatus(int errorStatus) {    this.errorStatus = errorStatus;  }  public boolean equals(Object obj) {    if (obj instanceof Request) {      return (transactionID == ((Request)obj).getTransactionID());    }    return false;  }  public int hashCode() {    return transactionID;  }  public int getReprocessCounter() {    return reprocessCounter;  }  public void incReprocessCounter() {    ++reprocessCounter;  }}

⌨️ 快捷键说明

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