Search in sources :

Example 1 with TelemetrySinkModule

use of org.opennms.netmgt.telemetry.ipc.TelemetrySinkModule in project opennms by OpenNMS.

the class Telemetryd method start.

@Override
public synchronized void start() throws Exception {
    if (consumers.size() > 0) {
        throw new IllegalStateException(NAME + " is already started.");
    }
    LOG.info("{} is starting.", NAME);
    final TelemetrydConfiguration config = telemetrydConfigDao.getContainer().getObject();
    final AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    for (Protocol protocol : config.getProtocols()) {
        if (!protocol.getEnabled()) {
            LOG.debug("Skipping disabled protocol: {}", protocol.getName());
            continue;
        }
        LOG.debug("Setting up protocol: {}", protocol.getName());
        // Create a Sink module using the protocol definition.
        // This allows for protocol to each have their respective queues and thread
        // related settings to help limit the impact of one protocol on another.
        final TelemetrySinkModule sinkModule = new TelemetrySinkModule(protocol);
        beanFactory.autowireBean(sinkModule);
        beanFactory.initializeBean(sinkModule, "sinkModule");
        // Create the consumer, but don't start it yet
        final TelemetryMessageConsumer consumer = new TelemetryMessageConsumer(protocol, sinkModule);
        beanFactory.autowireBean(consumer);
        beanFactory.initializeBean(consumer, "consumer");
        consumers.add(consumer);
        // Build the dispatcher, and all of
        final AsyncDispatcher<TelemetryMessage> dispatcher = messageDispatcherFactory.createAsyncDispatcher(sinkModule);
        dispatchers.add(dispatcher);
        for (org.opennms.netmgt.telemetry.config.model.Listener listenerDef : protocol.getListeners()) {
            listeners.add(ListenerFactory.buildListener(listenerDef, dispatcher));
        }
    }
    // Start the consumers
    for (TelemetryMessageConsumer consumer : consumers) {
        LOG.info("Starting consumer for {} protocol.", consumer.getProtocol().getName());
        messageConsumerManager.registerConsumer(consumer);
    }
    // Start the listeners
    for (Listener listener : listeners) {
        LOG.info("Starting {} listener.", listener.getName());
        listener.start();
    }
    LOG.info("{} is started.", NAME);
}
Also used : TelemetrySinkModule(org.opennms.netmgt.telemetry.ipc.TelemetrySinkModule) Listener(org.opennms.netmgt.telemetry.listeners.api.Listener) EventListener(org.opennms.netmgt.events.api.annotations.EventListener) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) TelemetryMessage(org.opennms.netmgt.telemetry.listeners.api.TelemetryMessage) TelemetrydConfiguration(org.opennms.netmgt.telemetry.config.model.TelemetrydConfiguration) Protocol(org.opennms.netmgt.telemetry.config.model.Protocol)

Example 2 with TelemetrySinkModule

use of org.opennms.netmgt.telemetry.ipc.TelemetrySinkModule in project opennms by OpenNMS.

the class ListenerManager method updated.

@Override
public void updated(String pid, Dictionary<String, ?> properties) {
    final Listener existingListener = listenersByPid.get(pid);
    if (existingListener != null) {
        LOG.info("Updating existing listener/dispatcher for pid: {}", pid);
        deleted(pid);
    } else {
        LOG.info("Creating new listener/dispatcher for pid: {}", pid);
    }
    // Convert the dictionary to a map
    final Map<String, String> parameters = MapUtils.fromDict(properties);
    // Build the protocol and listener definitions
    final MapBasedProtocolDef protocolDef = new MapBasedProtocolDef(parameters);
    final MapBasedListenerDef listenerDef = new MapBasedListenerDef(parameters);
    final TelemetrySinkModule sinkModule = new TelemetrySinkModule(protocolDef);
    sinkModule.setDistPollerDao(distPollerDao);
    final AsyncDispatcher<TelemetryMessage> dispatcher = messageDispatcherFactory.createAsyncDispatcher(sinkModule);
    try {
        final Listener listener = ListenerFactory.buildListener(listenerDef, dispatcher);
        listener.start();
        listenersByPid.put(pid, listener);
        dispatchersByPid.put(pid, dispatcher);
    } catch (Exception e) {
        LOG.error("Failed to build listener.", e);
        try {
            dispatcher.close();
        } catch (Exception ee) {
            LOG.error("Failed to close dispatcher.", e);
        }
    }
    LOG.info("Successfully started listener/dispatcher for pid: {}", pid);
}
Also used : TelemetrySinkModule(org.opennms.netmgt.telemetry.ipc.TelemetrySinkModule) Listener(org.opennms.netmgt.telemetry.listeners.api.Listener) TelemetryMessage(org.opennms.netmgt.telemetry.listeners.api.TelemetryMessage)

Aggregations

TelemetrySinkModule (org.opennms.netmgt.telemetry.ipc.TelemetrySinkModule)2 Listener (org.opennms.netmgt.telemetry.listeners.api.Listener)2 TelemetryMessage (org.opennms.netmgt.telemetry.listeners.api.TelemetryMessage)2 EventListener (org.opennms.netmgt.events.api.annotations.EventListener)1 Protocol (org.opennms.netmgt.telemetry.config.model.Protocol)1 TelemetrydConfiguration (org.opennms.netmgt.telemetry.config.model.TelemetrydConfiguration)1 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)1