Package convex.core.data
Class RefSoft<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.Ref<T>
convex.core.data.RefSoft<T>
- Type Parameters:
T
- Type of referenced Cell
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<Ref<T>>
Reference class implemented via a soft reference and store lookup.
Ref makes use of a soft reference to values, allowing memory to be reclaimed
by the garbage collector when not required. A MissingDataException will occur
with any attempt to deference this Ref when the value is not present
and not stored in the current store.
Instances of this class should usually be be STORED, otherwise data loss
may occur due to garbage collection. However UNKNOWN RefSoft may exist temporarily
(e.g. reading Refs from external messages)
RefSoft must always have a non-null hash, to ensure lookup capability in
store.
RefSoft must always store a canonical value, if any
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SoftReference<T>
SoftReference to value.protected AStore
SoftReference to value.Fields inherited from class convex.core.data.Ref
ANNOUNCED, BAD_MASK, EMBEDDING_MASK, FALSE_VALUE, flags, hash, INDIRECT_ENCODING_LENGTH, INTERNAL, INTERNAL_FLAGS, INVALID, KNOWN_EMBEDDED_MASK, MARKED, MAX_STATUS, NON_EMBEDDED_MASK, NULL_VALUE, PERSISTED, STATUS_MASK, STORED, TRUE_VALUE, UNKNOWN, VALIDATED, VERIFICATION_MASK, VERIFIED_MASK
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateForHash(Hash hash)
Create a RefSoft with a Hash reference.Ensures this Ref is canonicalboolean
Checks if two Ref Values are equal.int
Estimate the encoded data size for this Cell.getHash()
Gets the Hash of this ref's value.getValue()
Gets the value from this Ref.boolean
isDirect()
Return true if this Ref is a direct reference, i.e.boolean
Checks if this Ref refers to missing data, i.e.void
validate()
Validates the complete structure of this object.withFlags(int newFlags)
Create a new Ref of the same type with updated flagsUpdates the value stored within this Ref.Methods inherited from class convex.core.data.Ref
accumulateRefSet, addAllToSet, cachedHash, compareTo, createArray, createEncoding, encode, equals, findMissing, flagsWithStatus, forHash, get, get, getEncodingLength, getFlags, getMemorySize, getStatus, hashCode, isEmbedded, isMarked, isPersisted, markEmbedded, mergeFlags, persist, persist, persistShallow, persistShallow, print, readRaw, setFlags, toDirect, toString, updateRefs, withMinimumStatus, write
Methods inherited from class convex.core.data.AObject
attachEncoding, getEncoding, print, print
-
Field Details
-
softRef
SoftReference to value. Might get updated to a fresh instance. -
store
SoftReference to value. Might get updated to a fresh instance.
-
-
Constructor Details
-
RefSoft
-
RefSoft
-
RefSoft
-
-
Method Details
-
withFlags
Description copied from class:Ref
Create a new Ref of the same type with updated flags -
create
-
createForHash
Create a RefSoft with a Hash reference. Attempts to get the value will trigger a store lookup, which may in turn cause a MissingDataException if not found.- Type Parameters:
T
- Type of value- Parameters:
hash
- Hash ID of value.- Returns:
- New RefSoft instance
-
getValue
Description copied from class:Ref
Gets the value from this Ref. Important notes: - May throw a MissingDataException if the data does not exist in available storage - Will return null if and only if the Ref refers to the null value -
isMissing
public boolean isMissing()Description copied from class:Ref
Checks if this Ref refers to missing data, i.e. a Cell that does not exist in the currect store. -
equals
Description copied from class:Ref
Checks if two Ref Values are equal. Equality is defined as referring to the same data, i.e. have an identical hash. -
isDirect
public boolean isDirect()Description copied from class:Ref
Return true if this Ref is a direct reference, i.e. the value is pinned in memory and cannot be garbage collected -
getHash
Description copied from class:Ref
Gets the Hash of this ref's value. -
validate
Description copied from interface:IValidated
Validates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validate
in interfaceIValidated
- Overrides:
validate
in classRef<T extends ACell>
- Throws:
InvalidDataException
- If the data Valie is invalid in any way
-
withValue
Description copied from class:Ref
Updates the value stored within this Ref. New value must be equal in value to the old value (identical hash), but may have updated internal refs etc. -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
ensureCanonical
Description copied from class:Ref
Ensures this Ref is canonical- Specified by:
ensureCanonical
in classRef<T extends ACell>
- Returns:
- this Ref if already canonical, potentially a new Ref with canonical value otherwise
-