mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Some clarifications with the storage classes
This commit is contained in:
parent
fcccef2bd1
commit
a7163c8d1c
@ -10,28 +10,30 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represent an area which contain data
|
||||
* Represent an area which contain data.
|
||||
* <p>
|
||||
* Each {@link StorageLocation} has a {@link StorageSystem} associated to it which is used to save and retrieve data from keys.
|
||||
*/
|
||||
public class StorageLocation {
|
||||
|
||||
private static final DataManager DATA_MANAGER = MinecraftServer.getDataManager();
|
||||
|
||||
private final StorageSystem storageSystem;
|
||||
private final String folderPath;
|
||||
private final String location;
|
||||
|
||||
private final Map<String, SerializableData> cachedData;
|
||||
|
||||
protected StorageLocation(StorageSystem storageSystem, String folderPath, StorageOptions storageOptions) {
|
||||
protected StorageLocation(StorageSystem storageSystem, String location, StorageOptions storageOptions) {
|
||||
this.storageSystem = storageSystem;
|
||||
this.folderPath = folderPath;
|
||||
this.location = location;
|
||||
|
||||
this.cachedData = new HashMap<>();
|
||||
|
||||
this.storageSystem.open(folderPath, storageOptions);
|
||||
this.storageSystem.open(location, storageOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data associated with a key
|
||||
* Get the data associated with a key using {@link StorageSystem#get(String)}
|
||||
*
|
||||
* @param key the key
|
||||
* @return the data associated to {@code key}
|
||||
@ -42,7 +44,7 @@ public class StorageLocation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a data associated to a key
|
||||
* Set a data associated to a key using {@link StorageSystem#set(String, byte[])}
|
||||
*
|
||||
* @param key the key of the data
|
||||
* @param data the data
|
||||
@ -53,7 +55,7 @@ public class StorageLocation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key
|
||||
* Delete a key using the associated {@link StorageSystem}
|
||||
*
|
||||
* @param key the key
|
||||
* @see StorageSystem#delete(String)
|
||||
@ -63,7 +65,7 @@ public class StorageLocation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the {@link StorageLocation}
|
||||
* Close the {@link StorageLocation} using {@link StorageSystem#close()}
|
||||
*
|
||||
* @see StorageSystem#close()
|
||||
*/
|
||||
@ -217,7 +219,14 @@ public class StorageLocation {
|
||||
}
|
||||
}
|
||||
|
||||
public String getFolderPath() {
|
||||
return folderPath;
|
||||
/**
|
||||
* Get the location of this storage
|
||||
* <p>
|
||||
* WARNING: this is not necessary a file or folder path
|
||||
*
|
||||
* @return the location
|
||||
*/
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.minestom.server.storage;
|
||||
|
||||
/**
|
||||
* Represent a way of storing data
|
||||
* It works by using keys and values assigned to each one
|
||||
* Represent a way of storing data by key/value.
|
||||
* The location does not have to be a file or folder path. It is the 'identifier' of the data location
|
||||
*/
|
||||
public interface StorageSystem {
|
||||
|
||||
@ -15,9 +15,9 @@ public interface StorageSystem {
|
||||
boolean exists(String location);
|
||||
|
||||
/**
|
||||
* Called when a location is opened with this {@link StorageSystem}
|
||||
* Called when a {@link StorageLocation} is opened with this {@link StorageSystem}
|
||||
*
|
||||
* @param location the location name
|
||||
* @param location the location name
|
||||
* @param storageOptions the {@link StorageOptions}
|
||||
*/
|
||||
void open(String location, StorageOptions storageOptions);
|
||||
|
@ -8,8 +8,12 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* A storage system which is local using OS files system
|
||||
* It does make use of the RocksDB library
|
||||
* A {@link StorageSystem} which is local using OS files system
|
||||
* It does make use of the RocksDB library.
|
||||
* <p>
|
||||
* The location represents the path of the folder.
|
||||
* <p>
|
||||
* Warning: will create some log files in the location folder when opened, those are generated by RocksDB.
|
||||
*/
|
||||
public class FileStorageSystem implements StorageSystem {
|
||||
|
||||
@ -25,7 +29,7 @@ public class FileStorageSystem implements StorageSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(String folderPath, StorageOptions storageOptions) {
|
||||
public void open(String location, StorageOptions storageOptions) {
|
||||
Options options = new Options().setCreateIfMissing(true);
|
||||
|
||||
if (storageOptions.hasCompression()) {
|
||||
@ -34,7 +38,7 @@ public class FileStorageSystem implements StorageSystem {
|
||||
}
|
||||
|
||||
try {
|
||||
this.rocksDB = RocksDB.open(options, folderPath);
|
||||
this.rocksDB = RocksDB.open(options, location);
|
||||
} catch (RocksDBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user