use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.
the class Bsmd method handleReloadEvent.
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadEvent(Event e) {
LOG.info("Received a reload configuration event: {}", e);
final Parm daemonNameParm = e.getParm(EventConstants.PARM_DAEMON_NAME);
if (daemonNameParm == null || daemonNameParm.getValue() == null) {
LOG.warn("The {} parameter has no value. Ignoring.", EventConstants.PARM_DAEMON_NAME);
return;
}
if (NAME.equalsIgnoreCase(daemonNameParm.getValue().getContent())) {
LOG.info("Reloading bsmd.");
EventBuilder ebldr = null;
try {
handleConfigurationChanged();
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, NAME);
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, NAME);
LOG.info("Reload successful.");
} catch (Throwable t) {
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, NAME);
ebldr.addParam(EventConstants.PARM_REASON, t.getLocalizedMessage().substring(0, 128));
LOG.error("Reload failed.", t);
}
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, NAME);
m_eventIpcManager.sendNow(ebldr.getEvent());
}
}
use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.
the class AnnotationBasedEventListenerAdapter method populateUeiToHandlerMap.
private void populateUeiToHandlerMap() {
Method[] methods = m_annotatedListener.getClass().getMethods();
for (Method method : methods) {
EventHandler handlerInfo = AnnotationUtils.findAnnotation(method, EventHandler.class);
if (handlerInfo != null) {
String singleUei = handlerInfo.uei();
if (singleUei != null && !"".equals(singleUei)) {
validateMethodAsEventHandler(method);
Assert.state(!m_ueiToHandlerMap.containsKey(singleUei), "Cannot define method " + method + " as a handler for event " + singleUei + " since " + m_ueiToHandlerMap.get(singleUei) + " is already defined as a handler");
m_ueiToHandlerMap.put(singleUei, method);
}
String[] ueis = handlerInfo.ueis();
if (ueis != null && ueis.length > 0) {
validateMethodAsEventHandler(method);
for (String uei : ueis) {
Assert.state(!m_ueiToHandlerMap.containsKey(uei), "Cannot define method " + method + " as a handler for event " + uei + " since " + m_ueiToHandlerMap.get(uei) + " is already defined as a handler");
m_ueiToHandlerMap.put(uei, method);
}
}
}
}
Assert.state(!m_ueiToHandlerMap.isEmpty(), "annotatedListener must have public EventHandler annotated methods");
}
use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.
the class InterfaceToNodeCacheEventProcessor method handleInterfaceReparented.
@EventHandler(uei = EventConstants.INTERFACE_REPARENTED_EVENT_UEI)
@Transactional
public void handleInterfaceReparented(Event event) {
LOG.debug("Received event: {}", event.getUei());
final String oldNodeId = event.getParm(EventConstants.PARM_OLD_NODEID).getValue().getContent();
final String newNodeId = event.getParm(EventConstants.PARM_NEW_NODEID).getValue().getContent();
if (oldNodeId == null) {
LOG.error(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Event with no node ID: " + event.toString());
return;
}
if (newNodeId == null) {
LOG.error(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Event with no node ID: " + event.toString());
return;
}
final OnmsNode oldNode = m_nodeDao.get(oldNodeId);
if (oldNode == null) {
LOG.warn(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Cannot find node in DB: " + oldNodeId);
return;
}
final OnmsNode newNode = m_nodeDao.get(newNodeId);
if (newNode == null) {
LOG.warn(EventConstants.INTERFACE_REPARENTED_EVENT_UEI + ": Cannot find node in DB: " + newNodeId);
return;
}
// add to known nodes
m_cache.removeNodeId(oldNode.getLocation().getLocationName(), event.getInterfaceAddress(), oldNode.getId());
m_cache.setNodeId(newNode.getLocation().getLocationName(), event.getInterfaceAddress(), newNode.getId());
}
use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.
the class InterfaceToNodeCacheEventProcessor method handleInterfaceDeleted.
@EventHandler(uei = EventConstants.INTERFACE_DELETED_EVENT_UEI)
@Transactional
public void handleInterfaceDeleted(Event event) {
LOG.debug("Received event: {}", event.getUei());
Long nodeId = event.getNodeid();
if (nodeId == null) {
LOG.error(EventConstants.INTERFACE_DELETED_EVENT_UEI + ": Event with no node ID: " + event.toString());
return;
}
OnmsNode node = m_nodeDao.get(nodeId.intValue());
if (node == null) {
LOG.warn(EventConstants.INTERFACE_DELETED_EVENT_UEI + ": Cannot find node in DB: " + nodeId);
return;
}
// remove from known nodes
m_cache.removeNodeId(node.getLocation().getLocationName(), event.getInterfaceAddress(), nodeId.intValue());
}
use of org.opennms.netmgt.events.api.annotations.EventHandler in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapter method handleReloadConfigEvent.
/**
* <p>handleReloadConfigEvent</p>
*
* @param event a {@link org.opennms.netmgt.xml.event.Event} object.
*/
@EventHandler(uei = EventConstants.RELOAD_DAEMON_CONFIG_UEI)
public void handleReloadConfigEvent(final Event event) {
if (isReloadConfigEventTarget(event)) {
EventBuilder ebldr = null;
LOG.debug("Reloading the SNMP asset adapter configuration");
try {
m_config.update();
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, "Provisiond." + NAME);
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
} catch (Throwable e) {
LOG.info("Unable to reload SNMP asset adapter configuration", e);
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, "Provisiond." + NAME);
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Provisiond." + NAME);
ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(1, 128));
}
if (ebldr != null) {
getEventForwarder().sendNow(ebldr.getEvent());
}
}
}
Aggregations