Search in sources :

Example 1 with BackoffTimerStaticConfig

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;
        }
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) UnifiedClientStats(com.linkedin.databus.client.pub.mbean.UnifiedClientStats) ByteArrayInputStream(java.io.ByteArrayInputStream) BackoffTimerStaticConfig(com.linkedin.databus2.core.BackoffTimerStaticConfig) Checkpoint(com.linkedin.databus.core.Checkpoint) BackoffTimer(com.linkedin.databus2.core.BackoffTimer)

Aggregations

UnifiedClientStats (com.linkedin.databus.client.pub.mbean.UnifiedClientStats)1 Checkpoint (com.linkedin.databus.core.Checkpoint)1 BackoffTimer (com.linkedin.databus2.core.BackoffTimer)1 BackoffTimerStaticConfig (com.linkedin.databus2.core.BackoffTimerStaticConfig)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1