mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Storage system improvement
This commit is contained in:
parent
fe7e56da8d
commit
80f9122da1
@ -35,6 +35,13 @@ public class Data {
|
||||
return Collections.unmodifiableSet(data.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the data does not contain anything, false otherwise
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return data.isEmpty();
|
||||
}
|
||||
|
||||
public Data clone() {
|
||||
Data data = new Data();
|
||||
data.data = new ConcurrentHashMap<>(this.data);
|
||||
|
@ -27,7 +27,9 @@ public class StorageManager {
|
||||
* @return the specified storage folder
|
||||
*/
|
||||
public StorageFolder getFolder(String folderPath, StorageSystem storageSystem) {
|
||||
return folderMap.computeIfAbsent(folderPath, s -> new StorageFolder(storageSystem, folderPath));
|
||||
StorageFolder storageFolder =
|
||||
folderMap.computeIfAbsent(folderPath, s -> new StorageFolder(storageSystem, folderPath));
|
||||
return storageFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,6 +48,32 @@ public class StorageManager {
|
||||
return getFolder(folderPath, storageSystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to know if the specified folder already exist or not
|
||||
*
|
||||
* @param folderPath
|
||||
* @param storageSystem
|
||||
* @return true if the folder exists, false otherwise
|
||||
*/
|
||||
public boolean folderExists(String folderPath, StorageSystem storageSystem) {
|
||||
return storageSystem.exists(folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@link #folderExists(String, StorageSystem)} with the default StorageSystem
|
||||
*
|
||||
* @param folderPath
|
||||
* @return
|
||||
*/
|
||||
public boolean folderExists(String folderPath) {
|
||||
return folderExists(folderPath, defaultStorageSystemSupplier.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all folders which have been loaded by {@link #getFolder(String)} or {@link #getFolder(String, StorageSystem)}
|
||||
*
|
||||
* @return an unmodifiable list of all the loaded StorageFolder
|
||||
*/
|
||||
public Collection<StorageFolder> getLoadedFolders() {
|
||||
return Collections.unmodifiableCollection(folderMap.values());
|
||||
}
|
||||
|
@ -3,11 +3,17 @@ package net.minestom.server.storage;
|
||||
public interface StorageSystem {
|
||||
|
||||
/**
|
||||
* Called when a foler is opened with this StorageSystem
|
||||
*
|
||||
* @param folderName the name of the folder
|
||||
* @param folderPath
|
||||
* @return true if the folder exists, false otherwise
|
||||
*/
|
||||
void open(String folderName);
|
||||
boolean exists(String folderPath);
|
||||
|
||||
/**
|
||||
* Called when a folder is opened with this StorageSystem
|
||||
*
|
||||
* @param folderPath the name of the folder
|
||||
*/
|
||||
void open(String folderPath);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
|
@ -5,6 +5,8 @@ import org.rocksdb.Options;
|
||||
import org.rocksdb.RocksDB;
|
||||
import org.rocksdb.RocksDBException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* A storage system which is local using OS files system
|
||||
* It does make use of the RocksDB library
|
||||
@ -18,11 +20,16 @@ public class FileStorageSystem implements StorageSystem {
|
||||
private RocksDB rocksDB;
|
||||
|
||||
@Override
|
||||
public void open(String folderName) {
|
||||
public boolean exists(String folderPath) {
|
||||
return new File(folderPath).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(String folderPath) {
|
||||
Options options = new Options().setCreateIfMissing(true);
|
||||
|
||||
try {
|
||||
this.rocksDB = RocksDB.open(options, folderName);
|
||||
this.rocksDB = RocksDB.open(options, folderPath);
|
||||
} catch (RocksDBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user