use of com.linkedin.databus2.core.BackoffTimerStaticConfig in project databus by linkedin.
the class RelayPullThread method writeEventToRelayDispatcher.
private void writeEventToRelayDispatcher(ConnectionState curState, DbusEvent event, String message) throws InterruptedException, InvalidEventException {
boolean success = false;
// Create a infinite backoff timer that waits for maximum of 1 sec
// for writing the control message to evb
BackoffTimerStaticConfig timerConfig = new BackoffTimerStaticConfig(1, 1000, 1, 1, -1);
BackoffTimer timer = new BackoffTimer("EVB More Space Timer", timerConfig);
timer.reset();
byte[] eventBytes = new byte[event.size()];
_log.info("Event size: " + eventBytes.length);
_log.info("Event:" + event.toString());
event.getRawBytes().get(eventBytes);
UnifiedClientStats unifiedClientStats = _sourcesConn.getUnifiedClientStats();
while ((!success) && (timer.getRemainingRetriesNum() > 0)) {
ByteArrayInputStream cpIs = new ByteArrayInputStream(eventBytes);
ReadableByteChannel cpRbc = Channels.newChannel(cpIs);
sendHeartbeat(unifiedClientStats);
int ecnt = curState.getDataEventsBuffer().readEvents(cpRbc);
if (ecnt <= 0) {
_log.error("Not enough spece in the event buffer to add a control message :" + message);
boolean interrupted = !timer.backoffAndSleep();
if (interrupted)
throw new InterruptedException("Got interrupted while waiting to write control Message to EVB : " + message);
} else {
_log.info("Sent a control message :" + message);
success = true;
}
}
}
Aggregations