Package cz.o2.proxima.direct.io.kafka
Class KafkaLogReader
- java.lang.Object
-
- cz.o2.proxima.core.storage.AbstractStorage
-
- cz.o2.proxima.direct.io.kafka.KafkaLogReader
-
- All Implemented Interfaces:
CommitLogReader
public class KafkaLogReader extends AbstractStorage implements CommitLogReader
ACommitLogReaderimplementation for Kafka.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class cz.o2.proxima.core.storage.AbstractStorage
AbstractStorage.SerializableAbstractStorage
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.core.commitlog.CommitLogReader
CommitLogReader.Factory<T extends CommitLogReader>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommitLogReader.FactoryasFactory()Convert instance of this reader toCommitLogReader.Factorysuitable for serialization.java.util.Map<Partition,Offset>fetchOffsets(Position position, java.util.List<Partition> partitions)Fetch offsets at given position from given partitions.OffsetExternalizergetOffsetExternalizer()Provides offset externalizer for serializing log specific offsets to external formats (bytes, JSON).java.util.List<Partition>getPartitions()Retrieve list of partitions of this commit log.booleanhasExternalizableOffsets()Signals the user that offsets used by this reader can be externalized and reused later.ObserveHandleobserve(java.lang.String name, Position position, CommitLogObserver observer)Subscribe observer by name to the commit log.ObserveHandleobserveBulk(java.lang.String name, Position position, boolean stopAtCurrent, CommitLogObserver observer)Subscribe to the commit log in a bulk fashion.ObserveHandleobserveBulkOffsets(java.util.Collection<Offset> offsets, boolean stopAtCurrent, CommitLogObserver observer)Consume from given offsets in a bulk fashion.ObserveHandleobserveBulkPartitions(java.lang.String name, java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)Subscribe to given partitions in a bulk fashion.ObserveHandleobservePartitions(java.lang.String name, java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)Subscribe to given set of partitions.booleanrestoresSequentialIds()Signals the user that thisCommitLogReaderis able to recover sequential IDs sent to it inStreamElementsthrough its associated writer.-
Methods inherited from class cz.o2.proxima.core.storage.AbstractStorage
equals, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.core.commitlog.CommitLogReader
getUri, observe, observeBulk, observeBulk, observeBulkOffsets, observeBulkPartitions, observeBulkPartitions, observeBulkPartitions, observePartitions, observePartitions, observePartitions
-
-
-
-
Method Detail
-
restoresSequentialIds
public boolean restoresSequentialIds()
Description copied from interface:CommitLogReaderSignals the user that thisCommitLogReaderis able to recover sequential IDs sent to it inStreamElementsthrough its associated writer.- Specified by:
restoresSequentialIdsin interfaceCommitLogReader- Returns:
trueif StreamElement read from the commit log contain valid sequential IDs.
-
observe
public ObserveHandle observe(java.lang.String name, Position position, CommitLogObserver observer)
Subscribe observer by name to the commit log. Each observer maintains its own position in the commit log, so that the observers with different names do not interfere If multiple observers share the same name, then the ingests are load-balanced between them (in an undefined manner). This is a non blocking call.- Specified by:
observein interfaceCommitLogReader- Parameters:
name- identifier of the consumerposition- the position to seek for in the commit logobserver- the observer to subscribe to the commit log- Returns:
ObserveHandleto asynchronously cancel the observation
-
observePartitions
public ObserveHandle observePartitions(java.lang.String name, @Nullable java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReaderSubscribe to given set of partitions. If you use this call then the reader stops being automatically load balanced and the set of partitions can only be changed by call to this method again.- Specified by:
observePartitionsin interfaceCommitLogReader- Parameters:
name- name of the observerpartitions- the list of partitions to subscribe toposition- the position to seek to in the partitionsstopAtCurrent- whentruethen stop the observer as soon as it reaches most recent recordobserver- the observer to subscribe to the partitions- Returns:
ObserveHandleto asynchronously cancel the observation
-
observeBulk
public ObserveHandle observeBulk(java.lang.String name, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReaderSubscribe to the commit log in a bulk fashion. That implies that elements are not committed one-by-one, but in a bulks, where all elements in a bulk are committed at once. This is useful for micro-batching approach of data processing.- Specified by:
observeBulkin interfaceCommitLogReader- Parameters:
name- name of the observerposition- the position to seek to in the partitionsstopAtCurrent- whentruethen stop the observer as soon as it reaches most recent recordobserver- the observer to subscribe- Returns:
ObserveHandleto asynchronously cancel the observation
-
observeBulkPartitions
public ObserveHandle observeBulkPartitions(java.lang.String name, java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReaderSubscribe to given partitions in a bulk fashion.- Specified by:
observeBulkPartitionsin interfaceCommitLogReader- Parameters:
name- name of the observerpartitions- the partitions to subscribe toposition- the position to seek to in the partitionsstopAtCurrent- whentruethen stop the observer as soon as it reaches most recent recordobserver- the observer to subscribe to the partitions- Returns:
ObserveHandleto asynchronously cancel the observation
-
observeBulkOffsets
public ObserveHandle observeBulkOffsets(java.util.Collection<Offset> offsets, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReaderConsume from given offsets in a bulk fashion. A typical use-case for this type of consumption is to first useCommitLogReader.observeBulkPartitions(java.lang.String, java.util.Collection<cz.o2.proxima.core.storage.Partition>, cz.o2.proxima.core.storage.commitlog.Position, cz.o2.proxima.direct.core.commitlog.CommitLogObserver), observe for some time, than interrupt the consumption, store associated offsets and resume the consumption from these offsets later- Specified by:
observeBulkOffsetsin interfaceCommitLogReader- Parameters:
offsets- the @{link Offset}s to subscribe tostopAtCurrent-trueif the processing should stop at current offsetsobserver- the observer to subscribe to the offsets- Returns:
ObserveHandleto asynchronously cancel the observation
-
getPartitions
public java.util.List<Partition> getPartitions()
Description copied from interface:CommitLogReaderRetrieve list of partitions of this commit log.- Specified by:
getPartitionsin interfaceCommitLogReader- Returns:
- list of partitions of this reader
-
fetchOffsets
public java.util.Map<Partition,Offset> fetchOffsets(Position position, java.util.List<Partition> partitions)
Description copied from interface:CommitLogReaderFetch offsets at given position from given partitions.- Specified by:
fetchOffsetsin interfaceCommitLogReader- Parameters:
position- position of the offsetspartitions- partitions for which to fetch the offsets
-
hasExternalizableOffsets
public boolean hasExternalizableOffsets()
Description copied from interface:CommitLogReaderSignals the user that offsets used by this reader can be externalized and reused later.- Specified by:
hasExternalizableOffsetsin interfaceCommitLogReader- Returns:
trueifOffsets of this reader are externalizable
-
getOffsetExternalizer
public OffsetExternalizer getOffsetExternalizer()
Description copied from interface:CommitLogReaderProvides offset externalizer for serializing log specific offsets to external formats (bytes, JSON).- Specified by:
getOffsetExternalizerin interfaceCommitLogReader- Returns:
OffsetExternalizerwhen externalizable offsets are supported by this reader, check it byCommitLogReader.hasExternalizableOffsets().
-
asFactory
public CommitLogReader.Factory asFactory()
Description copied from interface:CommitLogReaderConvert instance of this reader toCommitLogReader.Factorysuitable for serialization.- Specified by:
asFactoryin interfaceCommitLogReader- Returns:
- the
CommitLogReader.Factoryrepresenting this reader
-
-