T - The type of the stored artifacts.public abstract class FileStorage<T> extends java.lang.Object implements ArtifactStorage<T>
| Constructor and Description |
|---|
FileStorage(java.nio.file.Path storagePath,
T emptyEntity) |
| Modifier and Type | Method and Description |
|---|---|
T |
get(java.lang.String id)
Retrieves the model for the given id.
|
java.lang.String |
getTagForId(java.lang.String id)
Returns the tag that is part of the ID.
|
java.lang.String |
put(T entity,
java.lang.String tag)
Adds a new entity and returns the automatically created id.
|
void |
putToReserved(java.lang.String id,
T entity)
Adds a new entity to an already reserved slot.
|
protected abstract T |
read(java.nio.file.Path dirPath,
java.lang.String id)
Reads an artifact.
|
protected abstract boolean |
remove(java.nio.file.Path dirPath,
java.lang.String id)
Removes an artifact.
|
boolean |
remove(java.lang.String id)
Removes the model with the passed id and returns whether the id was present.
|
java.lang.String |
reserve(java.lang.String tag)
Reserves a slot in the storage.
|
protected abstract void |
write(java.nio.file.Path dirPath,
java.lang.String id,
T entity)
Writes the artifacts to the file system.
|
public FileStorage(java.nio.file.Path storagePath,
T emptyEntity)
protected abstract void write(java.nio.file.Path dirPath,
java.lang.String id,
T entity)
throws java.io.IOException
dirPath - The directory in which the artifact should be stored.id - The ID of the artifact.entity - The artifact to be stored.java.io.IOException - If writing fails.protected abstract T read(java.nio.file.Path dirPath, java.lang.String id) throws java.io.IOException
dirPath - id - java.io.IOExceptionprotected abstract boolean remove(java.nio.file.Path dirPath,
java.lang.String id)
throws java.io.IOException
dirPath - id - true if the artifact existed and was removed successfully.java.io.IOExceptionpublic java.lang.String reserve(java.lang.String tag)
ArtifactStoragereserve in interface ArtifactStorage<T>tag - The tag of the entity.public void putToReserved(java.lang.String id,
T entity)
ArtifactStorageputToReserved in interface ArtifactStorage<T>id - The ID of the slot.entity - The entity to be stored.public java.lang.String put(T entity, java.lang.String tag)
ArtifactStorageput in interface ArtifactStorage<T>entity - The entity to be stored.tag - The tag of the entity.public T get(java.lang.String id)
ArtifactStorageget in interface ArtifactStorage<T>id - The id of the model.WorkloadModel.public boolean remove(java.lang.String id)
ArtifactStorageremove in interface ArtifactStorage<T>id - The id to be removed.true, if the passed id was present and successfully removed.public java.lang.String getTagForId(java.lang.String id)
ArtifactStoragegetTagForId in interface ArtifactStorage<T>id - The ID containing the tag.