use of org.opennms.core.ipc.sink.api.Message 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.Message 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);
}
}
});
}
}
}
use of org.opennms.core.ipc.sink.api.Message in project opennms by OpenNMS.
the class TrapSinkModuleTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() throws Exception {
SinkModule<Message, Message> mockModule = Mockito.mock(SinkModule.class);
Mockito.when(mockModule.getId()).thenReturn("id");
OnmsDistPoller distPollerMock = Mockito.mock(OnmsDistPoller.class);
TrapdConfig config = new TrapdConfigBean();
final TrapSinkModule module = new TrapSinkModule(config, distPollerMock);
Assert.assertEquals(module, module);
Assert.assertEquals(module.hashCode(), module.hashCode());
final TrapSinkModule other = new TrapSinkModule(config, distPollerMock);
Assert.assertEquals(module, other);
Assert.assertEquals(module.hashCode(), other.hashCode());
Assert.assertNotEquals(module, mockModule);
Assert.assertNotEquals(module.hashCode(), mockModule.hashCode());
}
use of org.opennms.core.ipc.sink.api.Message in project opennms by OpenNMS.
the class CamelSinkServerProcessor method process.
@Override
public void process(Exchange exchange) {
final byte[] messageBytes = exchange.getIn().getBody(byte[].class);
final Message message = module.unmarshal(messageBytes);
consumerManager.dispatch(module, message);
}
Aggregations