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);
}
}
});
}
}
}
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);
}
}
});
}
}
}
Aggregations