Package cz.o2.proxima.direct.core.view
Class LocalCachedPartitionedView
- java.lang.Object
-
- cz.o2.proxima.direct.core.view.LocalCachedPartitionedView
-
- All Implemented Interfaces:
AttributeWriterBase,OnlineAttributeWriter,RandomAccessReader,CachedView,java.io.Closeable,java.lang.AutoCloseable
public class LocalCachedPartitionedView extends java.lang.Object implements CachedView
A transformation view fromCommitLogReadertoCachedView.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.core.AttributeWriterBase
AttributeWriterBase.Type
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.core.view.CachedView
CachedView.Factory
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.core.randomaccess.RandomAccessReader
RandomAccessReader.GetRequest<T>, RandomAccessReader.Listing, RandomAccessReader.MultiFetch
-
-
Constructor Summary
Constructors Constructor Description LocalCachedPartitionedView(EntityDescriptor entity, CommitLogReader reader, OnlineAttributeWriter writer)LocalCachedPartitionedView(EntityDescriptor entity, CommitLogReader reader, OnlineAttributeWriter writer, long keepCachedDuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CachedView.FactoryasFactory()Convert instance of this view toCachedView.Factorysuitable for serialization.voidassign(java.util.Collection<Partition> partitions, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateCallback, java.time.Duration ttl)Assign and make given partitions accessible by random reads.voidcache(StreamElement element)Cache givenStreamElementinto local cache without writing it to the underlying writer.voidclose()Close allocated resources of this writer.RandomOffsetfetchOffset(RandomAccessReader.Listing type, java.lang.String key)ConstructOffsetfrom string (representing either key of the entity or attribute).<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, java.lang.String attribute, AttributeDescriptor<T> desc, long stamp)Retrieve data stored under given (key, attribute) pair (if any).java.util.Collection<Partition>getAssigned()Retrieve currently assigned partitions.EntityDescriptorgetEntityDescriptor()Retrieve entity associated with this reader.java.util.Optional<ObserveHandle>getRunningHandle()Retrieve a running handle (if present).CommitLogReadergetUnderlyingReader()Retrieve underlyingCommitLogReader.OnlineAttributeWritergetUnderlyingWriter()Retrieve underlyingOnlineAttributeWriter.java.net.URIgetUri()Retrieve URI of this writer.voidlistEntities(RandomOffset offset, int limit, Consumer<Pair<RandomOffset,java.lang.String>> consumer)List all entity keys with offset and limit.protected voidonCache(StreamElement element, boolean overwrite)<T> voidscanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<T>> consumer)List data stored for a particular wildcard attribute.voidscanWildcardAll(java.lang.String key, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<?>> consumer)Scan all data stored per given key.voidwrite(StreamElement data, CommitCallback statusCallback)Write given serialized attribute value to given entity.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.core.AttributeWriterBase
bulk, online
-
Methods inherited from interface cz.o2.proxima.direct.core.view.CachedView
assign, assign, assign, getPartitions
-
Methods inherited from interface cz.o2.proxima.direct.core.OnlineAttributeWriter
getType, isTransactional, rollback, transactional
-
Methods inherited from interface cz.o2.proxima.direct.core.randomaccess.RandomAccessReader
get, get, get, get, listEntities, multiFetch, scanWildcard, scanWildcard, scanWildcard, scanWildcardAll, scanWildcardAll, scanWildcardAll
-
-
-
-
Constructor Detail
-
LocalCachedPartitionedView
public LocalCachedPartitionedView(EntityDescriptor entity, CommitLogReader reader, OnlineAttributeWriter writer)
-
LocalCachedPartitionedView
public LocalCachedPartitionedView(EntityDescriptor entity, CommitLogReader reader, OnlineAttributeWriter writer, long keepCachedDuration)
-
-
Method Detail
-
onCache
protected void onCache(StreamElement element, boolean overwrite)
-
assign
public void assign(java.util.Collection<Partition> partitions, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateCallback, @Nullable java.time.Duration ttl)
Description copied from interface:CachedViewAssign and make given partitions accessible by random reads. If the view contains any partitions not listed in the collection, these partitions are dropped.- Specified by:
assignin interfaceCachedView- Parameters:
partitions- the partitions to cache locallyupdateCallback- function that is called when cache gets updated the function takes the new ingest element and pair of the most recent object that was associated with the key and it's currently associated stampttl- maximaul Duration that an update should be kept in the cache NOTE: this is not a hard limit, it is only a signal, that after this time the element can be removed to free up memory
-
getAssigned
public java.util.Collection<Partition> getAssigned()
Description copied from interface:CachedViewRetrieve currently assigned partitions.- Specified by:
getAssignedin interfaceCachedView- Returns:
- currently assigned partitions
-
fetchOffset
public RandomOffset fetchOffset(RandomAccessReader.Listing type, java.lang.String key)
Description copied from interface:RandomAccessReaderConstructOffsetfrom string (representing either key of the entity or attribute). The returned offset represents the first element that is following the givenkey, in case of equality.- Specified by:
fetchOffsetin interfaceRandomAccessReader- Parameters:
type- the type of the keykey- the key of entity or attribute- Returns:
- offset representation of the key
-
get
public <T> java.util.Optional<KeyValue<T>> get(java.lang.String key, java.lang.String attribute, AttributeDescriptor<T> desc, long stamp)
Description copied from interface:RandomAccessReaderRetrieve data stored under given (key, attribute) pair (if any).- Specified by:
getin interfaceRandomAccessReader- Type Parameters:
T- value type- Parameters:
key- key of the entityattribute- name of the attributedesc- the attribute to search forstamp- timestamp to relatively to which retrieve the data- Returns:
- optional
KeyValueif present
-
scanWildcardAll
public void scanWildcardAll(java.lang.String key, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<?>> consumer)Description copied from interface:RandomAccessReaderScan all data stored per given key.- Specified by:
scanWildcardAllin interfaceRandomAccessReader- Parameters:
key- the key whoseKeyValues to scanoffset- offset to start from (next key value will be returned)stamp- timestamp to relatively to which retrieve the datalimit- how many elements to process at mostconsumer- consumer to use for scanning
-
scanWildcard
public <T> void scanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<T>> consumer)Description copied from interface:RandomAccessReaderList data stored for a particular wildcard attribute.- Specified by:
scanWildcardin interfaceRandomAccessReader- Type Parameters:
T- value type- Parameters:
key- key of the entitywildcard- wildcard attribute to scanoffset- name of attribute (including the prefix) to start fromstamp- timestamp to relatively to which retrieve the datalimit- maximal number of items to consume *consumer- the consumer to stream data to
-
listEntities
public void listEntities(RandomOffset offset, int limit, Consumer<Pair<RandomOffset,java.lang.String>> consumer)
Description copied from interface:RandomAccessReaderList all entity keys with offset and limit.- Specified by:
listEntitiesin interfaceRandomAccessReader- Parameters:
offset- offset of the entitieslimit- limit for number of resultsconsumer- consumer of results
-
close
public void close()
Description copied from interface:AttributeWriterBaseClose allocated resources of this writer. This is supposed to be idempotent.- Specified by:
closein interfaceAttributeWriterBase- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceCachedView- Specified by:
closein interfacejava.io.Closeable
-
getEntityDescriptor
public EntityDescriptor getEntityDescriptor()
Description copied from interface:RandomAccessReaderRetrieve entity associated with this reader.- Specified by:
getEntityDescriptorin interfaceRandomAccessReader- Returns:
- entity associated with this reader
-
write
public void write(StreamElement data, CommitCallback statusCallback)
Description copied from interface:OnlineAttributeWriterWrite given serialized attribute value to given entity.- Specified by:
writein interfaceOnlineAttributeWriter- Parameters:
data- the data to writestatusCallback- callback used to commit data processing
-
getUri
public java.net.URI getUri()
Description copied from interface:AttributeWriterBaseRetrieve URI of this writer.- Specified by:
getUriin interfaceAttributeWriterBase- Returns:
- URI of this writer
-
cache
public void cache(StreamElement element)
Description copied from interface:CachedViewCache givenStreamElementinto local cache without writing it to the underlying writer. This is used in conjunction with attribute family proxy.- Specified by:
cachein interfaceCachedView- Parameters:
element- the data to cache
-
getUnderlyingReader
public CommitLogReader getUnderlyingReader()
Description copied from interface:CachedViewRetrieve underlyingCommitLogReader.- Specified by:
getUnderlyingReaderin interfaceCachedView
-
getUnderlyingWriter
public OnlineAttributeWriter getUnderlyingWriter()
Description copied from interface:CachedViewRetrieve underlyingOnlineAttributeWriter. Note that using this write might not update the cache. In most cases, useOnlineAttributeWriter.write(StreamElement, CommitCallback)directly.- Specified by:
getUnderlyingWriterin interfaceCachedView
-
getRunningHandle
public java.util.Optional<ObserveHandle> getRunningHandle()
Description copied from interface:CachedViewRetrieve a running handle (if present).- Specified by:
getRunningHandlein interfaceCachedView
-
asFactory
public CachedView.Factory asFactory()
Description copied from interface:CachedViewConvert instance of this view toCachedView.Factorysuitable for serialization.- Specified by:
asFactoryin interfaceAttributeWriterBase- Specified by:
asFactoryin interfaceCachedView- Specified by:
asFactoryin interfaceOnlineAttributeWriter- Specified by:
asFactoryin interfaceRandomAccessReader- Returns:
- the
CachedView.Factoryrepresenting this view
-
-