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