1 22 23 package org.snmp4j.agent.agentx; 24 25 import java.io.IOException ; 26 import java.nio.ByteBuffer ; 27 import java.util.Arrays ; 28 import java.util.List ; 29 30 import org.snmp4j.smi.VariableBinding; 31 import java.util.ArrayList ; 32 33 public class AgentXResponsePDU extends AgentXPDU { 34 35 private int sysUpTime; 36 private short errorStatus; 37 private short errorIndex; 38 39 private List variableBindings = new ArrayList (); 40 41 public AgentXResponsePDU(int sysUpTime, short errorStatus, short errorIndex) { 42 super(AGENTX_RESPONSE_PDU); 43 this.sysUpTime = sysUpTime; 44 this.errorIndex = errorIndex; 45 this.errorStatus = errorStatus; 46 } 47 48 public AgentXResponsePDU(AgentXMessageHeader header) { 49 super(header); 50 } 51 52 public void decodePayload(ByteBuffer buf, int length) throws IOException { 53 sysUpTime = buf.getInt(); 54 errorStatus = buf.getShort(); 55 errorIndex = buf.getShort(); 56 variableBindings = Arrays.asList(AgentXProtocol.decodeVariableBindings(buf)); 57 } 58 59 protected void encodePayload(ByteBuffer buf) { 60 buf.putInt(sysUpTime); 61 buf.putShort(errorStatus); 62 buf.putShort(errorIndex); 63 AgentXProtocol.encodeVaribleBindings(buf, getVariableBindings()); 64 } 65 66 public int getPayloadLength() { 67 return 2 * AgentXProtocol.AGENTX_INT_SIZE + 68 AgentXProtocol.getVariableBindingsLength(getVariableBindings()); 69 } 70 71 public int getSysUpTime() { 72 return sysUpTime; 73 } 74 75 public VariableBinding[] getVariableBindings() { 76 VariableBinding[] vbs = (VariableBinding[]) 77 variableBindings.toArray(new VariableBinding[variableBindings.size()]); 78 return vbs; 79 } 80 81 public int size() { 82 return variableBindings.size(); 83 } 84 85 public short getErrorIndex() { 86 return errorIndex; 87 } 88 89 public short getErrorStatus() { 90 return errorStatus; 91 } 92 93 public void setVariableBindings(VariableBinding[] variableBindings) { 94 this.variableBindings = Arrays.asList(variableBindings); 95 } 96 97 public void setSysUpTime(int sysUpTime) { 98 this.sysUpTime = sysUpTime; 99 } 100 101 public void setErrorStatus(short errorStatus) { 102 this.errorStatus = errorStatus; 103 } 104 105 public void setErrorIndex(short errorIndex) { 106 this.errorIndex = errorIndex; 107 } 108 109 public void setErrorStatus(int errorStatus) { 110 this.errorStatus = (short)errorStatus; 111 } 112 113 public void setErrorIndex(int errorIndex) { 114 this.errorIndex = (short)errorIndex; 115 } 116 117 public void add(VariableBinding vb) { 118 variableBindings.add(vb); 119 } 120 121 public void clear() { 122 variableBindings.clear(); 123 } 124 125 protected void beforeEncode() { 126 } 127 128 protected String toStringExtMembers() { 129 return super.toStringExtMembers()+",sysUpTime="+sysUpTime+",errorStatus="+ 130 errorStatus+",errorIndex="+errorIndex+",vbs="+variableBindings; 131 } 132 } 133 | Popular Tags |