Moved my blog to
Have moved my posts to my own hosting space, can keep in touch athttp://www.ashishpaliwal.com/blog
public class SNMP4JCodec extends ProtocolDecoderAdapter {The code converts ByteBuffer into an SNMP PDU using SNMP4J library. Similarly, we can use Adventnet or joesnmp to convert the byte stream into SNMP PDU's
static Logger logger = LoggerFactory.getLogger(SNMP4JCodec.class);
public void decode(IoSession ioSession, IoBuffer ioBuffer,
ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
ByteBuffer pduBuffer = ioBuffer.buf();
// Decode the bytes using SNMP4J API's
PDU pdu = new PDU();
try {
BERInputStream berStream = new BERInputStream(pduBuffer);
BER.MutableByte mutableByte = new BER.MutableByte();
int length = BER.decodeHeader(berStream, mutableByte);
int startPos = (int)berStream.getPosition();
if (mutableByte.getValue() != BER.SEQUENCE) {
String txt = "SNMPv2c PDU must start with a SEQUENCE";
throw new IOException(txt);
}
Integer32 version = new Integer32();
version.decodeBER(berStream);
// decode community string
OctetString securityName = new OctetString();
securityName.decodeBER(berStream);
// decode the remaining PDU
pdu.decodeBER(berStream);
logger.debug("PDU - "+pdu);
} catch (Exception ex) {
ex.printStackTrace();
}
protocolDecoderOutput.write(pdu);
}
}
Labels: Apache MINA, MINA, ProtocolCodec, SNMP, Trap
From the figure above, User application interacts with MINA API’s, shielding the User application from Low level IO details. MINA internally uses IO API’s to perform the actual IO functions. This makes it easy for the Users to concentrate on Application logic and leave the IO handling to Apache MINA.
Advantages
Reference
Apache MINA - Home Page of Apache MINA