use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.
the class KafkaRaftClient method maybeSendFetchOrFetchSnapshot.
private long maybeSendFetchOrFetchSnapshot(FollowerState state, long currentTimeMs) {
final Supplier<ApiMessage> requestSupplier;
if (state.fetchingSnapshot().isPresent()) {
RawSnapshotWriter snapshot = state.fetchingSnapshot().get();
long snapshotSize = snapshot.sizeInBytes();
requestSupplier = () -> buildFetchSnapshotRequest(snapshot.snapshotId(), snapshotSize);
} else {
requestSupplier = this::buildFetchRequest;
}
return maybeSendRequest(currentTimeMs, state.leaderId(), requestSupplier);
}
use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.
the class RecordTestUtils method replayAll.
/**
* Replay a list of records to the metadata delta.
*
* @param delta the metadata delta on which to replay the records
* @param highestOffset highest offset from the list of records
* @param highestEpoch highest epoch from the list of records
* @param recordsAndVersions list of records
*/
public static void replayAll(MetadataDelta delta, long highestOffset, int highestEpoch, List<ApiMessageAndVersion> recordsAndVersions) {
for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
ApiMessage record = recordAndVersion.message();
delta.replay(highestOffset, highestEpoch, record);
}
}
use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.
the class RecordTestUtils method replayAll.
/**
* Replay a list of records.
*
* @param target The object to invoke the replay function on.
* @param recordsAndVersions A list of records.
*/
public static void replayAll(Object target, List<ApiMessageAndVersion> recordsAndVersions) {
for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
ApiMessage record = recordAndVersion.message();
try {
Method method = target.getClass().getMethod("replay", record.getClass());
method.invoke(target, record);
} catch (NoSuchMethodException e) {
try {
Method method = target.getClass().getMethod("replay", record.getClass(), Optional.class);
method.invoke(target, record, Optional.empty());
} catch (NoSuchMethodException t) {
// ignore
} catch (InvocationTargetException t) {
throw new RuntimeException(t);
} catch (IllegalAccessException t) {
throw new RuntimeException(t);
}
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
Aggregations