org.snmp4j.agent.request
Class AbstractRequest<U extends SubRequest,S,R>

java.lang.Object
  extended by org.snmp4j.agent.request.AbstractRequest<U,S,R>
All Implemented Interfaces:
Request<S,R>
Direct Known Subclasses:
SnmpRequest

public abstract class AbstractRequest<U extends SubRequest,S,R>
extends java.lang.Object
implements Request<S,R>

The AbstractRequest implements common elements of SNMP and AgentX requests and might be also used for other sub-agent request types.

Version:
1.0
Author:
Frank Fock

Field Summary
protected  int errorStatus
           
protected  int phase
           
protected  int repeaterRowSize
           
protected  int repeaterStartIndex
           
protected  int reprocessCounter
           
protected  R response
           
protected  S source
           
protected  java.util.List<U> subrequests
           
protected  int transactionID
           
 
Fields inherited from interface org.snmp4j.agent.request.Request
PHASE_1PC, PHASE_2PC_CLEANUP, PHASE_2PC_COMMIT, PHASE_2PC_PREPARE, PHASE_2PC_UNDO, PHASE_INIT
 
Constructor Summary
AbstractRequest(S source)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 SubRequest find(org.snmp4j.smi.OID prefix)
          Finds the first sub-request whose OID starts with the supplied one.
 SubRequest get(int index)
          Gets the sub-request at the specified index.
 int getErrorIndex()
           
 int getErrorStatus()
           
protected abstract  int getMaxPhase()
           
 int getPhase()
          Gets the phase identifier of the current Two-Phase-Commit (2PC) phase of this request.
 int getReprocessCounter()
          Returns the value of the reprocessing counter associated with this request.
 R getResponse()
          Returns the response object for this request.
 S getSource()
          Returns the initiating event object for the request.
 int getTransactionID()
           
 int hashCode()
           
 void incReprocessCounter()
          Increments the reprocess counter by one.
protected  void initSubRequests()
           
abstract  boolean isBulkRequest()
           
 boolean isComplete()
          Checks whether the response for this request is complete.
 int nextPhase()
          Initializes next phase and returns its identifier.
protected  void resetCompletionStatus()
           
 void resetProcessedStatus()
          Set the processed status of each (incomplete) sub-request to false.
 void setErrorStatus(int errorStatus)
           
 void setPhase(int phase)
          Sets the request phase.
protected abstract  void setupSubRequests()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.snmp4j.agent.request.Request
getContext, getMessageProcessingModel, getProcessingUserObject, getSecurityLevel, getSecurityModel, getSecurityName, getViewName, getViewType, isPhaseComplete, iterator, setProcessingUserObject, setViewName, size
 

Field Detail

subrequests

protected java.util.List<U extends SubRequest> subrequests

source

protected S source

response

protected R response

phase

protected int phase

errorStatus

protected int errorStatus

repeaterStartIndex

protected int repeaterStartIndex

repeaterRowSize

protected int repeaterRowSize

reprocessCounter

protected int reprocessCounter

transactionID

protected int transactionID
Constructor Detail

AbstractRequest

public AbstractRequest(S source)
Method Detail

getSource

public S getSource()
Description copied from interface: Request
Returns the initiating event object for the request.

Specified by:
getSource in interface Request<S,R>
Returns:
an Object instance on whose behalf this request has been initiated.

getResponse

public R getResponse()
Description copied from interface: Request
Returns the response object for this request.

Specified by:
getResponse in interface Request<S,R>
Returns:
an object containing the response for this request.

isBulkRequest

public abstract boolean isBulkRequest()

find

public SubRequest find(org.snmp4j.smi.OID prefix)
Description copied from interface: Request
Finds the first sub-request whose OID starts with the supplied one.

Specified by:
find in interface Request<S,R>
Parameters:
prefix - the OID prefix of the sub-request OID.
Returns:
the first SubRequest instance of this request whose OID starts with prefix. If no such sub-request exits null is returned.

initSubRequests

protected void initSubRequests()

setupSubRequests

protected abstract void setupSubRequests()

getMaxPhase

protected abstract int getMaxPhase()

nextPhase

public int nextPhase()
Description copied from interface: Request
Initializes next phase and returns its identifier.

Specified by:
nextPhase in interface Request<S,R>
Returns:
a phase identifier.

isComplete

public boolean isComplete()
Description copied from interface: Request
Checks whether the response for this request is complete.

Specified by:
isComplete in interface Request<S,R>
Returns:
true if all required data has been collected to create a response for this request, false otherwise.

get

public SubRequest get(int index)
Description copied from interface: Request
Gets the sub-request at the specified index.

Specified by:
get in interface Request<S,R>
Parameters:
index - an index >= 0 and < size()
Returns:
a SnmpSubRequest instance.

getPhase

public int getPhase()
Description copied from interface: Request
Gets the phase identifier of the current Two-Phase-Commit (2PC) phase of this request.

Specified by:
getPhase in interface Request<S,R>
Returns:
a 2PC identifier

getErrorIndex

public int getErrorIndex()
Specified by:
getErrorIndex in interface Request<S,R>

getErrorStatus

public int getErrorStatus()
Specified by:
getErrorStatus in interface Request<S,R>

getTransactionID

public int getTransactionID()
Specified by:
getTransactionID in interface Request<S,R>

setPhase

public void setPhase(int phase)
              throws java.util.NoSuchElementException
Description copied from interface: Request
Sets the request phase.

Specified by:
setPhase in interface Request<S,R>
Parameters:
phase - a phase identifier.
Throws:
java.util.NoSuchElementException - if there is no such phase for this type of request.

resetCompletionStatus

protected void resetCompletionStatus()

resetProcessedStatus

public void resetProcessedStatus()
Description copied from interface: Request
Set the processed status of each (incomplete) sub-request to false.

Specified by:
resetProcessedStatus in interface Request<S,R>

setErrorStatus

public void setErrorStatus(int errorStatus)
Specified by:
setErrorStatus in interface Request<S,R>

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getReprocessCounter

public int getReprocessCounter()
Description copied from interface: Request
Returns the value of the reprocessing counter associated with this request. The reprocessing counter can be used to detect and handle endless-loop errors caused by instrumentation code not setting the completion status of a sub-request correctly.

Specified by:
getReprocessCounter in interface Request<S,R>
Returns:
0 after the initial (and normally last) processing iteration and n after the n-th reprocessing iteration.
See Also:
Request.incReprocessCounter()

incReprocessCounter

public void incReprocessCounter()
Description copied from interface: Request
Increments the reprocess counter by one.

Specified by:
incReprocessCounter in interface Request<S,R>
See Also:
Request.getReprocessCounter()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Copyright 2005-2010 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.