Class TransactionalCachedView
- java.lang.Object
-
- cz.o2.proxima.direct.core.transaction.TransactionalCachedView
-
- All Implemented Interfaces:
AttributeWriterBase,OnlineAttributeWriter,RandomAccessReader,CachedView,java.io.Closeable,java.lang.AutoCloseable
@Internal public class TransactionalCachedView extends java.lang.Object
-
-
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 TransactionalCachedView(DirectDataOperator direct, CachedView delegate)
-
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)Assign and make given partitions accessible by random reads.voidassign(java.util.Collection<Partition> partitions, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateCallback)Assign and make given partitions accessible by random reads.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.voidassign(java.util.Collection<Partition> partitions, java.time.Duration ttl)Assign and make given partitions accessible by random reads.BulkAttributeWriterbulk()Case this toBulkAttributeWriter.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(RandomAccessReader.GetRequest<T> request)Get singleKeyValueusingRandomAccessReader.GetRequest.<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, AttributeDescriptor<T> desc)Retrieve data stored under given (key, attribute) pair (if any).<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, AttributeDescriptor<T> desc, long stamp)Retrieve data stored under given (key, attribute) pair (if any).<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, TypedAttribute<T> attribute)Retrieve data stored under given (key, attribute) pair (if any).<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, TypedAttribute<T> attribute, long stamp)Retrieve data stored under given (key, attribute) pair (if any).<T> java.util.Optional<KeyValue<T>>get(java.lang.String key, java.lang.String attribute, AttributeDescriptor<T> desc)Retrieve data stored under given (key, attribute) pair (if any).<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.Collection<Partition>getPartitions()Retrieve all partitions of the underlying commit log.java.util.Optional<ObserveHandle>getRunningHandle()Retrieve a running handle (if present).AttributeWriterBase.TypegetType()Retrieve type of the writer.CommitLogReadergetUnderlyingReader()Retrieve underlyingCommitLogReader.OnlineAttributeWritergetUnderlyingWriter()Retrieve underlyingOnlineAttributeWriter.java.net.URIgetUri()Retrieve URI of this writer.booleanisTransactional()voidlistEntities(Consumer<Pair<RandomOffset,java.lang.String>> consumer)List all entity keys.voidlistEntities(RandomOffset offset, int limit, Consumer<Pair<RandomOffset,java.lang.String>> consumer)List all entity keys with offset and limit.RandomAccessReader.MultiFetchmultiFetch()Return a facadeRandomAccessReader.MultiFetchobject that can be used to queue multiple requests to the storage and fetch them at once usingRandomAccessReader.MultiFetch.fetch(Consumer).OnlineAttributeWriteronline()Cast this toOnlineAttributeWriter.voidrollback()Rollback the writer to last committed position.<T> voidscanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, long stamp, Consumer<KeyValue<T>> consumer)List data stored for a particular wildcard attribute.<T> voidscanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, Consumer<KeyValue<T>> consumer)List data stored for a particular wildcard attribute.<T> voidscanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, RandomOffset offset, int limit, Consumer<KeyValue<T>> consumer)List data stored for a particular wildcard attribute.<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, long stamp, Consumer<KeyValue<?>> consumer)Scan all data stored per given key.voidscanWildcardAll(java.lang.String key, Consumer<KeyValue<?>> consumer)Scan all data stored per given key.voidscanWildcardAll(java.lang.String key, RandomOffset offset, int limit, Consumer<KeyValue<?>> consumer)Scan all data stored per given key.voidscanWildcardAll(java.lang.String key, RandomOffset offset, long stamp, int limit, Consumer<KeyValue<?>> consumer)Scan all data stored per given key.TransactionalOnlineAttributeWritertransactional()voidwrite(StreamElement data, CommitCallback statusCallback)Write given serialized attribute value to given entity.
-
-
-
Constructor Detail
-
TransactionalCachedView
public TransactionalCachedView(DirectDataOperator direct, CachedView delegate)
-
-
Method Detail
-
online
public OnlineAttributeWriter online()
Description copied from interface:AttributeWriterBaseCast this toOnlineAttributeWriter. This is just a syntactic sugar.- Specified by:
onlinein interfaceAttributeWriterBase- Returns:
OnlineAttributeWriterfrom this writer
-
getType
public AttributeWriterBase.Type getType()
Description copied from interface:AttributeWriterBaseRetrieve type of the writer.- Specified by:
getTypein interfaceAttributeWriterBase- Specified by:
getTypein interfaceOnlineAttributeWriter- Returns:
AttributeWriterBase.Typeof the writer
-
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
-
isTransactional
public boolean isTransactional()
- Specified by:
isTransactionalin interfaceOnlineAttributeWriter- Returns:
trueis this is aTransactionalOnlineAttributeWriter.TransactionalOnlineAttributeWriteris used when writing attribute that supportsTransactionModedifferent fromTransactionMode.NONE.
-
transactional
public TransactionalOnlineAttributeWriter transactional()
- Specified by:
transactionalin interfaceOnlineAttributeWriter- Returns:
thisifOnlineAttributeWriter.isTransactional()returns true.
-
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
-
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
-
assign
public void assign(java.util.Collection<Partition> partitions)
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 locally
-
assign
public void assign(java.util.Collection<Partition> partitions, 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 locallyttl- 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
-
assign
public void assign(java.util.Collection<Partition> partitions, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateCallback)
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 stamp
-
assign
public void assign(java.util.Collection<Partition> partitions, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateCallback, 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
-
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
-
getPartitions
public java.util.Collection<Partition> getPartitions()
Description copied from interface:CachedViewRetrieve all partitions of the underlying commit log.- Specified by:
getPartitionsin interfaceCachedView- Returns:
- all partitions of underlying commit log
-
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
-
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, AttributeDescriptor<T> desc)
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 entitydesc- the attribute to search for (not wildcard)- Returns:
- optional
KeyValueif present
-
get
public <T> java.util.Optional<KeyValue<T>> get(java.lang.String key, 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 entitydesc- the attribute to search for (not wildcard)stamp- timestamp to relatively to which retrieve the data- Returns:
- optional
KeyValueif present
-
get
public <T> java.util.Optional<KeyValue<T>> get(java.lang.String key, TypedAttribute<T> attribute)
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- the typed attribute- Returns:
- optional
KeyValueif present
-
get
public <T> java.util.Optional<KeyValue<T>> get(java.lang.String key, TypedAttribute<T> attribute, 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- the typed attributestamp- timestamp to relatively to which retrieve the data- Returns:
- optional
KeyValueif present
-
get
public <T> java.util.Optional<KeyValue<T>> get(java.lang.String key, java.lang.String attribute, AttributeDescriptor<T> desc)
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 for- Returns:
- optional
KeyValueif present
-
get
public <T> java.util.Optional<KeyValue<T>> get(RandomAccessReader.GetRequest<T> request)
Description copied from interface:RandomAccessReaderGet singleKeyValueusingRandomAccessReader.GetRequest.- Specified by:
getin interfaceRandomAccessReader- Type Parameters:
T- value type- Parameters:
request- the request- Returns:
- optional
KeyValueif present
-
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
-
multiFetch
public RandomAccessReader.MultiFetch multiFetch()
Description copied from interface:RandomAccessReaderReturn a facadeRandomAccessReader.MultiFetchobject that can be used to queue multiple requests to the storage and fetch them at once usingRandomAccessReader.MultiFetch.fetch(Consumer).- Specified by:
multiFetchin interfaceRandomAccessReader- Returns:
- the
RandomAccessReader.MultiFetch
-
scanWildcardAll
public void scanWildcardAll(java.lang.String key, Consumer<KeyValue<?>> consumer)Description copied from interface:RandomAccessReaderScan all data stored per given key.- Specified by:
scanWildcardAllin interfaceRandomAccessReader- Parameters:
key- the key whoseKeyValues to scanconsumer- consumer to use for scanning
-
scanWildcardAll
public void scanWildcardAll(java.lang.String key, long stamp, Consumer<KeyValue<?>> consumer)Description copied from interface:RandomAccessReaderScan all data stored per given key.- Specified by:
scanWildcardAllin interfaceRandomAccessReader- Parameters:
key- the key whoseKeyValues to scanstamp- timestamp to relatively to which retrieve the dataconsumer- consumer to use for scanning
-
scanWildcardAll
public void scanWildcardAll(java.lang.String key, RandomOffset offset, 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)limit- how many elements to process at mostconsumer- consumer to use for scanning
-
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, 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 scanconsumer- the consumer to stream data to
-
scanWildcard
public <T> void scanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, long stamp, 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 scanstamp- timestamp to relatively to which retrieve the dataconsumer- the consumer to stream data to
-
scanWildcard
public <T> void scanWildcard(java.lang.String key, AttributeDescriptor<T> wildcard, RandomOffset offset, 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 fromlimit- maximal number of items to consumeconsumer- the consumer to stream data to
-
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(Consumer<Pair<RandomOffset,java.lang.String>> consumer)
Description copied from interface:RandomAccessReaderList all entity keys.- Specified by:
listEntitiesin interfaceRandomAccessReader- Parameters:
consumer- consumer that will receive keys of entities in the random access storage
-
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
-
getEntityDescriptor
public EntityDescriptor getEntityDescriptor()
Description copied from interface:RandomAccessReaderRetrieve entity associated with this reader.- Specified by:
getEntityDescriptorin interfaceRandomAccessReader- Returns:
- entity associated with this reader
-
rollback
public void rollback()
Description copied from interface:AttributeWriterBaseRollback the writer to last committed position.- Specified by:
rollbackin interfaceAttributeWriterBase- Specified by:
rollbackin interfaceOnlineAttributeWriter
-
getUri
public java.net.URI getUri()
Description copied from interface:AttributeWriterBaseRetrieve URI of this writer.- Specified by:
getUriin interfaceAttributeWriterBase- Returns:
- URI of this writer
-
bulk
public BulkAttributeWriter bulk()
Description copied from interface:AttributeWriterBaseCase this toBulkAttributeWriter. This is just a syntactic sugar.- Specified by:
bulkin interfaceAttributeWriterBase- Returns:
BulkAttributeWriterfrom this writer
-
-