Search in sources :

Example 1 with SinkModule

use of org.opennms.core.ipc.sink.api.SinkModule in project opennms by OpenNMS.

the class AbstractMessageConsumerManager method unregisterConsumer.

@SuppressWarnings("unchecked")
@Override
public synchronized <S extends Message, T extends Message> void unregisterConsumer(MessageConsumer<S, T> consumer) throws Exception {
    if (consumer == null) {
        return;
    }
    try (MDCCloseable mdc = Logging.withPrefixCloseable(MessageConsumerManager.LOG_PREFIX)) {
        LOG.info("Unregistering consumer: {}", consumer);
        final SinkModule<?, Message> module = (SinkModule<?, Message>) consumer.getModule();
        consumersByModule.remove(module, (MessageConsumer<?, Message>) consumer);
        if (consumersByModule.get(module).size() < 1) {
            waitForStartup.thenRunAsync(new Runnable() {

                @Override
                public void run() {
                    try {
                        LOG.info("Stopping consumption of messages for module: {}", module);
                        stopConsumingForModule(module);
                    } catch (Exception e) {
                        LOG.error("Unexpected exception while trying to stop consumer for module: {}", module, e);
                    }
                }
            });
        }
    }
}
Also used : SinkModule(org.opennms.core.ipc.sink.api.SinkModule) Message(org.opennms.core.ipc.sink.api.Message) MDCCloseable(org.opennms.core.logging.Logging.MDCCloseable)

Example 2 with SinkModule

use of org.opennms.core.ipc.sink.api.SinkModule in project opennms by OpenNMS.

the class AbstractMessageConsumerManager method registerConsumer.

@SuppressWarnings("unchecked")
@Override
public synchronized <S extends Message, T extends Message> void registerConsumer(MessageConsumer<S, T> consumer) throws Exception {
    if (consumer == null) {
        return;
    }
    try (MDCCloseable mdc = Logging.withPrefixCloseable(MessageConsumerManager.LOG_PREFIX)) {
        LOG.info("Registering consumer: {}", consumer);
        final SinkModule<?, Message> module = (SinkModule<?, Message>) consumer.getModule();
        final int numConsumersBefore = consumersByModule.get(module).size();
        consumersByModule.put(module, (MessageConsumer<?, Message>) consumer);
        if (numConsumersBefore < 1) {
            waitForStartup.thenRunAsync(new Runnable() {

                @Override
                public void run() {
                    try {
                        LOG.info("Starting to consume messages for module: {}", module);
                        startConsumingForModule(module);
                    } catch (Exception e) {
                        LOG.error("Unexpected exception while trying to start consumer for module: {}", module, e);
                    }
                }
            });
        }
    }
}
Also used : SinkModule(org.opennms.core.ipc.sink.api.SinkModule) Message(org.opennms.core.ipc.sink.api.Message) MDCCloseable(org.opennms.core.logging.Logging.MDCCloseable)

Aggregations

Message (org.opennms.core.ipc.sink.api.Message)2 SinkModule (org.opennms.core.ipc.sink.api.SinkModule)2 MDCCloseable (org.opennms.core.logging.Logging.MDCCloseable)2