Class ReplicationStream
java.lang.Object
com.loomcache.server.replication.ReplicationStream
Continuous replication stream from leader to a single read replica.
Manages sending committed log entries in order, with backpressure handling and automatic reconnection on disconnect with exponential backoff.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for sending entries to the replica.static final recordAggregated stats about the replication stream. -
Constructor Summary
ConstructorsConstructorDescriptionReplicationStream(String replicaId, String replicaAddress, int instanceNumber) Initialize a replication stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdvance the backoff (exponential backoff on disconnect).longGet the current backoff time in milliseconds.longGet the next index to send.getStats()Get aggregated stream statistics.booleanCheck if the stream is connected.booleanCheck if the stream is running.voidReset the backoff (on successful connection).booleansendEntry(long index, long term, byte[] data) Send an entry to the replica, handling backpressure.voidSet the callback for sending entries.voidstart()Start the replication stream.voidstop()Stop the replication stream.voidupdateNextIndex(long newIndex) Update the next index to send (e.g., after ACK from replica).
-
Constructor Details
-
ReplicationStream
-
-
Method Details
-
setSendCallback
Set the callback for sending entries.- Parameters:
callback- The send callback
-
start
public void start()Start the replication stream. -
stop
public void stop()Stop the replication stream. -
sendEntry
public boolean sendEntry(long index, long term, byte[] data) Send an entry to the replica, handling backpressure.- Parameters:
index- The log entry indexterm- The log entry termdata- The serialized entry data- Returns:
- true if queued or sent successfully, false if backpressure or not running
-
getNextIndexToSend
public long getNextIndexToSend()Get the next index to send.- Returns:
- The next log index
-
updateNextIndex
public void updateNextIndex(long newIndex) Update the next index to send (e.g., after ACK from replica).- Parameters:
newIndex- The new next index
-
isConnected
public boolean isConnected()Check if the stream is connected.- Returns:
- true if connected
-
isRunning
public boolean isRunning()Check if the stream is running.- Returns:
- true if running
-
advanceBackoff
public void advanceBackoff()Advance the backoff (exponential backoff on disconnect). -
resetBackoff
public void resetBackoff()Reset the backoff (on successful connection). -
getCurrentBackoffMs
public long getCurrentBackoffMs()Get the current backoff time in milliseconds.- Returns:
- current backoff delay
-
getStats
Get aggregated stream statistics.- Returns:
- StreamStats record
-