Class SegmentNodeState
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.SegmentNodeState
-
- All Implemented Interfaces:
NodeState
- Direct Known Subclasses:
CompactedNodeState
public class SegmentNodeState extends Object implements NodeState
A record of type "NODE". This class can read a node record from a segment. It currently doesn't cache data (but the template is fully loaded).
-
-
Constructor Summary
Constructors Constructor Description SegmentNodeState(@NotNull SegmentReader reader, @NotNull SegmentWriter writer, @Nullable BlobStore blobStore, @NotNull RecordId id)SegmentNodeState(@NotNull SegmentReader reader, @NotNull SegmentWriter writer, @Nullable BlobStore blobStore, @NotNull RecordId id, MeterStats readStats)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull SegmentNodeBuilderbuilder()Returns a builder for constructing a new node state based on this state, i.e.booleancompareAgainstBaseState(NodeState base, NodeStateDiff diff)Compares this node state against the given base state.booleanequals(Object object)booleanexists()Checks whether this node exists.static booleanfastEquals(NodeState a, NodeState b)Indicates whether twoNodeStateinstances are equal to each other.booleangetBoolean(@NotNull String name)Returns the boolean value of the named property.@NotNull NodeStategetChildNode(@NotNull String name)Returns the named, possibly non-existent, child node.longgetChildNodeCount(long max)Returns the number of iterable child nodes of this node.@NotNull Iterable<? extends ChildNodeEntry>getChildNodeEntries()Returns the iterable child node entries of this instance.@NotNull Iterable<String>getChildNodeNames()Returns the names of all iterable child nodes.@NotNull GCGenerationgetGcGeneration()Get the underlying segment's gc generation.longgetLong(String name)Returns the long value of the named property.@Nullable StringgetName(@NotNull String name)Returns the name value of the named property.@NotNull Iterable<String>getNames(@NotNull String name)Returns the name values of the named property.@NotNull Iterable<PropertyState>getProperties()Returns an iterable of the properties of this node.@Nullable PropertyStategetProperty(@NotNull String name)Returns the named property, ornullif no such property exists.longgetPropertyCount()Returns the number of properties of this node.RecordIdgetRecordId()Returns the identifier of this record.protected intgetRecordNumber()protected SegmentgetSegment()Returns the segment that contains this record.StringgetStableId()Returns the stable id of this node.BuffergetStableIdBytes()Returns the stable ID of this node, non parsed.@Nullable StringgetString(String name)Returns the string value of the named property.@NotNull Iterable<String>getStrings(@NotNull String name)Returns the string values of the named property.booleanhasChildNode(@NotNull String name)Checks whether the named child node exists.inthashCode()booleanhasProperty(@NotNull String name)Checks whether the named property exists.StringtoString()
-
-
-
Constructor Detail
-
SegmentNodeState
public SegmentNodeState(@NotNull @NotNull SegmentReader reader, @NotNull @NotNull SegmentWriter writer, @Nullable @Nullable BlobStore blobStore, @NotNull @NotNull RecordId id)
-
SegmentNodeState
public SegmentNodeState(@NotNull @NotNull SegmentReader reader, @NotNull @NotNull SegmentWriter writer, @Nullable @Nullable BlobStore blobStore, @NotNull @NotNull RecordId id, MeterStats readStats)
-
-
Method Detail
-
getStableId
public String getStableId()
Returns the stable id of this node. In contrast to the node's record id (which is technically the node's address) the stable id doesn't change after an online gc cycle. It might though change after an offline gc cycle.- Returns:
- stable id
-
getStableIdBytes
public Buffer getStableIdBytes()
Returns the stable ID of this node, non parsed. In contrast to the node's record id (which is technically the node's address) the stable id doesn't change after an online gc cycle. It might though change after an offline gc cycle.- Returns:
- the stable ID of this node.
-
exists
public boolean exists()
Description copied from interface:NodeStateChecks whether this node exists. See the above discussion about the existence of node states.
-
getPropertyCount
public long getPropertyCount()
Description copied from interface:NodeStateReturns the number of properties of this node.- Specified by:
getPropertyCountin interfaceNodeState- Returns:
- number of properties
-
hasProperty
public boolean hasProperty(@NotNull @NotNull String name)Description copied from interface:NodeStateChecks whether the named property exists. The implementation is equivalent togetProperty(name) != null, but may be optimized to avoid having to load the property value.- Specified by:
hasPropertyin interfaceNodeState- Parameters:
name- property name- Returns:
trueif the named property exists,falseotherwise
-
getProperty
@Nullable public @Nullable PropertyState getProperty(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the named property, ornullif no such property exists.- Specified by:
getPropertyin interfaceNodeState- Parameters:
name- name of the property to return- Returns:
- named property, or
nullif not found
-
getProperties
@NotNull public @NotNull Iterable<PropertyState> getProperties()
Description copied from interface:NodeStateReturns an iterable of the properties of this node. Multiple iterations are guaranteed to return the properties in the same order, but the specific order used is implementation-dependent and may change across different states of the same node.- Specified by:
getPropertiesin interfaceNodeState- Returns:
- properties in some stable order
-
getBoolean
public boolean getBoolean(@NotNull @NotNull String name)Description copied from interface:NodeStateReturns the boolean value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); return property != null && property.getType() == Type.BOOLEAN && property.getValue(Type.BOOLEAN);- Specified by:
getBooleanin interfaceNodeState- Parameters:
name- property name- Returns:
- boolean value of the named property, or
false
-
getLong
public long getLong(String name)
Description copied from interface:NodeStateReturns the long value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.LONG) { return property.getValue(Type.LONG); } else { return 0; }
-
getString
@Nullable public @Nullable String getString(String name)
Description copied from interface:NodeStateReturns the string value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRING) { return property.getValue(Type.STRING); } else { return null; }
-
getStrings
@NotNull public @NotNull Iterable<String> getStrings(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the string values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRINGS) { return property.getValue(Type.STRINGS); } else { return Collections.emptyList(); }- Specified by:
getStringsin interfaceNodeState- Parameters:
name- property name- Returns:
- string values of the named property, or an empty collection
-
getName
@Nullable public @Nullable String getName(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAME) { return property.getValue(Type.NAME); } else { return null; }
-
getNames
@NotNull public @NotNull Iterable<String> getNames(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the name values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAMES) { return property.getValue(Type.NAMES); } else { return Collections.emptyList(); }
-
getChildNodeCount
public long getChildNodeCount(long max)
Description copied from interface:NodeStateReturns the number of iterable child nodes of this node.If an implementation knows the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
- Specified by:
getChildNodeCountin interfaceNodeState- Parameters:
max- the maximum number of entries to traverse- Returns:
- number of iterable child nodes
-
hasChildNode
public boolean hasChildNode(@NotNull @NotNull String name)Description copied from interface:NodeStateChecks whether the named child node exists. The implementation is equivalent togetChildNode(name).exists(), except that passing an invalid name as argument will result in afalsereturn value instead of anIllegalArgumentException.- Specified by:
hasChildNodein interfaceNodeState- Parameters:
name- name of the child node- Returns:
trueif the named child node exists,falseotherwise
-
getChildNode
@NotNull public @NotNull NodeState getChildNode(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the named, possibly non-existent, child node. Use theNodeState.exists()method on the returned child node to determine whether the node exists or not.- Specified by:
getChildNodein interfaceNodeState- Parameters:
name- name of the child node to return- Returns:
- named child node
-
getChildNodeNames
@NotNull public @NotNull Iterable<String> getChildNodeNames()
Description copied from interface:NodeStateReturns the names of all iterable child nodes.- Specified by:
getChildNodeNamesin interfaceNodeState- Returns:
- child node names in some stable order
-
getChildNodeEntries
@NotNull public @NotNull Iterable<? extends ChildNodeEntry> getChildNodeEntries()
Description copied from interface:NodeStateReturns the iterable child node entries of this instance. Multiple iterations are guaranteed to return the child nodes in the same order, but the specific order used is implementation dependent and may change across different states of the same node.Note on cost and performance: while it is possible to iterate over all child
NodeStates with the two methodsNodeState.getChildNodeNames()andNodeState.getChildNode(String), this method is considered more efficient because an implementation can potentially perform the retrieval of the name andNodeStatein one call. This results in O(n) vs. O(n log n) when iterating over the child node names and then look up theNodeStateby name.- Specified by:
getChildNodeEntriesin interfaceNodeState- Returns:
- child node entries in some stable order
-
builder
@NotNull public @NotNull SegmentNodeBuilder builder()
Description copied from interface:NodeStateReturns a builder for constructing a new node state based on this state, i.e. starting with all the properties and child nodes of this state.
-
compareAgainstBaseState
public boolean compareAgainstBaseState(NodeState base, NodeStateDiff diff)
Description copied from interface:NodeStateCompares this node state against the given base state. Any differences are reported by calling the relevant added/changed/deleted methods of the given handler.TODO: Define the behavior of this method with regards to iterability/existence of child nodes.
- Specified by:
compareAgainstBaseStatein interfaceNodeState- Parameters:
base- base statediff- handler of node state differences- Returns:
trueif the full diff was performed, orfalseif it was aborted as requested by the handler (see theNodeStateDiffcontract for more details)
-
fastEquals
public static boolean fastEquals(NodeState a, NodeState b)
Indicates whether twoNodeStateinstances are equal to each other. A return value oftrueclearly means that the instances are equal, while a return value offalsedoesn't necessarily mean the instances are not equal. These "false negatives" are an implementation detail and callers cannot rely on them being stable.
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object object)
-
toString
public String toString()
-
getSegment
protected Segment getSegment()
Returns the segment that contains this record.- Returns:
- segment that contains this record
-
getRecordNumber
protected int getRecordNumber()
-
getRecordId
public RecordId getRecordId()
Returns the identifier of this record.- Returns:
- record identifier
-
getGcGeneration
@NotNull public @NotNull GCGeneration getGcGeneration()
Get the underlying segment's gc generation. Might cause the segment to get loaded if the generation info is missing- Returns:
- the segment's gc generation
-
-