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
ACommitLogReader
implementation 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.Factory
asFactory()
Convert instance of this reader toCommitLogReader.Factory
suitable for serialization.java.util.Map<Partition,Offset>
fetchOffsets(Position position, java.util.List<Partition> partitions)
Fetch offsets at given position from given partitions.OffsetExternalizer
getOffsetExternalizer()
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.boolean
hasExternalizableOffsets()
Signals the user that offsets used by this reader can be externalized and reused later.ObserveHandle
observe(java.lang.String name, Position position, CommitLogObserver observer)
Subscribe observer by name to the commit log.ObserveHandle
observeBulk(java.lang.String name, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Subscribe to the commit log in a bulk fashion.ObserveHandle
observeBulkOffsets(java.util.Collection<Offset> offsets, boolean stopAtCurrent, CommitLogObserver observer)
Consume from given offsets in a bulk fashion.ObserveHandle
observeBulkPartitions(java.lang.String name, java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Subscribe to given partitions in a bulk fashion.ObserveHandle
observePartitions(java.lang.String name, java.util.Collection<Partition> partitions, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Subscribe to given set of partitions.boolean
restoresSequentialIds()
Signals the user that thisCommitLogReader
is able to recover sequential IDs sent to it inStreamElements
through 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:CommitLogReader
Signals the user that thisCommitLogReader
is able to recover sequential IDs sent to it inStreamElements
through its associated writer.- Specified by:
restoresSequentialIds
in interfaceCommitLogReader
- Returns:
true
if 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:
observe
in 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:
ObserveHandle
to 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:CommitLogReader
Subscribe 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:
observePartitions
in interfaceCommitLogReader
- Parameters:
name
- name of the observerpartitions
- the list of partitions to subscribe toposition
- the position to seek to in the partitionsstopAtCurrent
- whentrue
then stop the observer as soon as it reaches most recent recordobserver
- the observer to subscribe to the partitions- Returns:
ObserveHandle
to asynchronously cancel the observation
-
observeBulk
public ObserveHandle observeBulk(java.lang.String name, Position position, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReader
Subscribe 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:
observeBulk
in interfaceCommitLogReader
- Parameters:
name
- name of the observerposition
- the position to seek to in the partitionsstopAtCurrent
- whentrue
then stop the observer as soon as it reaches most recent recordobserver
- the observer to subscribe- Returns:
ObserveHandle
to 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:CommitLogReader
Subscribe to given partitions in a bulk fashion.- Specified by:
observeBulkPartitions
in interfaceCommitLogReader
- Parameters:
name
- name of the observerpartitions
- the partitions to subscribe toposition
- the position to seek to in the partitionsstopAtCurrent
- whentrue
then stop the observer as soon as it reaches most recent recordobserver
- the observer to subscribe to the partitions- Returns:
ObserveHandle
to asynchronously cancel the observation
-
observeBulkOffsets
public ObserveHandle observeBulkOffsets(java.util.Collection<Offset> offsets, boolean stopAtCurrent, CommitLogObserver observer)
Description copied from interface:CommitLogReader
Consume 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:
observeBulkOffsets
in interfaceCommitLogReader
- Parameters:
offsets
- the @{link Offset}s to subscribe tostopAtCurrent
-true
if the processing should stop at current offsetsobserver
- the observer to subscribe to the offsets- Returns:
ObserveHandle
to asynchronously cancel the observation
-
getPartitions
public java.util.List<Partition> getPartitions()
Description copied from interface:CommitLogReader
Retrieve list of partitions of this commit log.- Specified by:
getPartitions
in 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:CommitLogReader
Fetch offsets at given position from given partitions.- Specified by:
fetchOffsets
in interfaceCommitLogReader
- Parameters:
position
- position of the offsetspartitions
- partitions for which to fetch the offsets
-
hasExternalizableOffsets
public boolean hasExternalizableOffsets()
Description copied from interface:CommitLogReader
Signals the user that offsets used by this reader can be externalized and reused later.- Specified by:
hasExternalizableOffsets
in interfaceCommitLogReader
- Returns:
true
ifOffset
s of this reader are externalizable
-
getOffsetExternalizer
public OffsetExternalizer getOffsetExternalizer()
Description copied from interface:CommitLogReader
Provides offset externalizer for serializing log specific offsets to external formats (bytes, JSON).- Specified by:
getOffsetExternalizer
in interfaceCommitLogReader
- Returns:
OffsetExternalizer
when externalizable offsets are supported by this reader, check it byCommitLogReader.hasExternalizableOffsets()
.
-
asFactory
public CommitLogReader.Factory asFactory()
Description copied from interface:CommitLogReader
Convert instance of this reader toCommitLogReader.Factory
suitable for serialization.- Specified by:
asFactory
in interfaceCommitLogReader
- Returns:
- the
CommitLogReader.Factory
representing this reader
-
-