public class WebClientKeyValueStorage extends UserKeyValueStorage
UserKeyValueStorage.Chunk
Modifier and Type | Field and Description |
---|---|
private UserKeyValueStorage.Chunk |
lastRetrievedChunk
The last retrieved chunk
|
private static int |
MAXIMAL_STRING_LENGTH
The maximal string length for values
|
private com.fasterxml.jackson.databind.ObjectMapper |
objectMapper
Maps an object into its json presentation and back
|
private GuiWebSocket |
webSocket
The web socket object that is responsible for the communication with the js client
|
Constructor and Description |
---|
WebClientKeyValueStorage(GuiWebSocket webSocket)
Creates the web client storage.
|
Modifier and Type | Method and Description |
---|---|
void |
delete(java.lang.String key)
Deletes the given key and its value from this storage.
|
private void |
deleteChunks(UserKeyValueStorage.Chunk head)
Delete extended chunks that follow the head chunk.
|
void |
flushChanges()
Flushes the current changes into this storage backend.
|
private UserKeyValueStorage.Chunk |
getChunk(java.lang.String key,
boolean headOnly)
Gets chunk by its key and checks if it is a head chunk.
|
UserKeyValueStorage.Chunk |
getFirstChunk(java.lang.String key)
Retrieves the first chunk node.
|
java.lang.String |
getKey(int index)
Returns the key by its index number in a sequence of all storage keys.
|
int |
getMaximalValueSize()
Returns the maximal value size that can be stored into this storage backend.
|
UserKeyValueStorage.Chunk |
getNextChunk(UserKeyValueStorage.Chunk head,
java.lang.String nextChunkKey)
Retrieves the next chunk of stored data.
|
int |
getSize()
Gets the storage size.
|
boolean |
isChunkKey(java.lang.String key)
Tests if the given key is used by a chunk that follows the head chunk.
|
void |
saveHeadChunk(java.lang.String key,
UserKeyValueStorage.Chunk head)
Stores the head chunk with the given key within this storage backend.
|
void |
saveNextChunk(UserKeyValueStorage.Chunk head,
java.lang.String nextChunkKey,
UserKeyValueStorage.Chunk node)
Stores the given chunk with the given key within this storage backend.
|
collectChunks, getBoolean, getNextChunkKey, getNumber, getString, saveByChunks, setBoolean, setNumber, setString, setUniqueHeadName
private static final int MAXIMAL_STRING_LENGTH
private final GuiWebSocket webSocket
private final com.fasterxml.jackson.databind.ObjectMapper objectMapper
private UserKeyValueStorage.Chunk lastRetrievedChunk
public WebClientKeyValueStorage(GuiWebSocket webSocket)
webSocket
- The web socket objectpublic void delete(java.lang.String key)
key
- The given keypublic void saveHeadChunk(java.lang.String key, UserKeyValueStorage.Chunk head)
saveHeadChunk
in class UserKeyValueStorage
key
- The given keyhead
- The head chunkpublic void saveNextChunk(UserKeyValueStorage.Chunk head, java.lang.String nextChunkKey, UserKeyValueStorage.Chunk node)
saveNextChunk
in class UserKeyValueStorage
head
- The head chunknextChunkKey
- The given chunk keynode
- The chunkpublic void flushChanges()
flushChanges
in class UserKeyValueStorage
public int getMaximalValueSize()
getMaximalValueSize
in class UserKeyValueStorage
public UserKeyValueStorage.Chunk getFirstChunk(java.lang.String key)
getFirstChunk
in class UserKeyValueStorage
key
- The given keypublic UserKeyValueStorage.Chunk getNextChunk(UserKeyValueStorage.Chunk head, java.lang.String nextChunkKey)
getNextChunk
in class UserKeyValueStorage
head
- The first chunk of the stored data valuenextChunkKey
- The next chunk keypublic int getSize()
public java.lang.String getKey(int index)
index
- The given index number in a sequence of all storage keys.public boolean isChunkKey(java.lang.String key)
isChunkKey
in class UserKeyValueStorage
key
- The given key to testprivate UserKeyValueStorage.Chunk getChunk(java.lang.String key, boolean headOnly)
key
- The given keyheadOnly
- The head chunk or the next chunkprivate void deleteChunks(UserKeyValueStorage.Chunk head)
head
- The head