[jboss-cvs] JBossAS SVN: r97999 - branches/snmp4j-integration/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 18 14:07:14 EST 2009


Author: bshim
Date: 2009-12-18 14:07:14 -0500 (Fri, 18 Dec 2009)
New Revision: 97999

Modified:
   branches/snmp4j-integration/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
Log:
Fixed TrapEmitter stop and cleaned up send() a bit

Modified: branches/snmp4j-integration/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
===================================================================
--- branches/snmp4j-integration/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java	2009-12-18 17:45:01 UTC (rev 97998)
+++ branches/snmp4j-integration/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java	2009-12-18 19:07:14 UTC (rev 97999)
@@ -144,14 +144,6 @@
       throws Exception
    {
       synchronized(this.managers) {
-
-         // Recycle open sessions to managers
-         Iterator i = this.managers.iterator();
-         
-         while (i.hasNext()) {
-            ManagerRecord s = (ManagerRecord)i.next();
-            s.closeSession();    
-         }
             
          // Drop all held manager records
          this.managers.clear();
@@ -182,22 +174,26 @@
       ScopedPDU v2cTrapPdu = null; 
       ScopedPDU v3TrapPdu = null;
       
+      //The snmp session
+      Snmp snmp = null;
+      
+      //The target to send to
+      Target t = null;
+      
       // Send trap. Synchronise on the subscription collection while 
       // iterating 
-      synchronized(this.managers) {
+      synchronized(this.managers) { 	  
     	  
-    	  //The Snmp Session
-    	  Snmp snmp = null;
-    	  
          // Iterate over sessions and emit the trap on each one
          Iterator i = this.managers.iterator();
          while (i.hasNext()) {
             //ManagerRecord t = (ManagerRecord)i.next();
-        	 Target t = (Target)i.next();
-
+        	 t = (Target)i.next();
+        	 
             try {
-               switch (t.getVersion()) {
-               		case SnmpConstants.version1:
+            	snmp = createSnmpSession(t.getAddress());
+            	switch (t.getVersion()) {
+            		case SnmpConstants.version1:
                   //case SnmpAgentService.SNMPV1:
                      if (v1TrapPdu == null)
                         v1TrapPdu = this.trapFactory.generateV1Trap(n);
@@ -211,7 +207,6 @@
                             
                      // Send
                      //s.getSession().send(v1TrapPdu);
-                     snmp = createSnmpSession(t.getAddress());
                      log.debug("Sending trap: "+v1TrapPdu.toString() + "\n to target: "+ t.toString());
                      snmp.send(v1TrapPdu, t);
                      break;
@@ -226,7 +221,6 @@
                             
                      // Send
                      //t.getSession().send(v2TrapPdu);
-                     snmp = createSnmpSession(t.getAddress());
                      snmp.send(v2cTrapPdu, t);
                      break;
                      
@@ -246,7 +240,6 @@
                          this.trapCount.advance();
                                 
                          // Send
-                         snmp = createSnmpSession(t.getAddress());
                          snmp.send(v3TrapPdu, t);
                 	 break;
                      
@@ -407,29 +400,31 @@
 //	   else {return null;}
 	   
 	   int version = m.getVersion();
+	   try{
+		   if (version == SnmpConstants.version1 || version == SnmpConstants.version2c){
+			   
+			   //change 'public' to a constant somewhere
+			   //target = new CommunityTarget(new TcpAddress(newAddr), new OctetString("public"));
+			   
+				   if (m.getAddress() != null){
+			   target = new CommunityTarget(new TcpAddress(InetAddress.getByName(m.getAddress()), m.getPort()), new OctetString(m.getCommunityString()));
+			   //try defining retries/timeout period in notifications.xml
+			   //Timeout and Retries needs to be a field later on
+			   //target.setRetries(3);
+			   target.setTimeout(8000);
+				   }
+		   }
+		   else if (version == SnmpConstants.version3) {
+			   //won't be used at the moment
+			   target = new UserTarget();
+			   target.setAddress(new TcpAddress(InetAddress.getByName(m.getAddress()), m.getPort()));
+		   }
+		   else {
+			   //unrecognized version
+			   return null;
+		   }
 	   
-	   if (version == SnmpConstants.version1 || version == SnmpConstants.version2c){
-		   
-		   //change 'public' to a constant somewhere
-		   //target = new CommunityTarget(new TcpAddress(newAddr), new OctetString("public"));
-		   try{
-			   if (m.getAddress() != null){
-		   target = new CommunityTarget(new TcpAddress(InetAddress.getByName(m.getAddress()), m.getPort()), new OctetString(m.getCommunityString()));
-		   //try defining retries/timeout period in notifications.xml
-		   //Timeout and Retries needs to be a field later on
-		   //target.setRetries(3);
-		   target.setTimeout(8000);
-			   }
-		   }catch (UnknownHostException e) {} //something goes here
-	   }
-	   else if (version == SnmpConstants.version3) {
-		   //won't be used at the moment
-		   target = new UserTarget();
-	   }
-	   else {
-		   //unrecognized version
-		   return null;
-	   }
+	   } catch (UnknownHostException e) {} //something goes here
 	   if (target != null){
 		   target.setVersion(version);
 	   }




More information about the jboss-cvs-commits mailing list