Search in sources :

Example 1 with DatabusCombinedConsumer

use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.

the class TestConsumerRegistration method testMultipleConsumers.

@Test
public void testMultipleConsumers() throws Exception {
    DatabusCombinedConsumer logConsumer1 = new LoggingConsumer();
    DatabusCombinedConsumer logConsumer2 = new LoggingConsumer();
    List<DatabusCombinedConsumer> lcs = new ArrayList<DatabusCombinedConsumer>();
    lcs.add(logConsumer1);
    lcs.add(logConsumer2);
    List<String> sources = new ArrayList<String>();
    ConsumerRegistration consumerReg = new ConsumerRegistration(lcs, sources, null);
    DatabusStreamConsumer cons = consumerReg.getConsumer();
    boolean condition = logConsumer1.equals(cons) || logConsumer2.equals(cons);
    Assert.assertEquals(condition, true);
    return;
}
Also used : DatabusStreamConsumer(com.linkedin.databus.client.pub.DatabusStreamConsumer) ArrayList(java.util.ArrayList) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) Test(org.testng.annotations.Test)

Example 2 with DatabusCombinedConsumer

use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.

the class DatabusHttpClientImpl method register.

@Override
public DatabusRegistration register(DatabusCombinedConsumer consumer, String... sources) throws DatabusClientException {
    if ((null == consumer))
        throw new DatabusClientException("No consumer callback has been specified.");
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Please specify Databus sources to be consumed: register(consumer, source1, source2, ...");
    RegistrationId regId = RegistrationIdGenerator.generateNewId(consumer.getClass().getSimpleName(), DatabusSubscription.createSubscriptionList(Arrays.asList(sources)));
    DatabusV2RegistrationImpl reg = new DatabusV2RegistrationImpl(regId, this, getCheckpointPersistenceProvider());
    List<DatabusCombinedConsumer> consumers = new ArrayList<DatabusCombinedConsumer>();
    consumers.add(consumer);
    reg.addDatabusConsumers(consumers);
    reg.addSubscriptions(sources);
    _regList.add(reg);
    reg.onRegister();
    return reg;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) SelectingDatabusCombinedConsumer(com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 3 with DatabusCombinedConsumer

use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.

the class MultiConsumerCallback method onStopConsumption.

@Override
public ConsumerCallbackResult onStopConsumption() {
    long curNanos = System.nanoTime();
    for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
        for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
            ConsumerCallable<ConsumerCallbackResult> endConsumptionCallable = _callbackFactory.createEndConsumptionCallable(curNanos, consumer, true);
            _currentBatch.add(endConsumptionCallable);
            if (_consumerStats != null)
                _consumerStats.registerEventsReceived(1);
        }
    }
    if (_loggingConsumer != null) {
        ConsumerCallable<ConsumerCallbackResult> endConsumptionCallable = _callbackFactory.createEndConsumptionCallable(curNanos, _loggingConsumer, false);
        _currentBatch.add(endConsumptionCallable);
    }
    if (_log.isDebugEnabled()) {
        long endNanos = System.nanoTime();
        _log.debug("Time spent in databus clientlib by onStopConsumption = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
    }
    return submitBatch(curNanos, true, true);
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer)

Example 4 with DatabusCombinedConsumer

use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.

the class MultiConsumerCallback method onRollback.

@Override
public ConsumerCallbackResult onRollback(SCN startScn) {
    long curNanos = System.nanoTime();
    for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
        for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
            ConsumerCallable<ConsumerCallbackResult> rollbackCallable = _callbackFactory.createRollbackCallable(curNanos, startScn, consumer, true);
            _currentBatch.add(rollbackCallable);
            if (_consumerStats != null)
                _consumerStats.registerEventsReceived(1);
        }
    }
    if (_loggingConsumer != null) {
        ConsumerCallable<ConsumerCallbackResult> rollbackCallable = _callbackFactory.createRollbackCallable(curNanos, startScn, _loggingConsumer, false);
        _currentBatch.add(rollbackCallable);
    }
    if (_log.isDebugEnabled()) {
        long endNanos = System.nanoTime();
        _log.debug("Time spent in databus clientlib by onRollback = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
    }
    return submitBatch(curNanos, true, true);
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer)

Example 5 with DatabusCombinedConsumer

use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.

the class MultiConsumerCallback method onEndDataEventSequence.

@Override
public ConsumerCallbackResult onEndDataEventSequence(SCN endScn) {
    long curNanos = System.nanoTime();
    for (DatabusV2ConsumerRegistration consumerReg : _registrations) {
        for (DatabusCombinedConsumer consumer : consumerReg.getConsumers()) {
            ConsumerCallable<ConsumerCallbackResult> endWindowCallable = _callbackFactory.createEndDataEventSequenceCallable(curNanos, endScn, consumer, true);
            _currentBatch.add(endWindowCallable);
            if (_consumerStats != null)
                _consumerStats.registerSystemEventReceived();
        }
    }
    if (_loggingConsumer != null) {
        ConsumerCallable<ConsumerCallbackResult> endWindowCallable = _callbackFactory.createEndDataEventSequenceCallable(curNanos, endScn, _loggingConsumer, false);
        _currentBatch.add(endWindowCallable);
    }
    if (_log.isDebugEnabled()) {
        long endNanos = System.nanoTime();
        _log.debug("Time spent in databus clientlib by onEndDataEventSequence = " + (endNanos - curNanos) / DbusConstants.NUM_NSECS_IN_MSEC + "ms");
    }
    return submitBatch(curNanos, true, true);
}
Also used : ConsumerCallbackResult(com.linkedin.databus.client.pub.ConsumerCallbackResult) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer)

Aggregations

DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)26 ArrayList (java.util.ArrayList)15 DatabusV2ConsumerRegistration (com.linkedin.databus.client.consumer.DatabusV2ConsumerRegistration)9 SelectingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer)9 ConsumerCallbackResult (com.linkedin.databus.client.pub.ConsumerCallbackResult)9 AbstractDatabusCombinedConsumer (com.linkedin.databus.client.consumer.AbstractDatabusCombinedConsumer)8 IdNamePair (com.linkedin.databus.core.util.IdNamePair)8 HashMap (java.util.HashMap)8 Test (org.testng.annotations.Test)8 DbusEvent (com.linkedin.databus.core.DbusEvent)7 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)7 DelegatingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.DelegatingDatabusCombinedConsumer)6 MultiConsumerCallback (com.linkedin.databus.client.consumer.MultiConsumerCallback)6 StreamConsumerCallbackFactory (com.linkedin.databus.client.consumer.StreamConsumerCallbackFactory)6 DatabusStreamConsumer (com.linkedin.databus.client.pub.DatabusStreamConsumer)6 Checkpoint (com.linkedin.databus.core.Checkpoint)6 UncaughtExceptionTrackingThread (com.linkedin.databus.core.util.UncaughtExceptionTrackingThread)6 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)6 List (java.util.List)6 DbusEventAppender (com.linkedin.databus.core.test.DbusEventAppender)5