Search in sources :

Example 1 with MessageDispatcherFactory

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()));
}
Also used : Dictionary(java.util.Dictionary) MinionIdentity(org.opennms.minion.core.api.MinionIdentity) Properties(java.util.Properties) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory)

Example 2 with MessageDispatcherFactory

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()));
}
Also used : Dictionary(java.util.Dictionary) MinionIdentity(org.opennms.minion.core.api.MinionIdentity) Properties(java.util.Properties) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory)

Example 3 with MessageDispatcherFactory

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();
    }
}
Also used : HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Before(org.junit.Before)

Example 4 with MessageDispatcherFactory

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) HeartbeatGenerator(org.opennms.core.ipc.sink.camel.HeartbeatSinkPerfIT.HeartbeatGenerator) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 5 with MessageDispatcherFactory

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);
}
Also used : ThreadLockingMessageConsumer(org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer) MessageConsumer(org.opennms.core.ipc.sink.api.MessageConsumer) HeartbeatModule(org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Heartbeat(org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat) MessageDispatcherFactory(org.opennms.core.ipc.sink.api.MessageDispatcherFactory) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Aggregations

MessageDispatcherFactory (org.opennms.core.ipc.sink.api.MessageDispatcherFactory)7 Heartbeat (org.opennms.core.ipc.sink.camel.heartbeat.Heartbeat)4 HeartbeatModule (org.opennms.core.ipc.sink.camel.heartbeat.HeartbeatModule)4 Test (org.junit.Test)3 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)3 Dictionary (java.util.Dictionary)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MessageConsumer (org.opennms.core.ipc.sink.api.MessageConsumer)2 ThreadLockingMessageConsumer (org.opennms.core.ipc.sink.common.ThreadLockingMessageConsumer)2 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 MessageConsumerManager (org.opennms.core.ipc.sink.api.MessageConsumerManager)1 HeartbeatGenerator (org.opennms.core.ipc.sink.camel.HeartbeatSinkPerfIT.HeartbeatGenerator)1 MockMessageConsumerManager (org.opennms.core.ipc.sink.mock.MockMessageConsumerManager)1 RestClient (org.opennms.minion.core.api.RestClient)1 DistPollerDao (org.opennms.netmgt.dao.api.DistPollerDao)1