@API(value=MAINTAINED) public class KeySpaceDirectory extends Object
KeySpace
.Modifier and Type | Class and Description |
---|---|
static class |
KeySpaceDirectory.KeyType
The available data types for directories.
|
Modifier and Type | Field and Description |
---|---|
static Object |
ANY_VALUE
The value of a directory that may contain any value of the type specified for the directory (as opposed
to a directory that is restricted to a specific constant value).
|
protected static CompletableFuture<Optional<ResolvedKeySpacePath>> |
DIRECTORY_NOT_FOR_KEY
Return value from
pathFromKey to indicate that a given tuple value is not appropriate
for a given directory. |
protected KeySpaceDirectory.KeyType |
keyType |
protected String |
name |
protected KeySpaceDirectory |
parent |
protected List<KeySpaceDirectory> |
subdirs |
protected Map<String,KeySpaceDirectory> |
subdirsByName |
protected Object |
value |
protected Function<KeySpacePath,KeySpacePath> |
wrapper |
Constructor and Description |
---|
KeySpaceDirectory(String name,
KeySpaceDirectory.KeyType keyType)
Creates a directory that can hold any value of a given type.
|
KeySpaceDirectory(String name,
KeySpaceDirectory.KeyType keyType,
Function<KeySpacePath,KeySpacePath> wrapper)
Creates a directory that can hold any value of a given type.
|
KeySpaceDirectory(String name,
KeySpaceDirectory.KeyType keyType,
Object value) |
KeySpaceDirectory(String name,
KeySpaceDirectory.KeyType keyType,
Object value,
Function<KeySpacePath,KeySpacePath> wrapper)
Creates a directory.
|
Modifier and Type | Method and Description |
---|---|
KeySpaceDirectory |
addSubdirectory(KeySpaceDirectory subdirectory)
Adds a subdirectory within the directory.
|
protected static boolean |
areEqual(Object o1,
Object o2) |
int |
depth()
Get the depth in the directory tree of this directory.
|
protected CompletableFuture<ResolvedKeySpacePath> |
findChildForKey(FDBRecordContext context,
ResolvedKeySpacePath parent,
Tuple key,
int keySize,
int keyIndex)
Iterates over the subdirectories of this directory looking for one that is compatible with the
key tuple, starting at position keyIndex . |
KeySpaceDirectory.KeyType |
getKeyType()
Returns the type of values this directory stores.
|
String |
getName()
Returns the name of this directory.
|
String |
getNameInTree()
When displaying the name of this directory in the tree output from
toString() allows the
directory implementation to ornament the name in any fashion it sees fit. |
KeySpaceDirectory |
getParent()
Returns this directory's parent.
|
List<KeySpaceDirectory> |
getSubdirectories()
Returns the set of subdirectories contained within this directory.
|
KeySpaceDirectory |
getSubdirectory(String name)
Retrieves a subdirectory.
|
Object |
getValue()
Returns the constant value that this directory stores.
|
protected boolean |
isCompatible(KeySpaceDirectory parent,
KeySpaceDirectory dir)
When a subdirectory is being added to a directory and an existing subdirectory is found that stores the
same data type but with a different constant value, this method will be called both on the directory being
added as well as the existing subdirectory to allow them to determine if they are compatible with each other.
|
boolean |
isLeaf()
Returns whether or not the directory is a leaf directory (has no subdirectories).
|
protected RecordCursor<ResolvedKeySpacePath> |
listSubdirectoryAsync(KeySpacePath listFrom,
FDBRecordContext context,
String subdirName,
byte[] continuation,
ScanProperties scanProperties) |
protected RecordCursor<ResolvedKeySpacePath> |
listSubdirectoryAsync(KeySpacePath listFrom,
FDBRecordContext context,
String subdirName,
ValueRange<?> valueRange,
byte[] continuation,
ScanProperties scanProperties) |
protected CompletableFuture<ResolvedKeySpacePath> |
nextChildForKey(int childIndex,
FDBRecordContext context,
ResolvedKeySpacePath parent,
Tuple key,
int keySize,
int keyIndex) |
protected CompletableFuture<Optional<ResolvedKeySpacePath>> |
pathFromKey(FDBRecordContext context,
ResolvedKeySpacePath parent,
Tuple key,
int keySize,
int keyIndex)
Given a position in a tuple, checks to see if this directory is compatible with the value at the
position, returning either a path indicating that it was compatible or nothing if it was not compatible.
|
String |
toString() |
void |
toTree(Writer out)
Sends the keyspace as an ascii-art tree to an output stream.
|
protected PathValue |
toTupleValue(FDBRecordContext context,
Object value) |
protected CompletableFuture<PathValue> |
toTupleValueAsync(FDBRecordContext context,
Object value)
Asks the directory implementation to "resolve" a tuple value.
|
protected CompletableFuture<PathValue> |
toTupleValueAsyncImpl(FDBRecordContext context,
Object value)
This method is called during the process of turning a
KeySpacePath into a Tuple . |
protected void |
validateConstant(Object value)
Called during creation to validate that the constant value provided is of a valid type for this
directory.
|
protected Object |
validateResolvedValue(Object value)
Ensures that a value is suitable to be stored within this directory.
|
protected KeySpacePath |
wrap(KeySpacePath path)
If a
wrapper was installed for this directory, the provided path will be
wrapped by the wrapper and returned, otherwise the original path is returned. |
protected static final CompletableFuture<Optional<ResolvedKeySpacePath>> DIRECTORY_NOT_FOR_KEY
pathFromKey
to indicate that a given tuple value is not appropriate
for a given directory.public static final Object ANY_VALUE
@Nullable protected KeySpaceDirectory parent
@Nonnull protected final KeySpaceDirectory.KeyType keyType
@Nonnull protected final Map<String,KeySpaceDirectory> subdirsByName
@Nonnull protected final List<KeySpaceDirectory> subdirs
@Nullable protected Function<KeySpacePath,KeySpacePath> wrapper
public KeySpaceDirectory(@Nonnull String name, @Nonnull KeySpaceDirectory.KeyType keyType, @Nullable Object value, @Nullable Function<KeySpacePath,KeySpacePath> wrapper)
getEmployeePath(int id)
).name
- the name of the directorykeyType
- the data type of the values that may be contained within the directoryvalue
- a value
of ANY_VALUE
indicates that any value of the specified
type may be stored in the directory, otherwise specifies a constant value that represents the
directorywrapper
- if non-null, specifies a function that may be used to wrap any KeySpacePath
objects return from KeySpace.pathFromKey(FDBRecordContext, Tuple)
RecordCoreArgumentException
- if the provided value constant value is not valid for the
type of directory being createdpublic KeySpaceDirectory(@Nonnull String name, @Nonnull KeySpaceDirectory.KeyType keyType, @Nullable Function<KeySpacePath,KeySpacePath> wrapper)
getEmployeePath(int id)
).name
- the name of the directorykeyType
- the data type of the values that may be contained within the directorywrapper
- if non-null, specifies a function that may be used to wrap any KeySpacePath
objects returned from KeySpace.pathFromKey(FDBRecordContext, Tuple)
public KeySpaceDirectory(@Nonnull String name, @Nonnull KeySpaceDirectory.KeyType keyType)
name
- the name of the directorykeyType
- the data type of the values that may be contained within the directorypublic int depth()
protected void validateConstant(@Nullable Object value)
value
- constant value to validate@Nonnull protected CompletableFuture<Optional<ResolvedKeySpacePath>> pathFromKey(@Nonnull FDBRecordContext context, @Nullable ResolvedKeySpacePath parent, @Nonnull Tuple key, int keySize, int keyIndex)
KeySpacePath
for itself is constructed.
If key size if less than the actual key length, the path remainder will reflect
the left over key elements.context
- the database contextparent
- the parent path elementkey
- the tuple being parsedkeySize
- the logical key size.keyIndex
- the position in the index being parsedKeySpacePath
representing the leaf-most path for the provided key
or Optional.empty()
if this directory is not compatible with the element at
keyIndex
position in the key
@Nonnull protected CompletableFuture<ResolvedKeySpacePath> findChildForKey(@Nonnull FDBRecordContext context, @Nullable ResolvedKeySpacePath parent, @Nonnull Tuple key, int keySize, int keyIndex)
key
tuple, starting at position keyIndex
.
If the key size is less than the actual key length, the path remainder will reflect
the left over key elements.context
- the database contextparent
- the parent path elementkey
- the tuple being parsedkeySize
- the logical key sizekeyIndex
- the position in the index being parsedRecordCoreArgumentException
- if no compatible child can be foundprotected CompletableFuture<ResolvedKeySpacePath> nextChildForKey(int childIndex, @Nonnull FDBRecordContext context, @Nullable ResolvedKeySpacePath parent, @Nonnull Tuple key, int keySize, int keyIndex)
@Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory)
subdirectory
- the subdirectory to addRecordCoreArgumentException
- if a subdirectory of the same name already exists, or a subdirectory of the
same type already exists with the same constant valueprotected boolean isCompatible(@Nonnull KeySpaceDirectory parent, @Nonnull KeySpaceDirectory dir)
DirectoryLayerDirectory
: let's say we had something
like:
dir.addSubdirectory(new DirectoryLayerDirectory("dir1", "constValue")) .addSubdirectory(new KeySpaceDirectory("dir2", KeyType.LONG, 1)In this case, we are adding two directories which are of the same type, LONG (
DirectorylayerDirectory
is implicitly of type long) and, although, the two appear to have different constant values and, thus, should
be compatible with each other, the DirectoryLayerDirectory
dynamically converts it's
"constValue"
into a LONG and, thus, could end up colliding with the constant value of 1
used for "dir2"
. To prevent this, the DirectoryLayerDirectory
must override this method
to block any peer that isn't also a DirectorylayerDirectory
.
If this directory is being added to parent
, then dir
is the existing
peer that has the same storage data type but a different constant value. If this directory already exists
in parent
, then dir
is a new peer that is being added that has the same data type
but a different constant value.parent
- the parent directory in which a subdirectory is being addeddir
- the existing peer directorypublic boolean isLeaf()
@Nonnull public KeySpaceDirectory getSubdirectory(@Nonnull String name)
name
- the name of the subdirectory to returnname
NoSuchDirectoryException
- if the directory does not exist@Nonnull protected KeySpacePath wrap(@Nonnull KeySpacePath path)
wrapper
was installed for this directory, the provided path
will be
wrapped by the wrapper
and returned, otherwise the original path
is returned.path
- the path to be wrapped@Nonnull protected RecordCursor<ResolvedKeySpacePath> listSubdirectoryAsync(@Nullable KeySpacePath listFrom, @Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
@Nonnull protected RecordCursor<ResolvedKeySpacePath> listSubdirectoryAsync(@Nullable KeySpacePath listFrom, @Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable ValueRange<?> valueRange, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
@Nonnull public List<KeySpaceDirectory> getSubdirectories()
@Nonnull protected final CompletableFuture<PathValue> toTupleValueAsync(@Nonnull FDBRecordContext context, @Nullable Object value)
DirectoryLayerDirectory
would be expecting the value to be
a String
and would use the directory layer to then convert it into a Long
.context
- the context in which to perform the resolutionvalue
- the value to be resolved@Nullable protected PathValue toTupleValue(@Nonnull FDBRecordContext context, @Nullable Object value)
@Nonnull protected CompletableFuture<PathValue> toTupleValueAsyncImpl(@Nonnull FDBRecordContext context, @Nullable Object value)
KeySpacePath
into a Tuple
. This
method should never be directly invoked from anything other than toTupleValueAsync
, it is purely
intended for new KeySpaceDirectory
implementations to override.context
- the context in which the tuple is being constructedvalue
- the value that was provided to be stored in this directoryvalue
RecordCoreArgumentException
- if the value provided for this directory is incompatible with the
definition of this directory@Nullable protected Object validateResolvedValue(@Nullable Object value)
value
- the value to be stored in this directoryvalue
RecordCoreArgumentException
- if the value is not suitable for storing in this directory@Nullable public KeySpaceDirectory getParent()
null
if there is no parent@Nonnull public String getName()
@Nonnull public String getNameInTree()
toString()
allows the
directory implementation to ornament the name in any fashion it sees fit.@Nonnull public KeySpaceDirectory.KeyType getKeyType()
@Nullable public Object getValue()
ANY_VALUE
indicates
that this directory may contain any value of the type indicated by getKeyType()
public void toTree(Writer out) throws IOException
out
- the print destinationIOException
- if there is a problem with the destination