| | |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import java.util.Set; |
| | | import java.util.SortedSet; |
| | | import javax.management.MBeanServer; |
| | | import javax.management.ObjectName; |
| | |
| | | */ |
| | | public void initializeConnectionHandler( |
| | | SNMPConnectionHandlerCfg configuration) throws Exception { |
| | | |
| | | |
| | | // Keep the connection handler configuration |
| | | this.currentConfig = configuration; |
| | | |
| | |
| | | |
| | | // Initialize the Connection Handler with the given configuration |
| | | this.initializeConnectionHandler(); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public ConfigChangeResult applyConfigurationChange( |
| | | SNMPConnectionHandlerCfg configuration) { |
| | | |
| | | try { |
| | | |
| | | // Register/UnRegister SNMP MBeans |
| | | if ((this.registeredSNMPMBeans) && |
| | | (!configuration.isRegisteredMbean())) { |
| | |
| | | |
| | | // private methods |
| | | private void initializeConnectionHandler() throws Exception { |
| | | |
| | | |
| | | // Compute the connectionHandler name |
| | | this.connectionHandlerName = "SNMP Connection Handler " + |
| | | this.currentConfig.getListenPort(); |
| | |
| | | * Finalize. |
| | | */ |
| | | public void finalizeConnectionHandler() { |
| | | |
| | | try { |
| | | |
| | | if (this.sentTraps == true) { |
| | | // Send a trap when stop |
| | | this.snmpAdaptor.snmpV1Trap( |
| | |
| | | } |
| | | |
| | | private void unregisterSnmpMBeans() { |
| | | Set objectNames = this.dsMib.getMib().getEntriesObjectNames(); |
| | | for (Object objectName : objectNames) { |
| | | ObjectName name = (ObjectName) objectName; |
| | | for (ObjectName name : this.dsMib.getMib().getEntriesObjectNames()) { |
| | | try { |
| | | this.server.unregisterMBean(name); |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean checkTrapsDestinations(SortedSet destinations) { |
| | | |
| | | private boolean checkTrapsDestinations(SortedSet<String> destinations) { |
| | | // If the traps destinations is empty, the traps have to be sent |
| | | // to localhost |
| | | if ((destinations == null) || (destinations.isEmpty())) { |
| | |
| | | } |
| | | |
| | | boolean found = false; |
| | | for (Object destination : destinations) { |
| | | String dest = null; |
| | | for (String dest : destinations) { |
| | | try { |
| | | dest = (String) destination; |
| | | InetAddress addr = InetAddress.getByName(dest); |
| | | found = true; |
| | | } catch (UnknownHostException ex) { |
| | |
| | | } |
| | | } |
| | | return found; |
| | | |
| | | } |
| | | } |
| | | |