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 fromCommitLogReader
toCachedView
.
-
-
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.Factory
asFactory()
Convert instance of this view toCachedView.Factory
suitable for serialization.void
assign(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.void
cache(StreamElement element)
Cache givenStreamElement
into local cache without writing it to the underlying writer.void
close()
Close allocated resources of this writer.RandomOffset
fetchOffset(RandomAccessReader.Listing type, java.lang.String key)
ConstructOffset
from 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.EntityDescriptor
getEntityDescriptor()
Retrieve entity associated with this reader.java.util.Optional<ObserveHandle>
getRunningHandle()
Retrieve a running handle (if present).CommitLogReader
getUnderlyingReader()
Retrieve underlyingCommitLogReader
.OnlineAttributeWriter
getUnderlyingWriter()
Retrieve underlyingOnlineAttributeWriter
.java.net.URI
getUri()
Retrieve URI of this writer.void
listEntities(RandomOffset offset, int limit, Consumer<Pair<RandomOffset,java.lang.String>> consumer)
List all entity keys with offset and limit.protected void
onCache(StreamElement element, boolean overwrite)
<T> void
scanWildcard(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.void
scanWildcardAll(java.lang.String key, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<?>> consumer)
Scan all data stored per given key.void
write(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:CachedView
Assign 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:
assign
in 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:CachedView
Retrieve currently assigned partitions.- Specified by:
getAssigned
in interfaceCachedView
- Returns:
- currently assigned partitions
-
fetchOffset
public RandomOffset fetchOffset(RandomAccessReader.Listing type, java.lang.String key)
Description copied from interface:RandomAccessReader
ConstructOffset
from 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:
fetchOffset
in 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:RandomAccessReader
Retrieve data stored under given (key, attribute) pair (if any).- Specified by:
get
in 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
KeyValue
if present
-
scanWildcardAll
public void scanWildcardAll(java.lang.String key, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<?>> consumer)
Description copied from interface:RandomAccessReader
Scan all data stored per given key.- Specified by:
scanWildcardAll
in interfaceRandomAccessReader
- Parameters:
key
- the key whoseKeyValue
s 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:RandomAccessReader
List data stored for a particular wildcard attribute.- Specified by:
scanWildcard
in 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:RandomAccessReader
List all entity keys with offset and limit.- Specified by:
listEntities
in interfaceRandomAccessReader
- Parameters:
offset
- offset of the entitieslimit
- limit for number of resultsconsumer
- consumer of results
-
close
public void close()
Description copied from interface:AttributeWriterBase
Close allocated resources of this writer. This is supposed to be idempotent.- Specified by:
close
in interfaceAttributeWriterBase
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCachedView
- Specified by:
close
in interfacejava.io.Closeable
-
getEntityDescriptor
public EntityDescriptor getEntityDescriptor()
Description copied from interface:RandomAccessReader
Retrieve entity associated with this reader.- Specified by:
getEntityDescriptor
in interfaceRandomAccessReader
- Returns:
- entity associated with this reader
-
write
public void write(StreamElement data, CommitCallback statusCallback)
Description copied from interface:OnlineAttributeWriter
Write given serialized attribute value to given entity.- Specified by:
write
in interfaceOnlineAttributeWriter
- Parameters:
data
- the data to writestatusCallback
- callback used to commit data processing
-
getUri
public java.net.URI getUri()
Description copied from interface:AttributeWriterBase
Retrieve URI of this writer.- Specified by:
getUri
in interfaceAttributeWriterBase
- Returns:
- URI of this writer
-
cache
public void cache(StreamElement element)
Description copied from interface:CachedView
Cache givenStreamElement
into local cache without writing it to the underlying writer. This is used in conjunction with attribute family proxy.- Specified by:
cache
in interfaceCachedView
- Parameters:
element
- the data to cache
-
getUnderlyingReader
public CommitLogReader getUnderlyingReader()
Description copied from interface:CachedView
Retrieve underlyingCommitLogReader
.- Specified by:
getUnderlyingReader
in interfaceCachedView
-
getUnderlyingWriter
public OnlineAttributeWriter getUnderlyingWriter()
Description copied from interface:CachedView
Retrieve underlyingOnlineAttributeWriter
. Note that using this write might not update the cache. In most cases, useOnlineAttributeWriter.write(StreamElement, CommitCallback)
directly.- Specified by:
getUnderlyingWriter
in interfaceCachedView
-
getRunningHandle
public java.util.Optional<ObserveHandle> getRunningHandle()
Description copied from interface:CachedView
Retrieve a running handle (if present).- Specified by:
getRunningHandle
in interfaceCachedView
-
asFactory
public CachedView.Factory asFactory()
Description copied from interface:CachedView
Convert instance of this view toCachedView.Factory
suitable for serialization.- Specified by:
asFactory
in interfaceAttributeWriterBase
- Specified by:
asFactory
in interfaceCachedView
- Specified by:
asFactory
in interfaceOnlineAttributeWriter
- Specified by:
asFactory
in interfaceRandomAccessReader
- Returns:
- the
CachedView.Factory
representing this view
-
-