/** * {@inheritDoc} * * <p>This method is invoked by the EventIpcManager when a new event is available for processing. * Each message is examined for its Universal Event Identifier and the appropriate action is * taking based on each UEI. */ public void onEvent(Event event) { ThreadCategory log = ThreadCategory.getInstance(getClass()); String eventUei = event.getUei(); if (eventUei == null) { log.warn("Received an unexpected event with a null UEI"); return; } if (log.isDebugEnabled()) { log.debug("Received event: " + eventUei); } if (eventUei.equals(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI) || eventUei.equals(EventConstants.INTERFACE_REPARENTED_EVENT_UEI)) { String action = eventUei.equals(EventConstants.INTERFACE_REPARENTED_EVENT_UEI) ? "reparent" : "add"; if (Long.toString(event.getNodeid()) == null) { log.warn("Not " + action + "ing interface to known node list: " + "nodeId is null"); } else if (event.getInterface() == null) { log.warn("Not " + action + "ing interface to known node list: " + "interface is null"); } else { m_trapdIpMgr.setNodeId(event.getInterface(), event.getNodeid()); if (log.isDebugEnabled()) { log.debug( "Successfully " + action + "ed " + event.getInterface() + " to known node list"); } } } else if (eventUei.equals(EventConstants.INTERFACE_DELETED_EVENT_UEI)) { if (event.getInterface() != null) { m_trapdIpMgr.removeNodeId(event.getInterface()); if (log.isDebugEnabled()) { log.debug("Removed " + event.getInterface() + " from known node list"); } } } else { log.warn("Received an unexpected event with UEI of \"" + eventUei + "\""); } }
/** onInit */ public synchronized void onInit() { Assert.state(m_trapdIpMgr != null, "trapdIpMgr must be set"); Assert.state(m_eventReader != null, "eventReader must be set"); Assert.state(m_backlogQ != null, "backlogQ must be set"); Assert.state(m_snmpTrapAddress != null, "snmpTrapAddress must be set"); Assert.state(m_snmpTrapPort != null, "snmpTrapPort must be set"); Assert.state(m_processor != null, "processor must be set"); try { m_trapdIpMgr.dataSourceSync(); } catch (final SQLException e) { LogUtils.errorf(this, e, "init: Failed to load known IP address list"); throw new UndeclaredThrowableException(e); } try { InetAddress address = getInetAddress(); LogUtils.infof( this, "Listening on %s:%d", address == null ? "[all interfaces]" : InetAddressUtils.str(address), getSnmpTrapPort()); SnmpUtils.registerForTraps(this, this, address, getSnmpTrapPort(), getSnmpV3Users()); m_registeredForTraps = true; LogUtils.debugf(this, "init: Creating the trap session"); } catch (final IOException e) { if (e instanceof java.net.BindException) { managerLog() .error( "init: Failed to listen on SNMP trap port, perhaps something else is already listening?", e); LogUtils.errorf( this, e, "init: Failed to listen on SNMP trap port, perhaps something else is already listening?"); } else { LogUtils.errorf(this, e, "init: Failed to initialize SNMP trap socket"); } throw new UndeclaredThrowableException(e); } try { m_eventReader.open(); } catch (final Throwable e) { LogUtils.errorf(this, e, "init: Failed to open event reader"); throw new UndeclaredThrowableException(e); } }