Implementing Trap Receiver in 30 minutes using Apache MINA
Will continues to post articles about MINA, to be updated,
Subscribe in a reader
Yes, we are going to implement a SNMP trap receiver in less than 30 minutes. If you have been following my post on Apache MINA, this would be a natural extension to it. In this article, we shall bring together all our components to build the system.
Pre-requisites:
Please read through these articles. You can find all these posts on Apache MINA
- What is Apache MINA
- Apache MINA based Server Application Architecture
- Implementing UDP Server using Apache MINA
- Implementing SNMP4J Decoder for Apache MINA
To execute the code, you need following jars
- mina-core-2.0.0-M1.jar
- slf4j-api-1.5.0.jar
- slf4j-log4j12-1.5.0.jar
- log4j-1.2.15.jar
- SNMP4J.jar
I am assuming that you have read my previous posts and jumping straight to the implementations. The high level architecture is explained in the post Apache MINA based Server Application Architecture
Architecture
Let’s understand the flow here and see what all we need to do to process a trap
- Receive the trap over UDP
- Decode the Trap
- Dump the Trap
Lets see how each of the these maps to the code we have already written
It's a now simple to understand that we have reused all the components to create the Server. Let me not write too much, and jump straight to the code J
The Server Code
The only change that we did to the UDP Server code was to add a Protocol Codec. At line 36, we added our custom ProtocolCodecFiler. The SNMPCodecFactory return the instance of our SNMP4J codec. There is not much code and this construct is fairly simple, and explained very well in MINA’s documentation. From the main method, we just need to call the method initialize() and our trap receiver starts.
References




Can i use this within a java applet? Have you done any work with it? I have heard great reviews of it, but havent actually used it.