use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.
the class SyslogdReceiverJavaNetBlueprintIT method addServicesOnStartup.
@SuppressWarnings("rawtypes")
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
// Register any mock OSGi services here
final MessageDispatcherFactory messageProducerFactory = mock(MessageDispatcherFactory.class);
final MinionIdentity minionIdentity = mock(MinionIdentity.class);
services.put(MessageDispatcherFactory.class.getName(), new KeyValueHolder<Object, Dictionary>(messageProducerFactory, new Properties()));
services.put(MinionIdentity.class.getName(), new KeyValueHolder<Object, Dictionary>(minionIdentity, new Properties()));
}
use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.
the class SyslogdReceiverCamelNettyBlueprintIT method addServicesOnStartup.
@SuppressWarnings("rawtypes")
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
// Register any mock OSGi services here
final MessageDispatcherFactory messageProducerFactory = mock(MessageDispatcherFactory.class);
final MinionIdentity minionIdentity = mock(MinionIdentity.class);
services.put(MessageDispatcherFactory.class.getName(), new KeyValueHolder<Object, Dictionary>(messageProducerFactory, new Properties()));
services.put(MinionIdentity.class.getName(), new KeyValueHolder<Object, Dictionary>(minionIdentity, new Properties()));
}
use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.
the class HeartbeatSinkPerfIT method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
final HeartbeatModule parallelHeartbeatModule = new HeartbeatModule() {
@Override
public int getNumConsumerThreads() {
return NUM_CONSUMER_THREADS;
}
};
final HeartbeatConsumer consumer = new HeartbeatConsumer(parallelHeartbeatModule, receivedMeter);
consumerManager.registerConsumer(consumer);
final MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
final SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
// Fire up the generators
generators = new ArrayList<>(NUM_GENERATORS);
for (int k = 0; k < NUM_GENERATORS; k++) {
final HeartbeatGenerator generator = new HeartbeatGenerator(dispatcher, RATE_PER_GENERATOR, sentMeter, sendTimer);
generators.add(generator);
generator.start();
}
}
use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.
the class HeartbeatSinkBlueprintIT method canConsumeMessagesInParallel.
@Test(timeout = 60000)
public void canConsumeMessagesInParallel() throws Exception {
final int NUM_CONSUMER_THREADS = 7;
final HeartbeatModule parallelHeartbeatModule = new HeartbeatModule() {
@Override
public int getNumConsumerThreads() {
return NUM_CONSUMER_THREADS;
}
};
ThreadLockingMessageConsumer<Heartbeat, Heartbeat> consumer = new ThreadLockingMessageConsumer<>(parallelHeartbeatModule);
CompletableFuture<Integer> future = consumer.waitForThreads(NUM_CONSUMER_THREADS);
consumerManager.registerConsumer(consumer);
MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
SyncDispatcher<Heartbeat> dispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(HeartbeatModule.INSTANCE);
HeartbeatGenerator generator = new HeartbeatGenerator(dispatcher, 100.0);
generator.start();
// Wait until we have NUM_CONSUMER_THREADS locked
future.get();
// Take a snooze
Thread.sleep(TimeUnit.SECONDS.toMillis(5));
// Verify that there aren't more than NUM_CONSUMER_THREADS waiting
assertEquals(0, consumer.getNumExtraThreadsWaiting());
generator.stop();
// This doesn't work because the consumer seems to leave NUM_CONSUMER_THREADS
// messages in-flight if it's unregistered before the context shuts down
// consumerManager.unregisterConsumer(consumer);
}
use of org.opennms.core.ipc.sink.api.MessageDispatcherFactory in project opennms by OpenNMS.
the class HeartbeatSinkBlueprintIT method canProduceAndConsumerMessages.
@Test(timeout = 60000)
public void canProduceAndConsumerMessages() throws Exception {
HeartbeatModule module = new HeartbeatModule();
AtomicInteger heartbeatCount = new AtomicInteger();
MessageConsumer<Heartbeat, Heartbeat> consumer = new MessageConsumer<Heartbeat, Heartbeat>() {
@Override
public SinkModule<Heartbeat, Heartbeat> getModule() {
return module;
}
@Override
public void handleMessage(Heartbeat heartbeat) {
heartbeatCount.incrementAndGet();
}
};
consumerManager.registerConsumer(consumer);
SyncDispatcher<Heartbeat> localDispatcher = localMessageDispatcherFactory.createSyncDispatcher(module);
localDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(1));
MessageDispatcherFactory remoteMessageDispatcherFactory = context.getRegistry().lookupByNameAndType("camelRemoteMessageDispatcherFactory", MessageDispatcherFactory.class);
SyncDispatcher<Heartbeat> remoteDispatcher = remoteMessageDispatcherFactory.createSyncDispatcher(module);
remoteDispatcher.send(new Heartbeat());
await().atMost(1, MINUTES).until(() -> heartbeatCount.get(), equalTo(2));
consumerManager.unregisterConsumer(consumer);
}
Aggregations