use of com.tvd12.dahlia.core.setting.RuntimeSetting in project dahlia by youngmonkeys.
the class SettingRuntimeDeserializer method deserialize.
@Override
public RuntimeSetting deserialize(byte[] bytes) {
EzyObject object = objectDeserializer.deserialize(bytes);
RuntimeSetting setting = new RuntimeSetting();
setting.setMaxDatabaseId(object.get(SettingFields.MAX_DATABASE_ID, int.class));
setting.setMaxCollectionId(object.get(SettingFields.MAX_COLLECTION_ID, int.class));
return setting;
}
use of com.tvd12.dahlia.core.setting.RuntimeSetting in project dahlia by youngmonkeys.
the class SettingRuntimeSerializer method serialize.
@Override
public byte[] serialize(RuntimeSetting setting) {
EzyObject object = settingToObject(setting);
byte[] bytes = objectSerializer.serialize(object);
return bytes;
}
use of com.tvd12.dahlia.core.setting.RuntimeSetting in project dahlia by youngmonkeys.
the class DahliaCoreLoader method doLoad.
protected DahliaCore doLoad() {
Map<String, DatabaseStorage> databaseStoreages = newDatabaseStorages();
Set<String> databaseNames = databaseStoreages.keySet();
Map<String, List<CollectionStorage>> collectionStoragesMap = newDatabaseColectionsStorages(databaseNames);
Map<String, DatabaseSetting> databaseSettings = readDatabaseSettings(databaseStoreages);
Map<String, List<CollectionSetting>> collectionSettingsMap = readCollectionSettings(collectionStoragesMap);
Storage storage = newStorage(databaseStoreages, collectionStoragesMap, databaseSettings, collectionSettingsMap);
RuntimeSetting runtimeSetting = storage.readRuntimeSetting();
DatabaseFactory databaseFactory = new DatabaseFactory(runtimeSetting.getMaxDatabaseId());
CollectionFactory collectionFactory = new CollectionFactory(runtimeSetting.getMaxCollectionId());
Databases databases = newDatabases(databaseFactory, collectionFactory, databaseSettings, collectionSettingsMap);
loadAllCollections(databases, storage);
DahliaCore dahlia = DahliaCore.builder().storage(storage).databases(databases).runtimeSetting(runtimeSetting).databaseFactory(databaseFactory).collectionFactory(collectionFactory).databaseStorageFactory(databaseStorageFactory).collectionStorageFactory(collectionStorageFactory).build();
return dahlia;
}
use of com.tvd12.dahlia.core.setting.RuntimeSetting in project dahlia by youngmonkeys.
the class CommandCreateCollectionHandler method handle.
@Override
public Object handle(CommandCreateCollection command) {
int databaseId = command.getDatabaseId();
CollectionSetting setting = command.getSetting();
String collectionName = setting.getCollectionName();
Database database = databases.getDatabase(databaseId);
if (database == null)
throw new DatabaseNotFoundException(databaseId);
Collection existedCollection = database.getCollection(collectionName);
if (existedCollection != null)
throw new CollectionExistedException(collectionName);
int recordSize = recordSizeReader.read(setting.getAllFields());
setting.setRecordSize(recordSize);
Collection collection = collectionFactory.newCollection(setting);
synchronized (runtimeSetting) {
runtimeSetting.setMaxCollectionId(collection.getId());
storage.storeRuntimeSetting(runtimeSetting);
}
database.addCollection(collection);
databases.addCollection(collection);
CollectionStorage collectionStorage = collectionStorageFactory.newCollectionStorage(collectionName, database.getName());
storage.addCollectionStorage(collection.getId(), collectionStorage);
collectionStorage.storeSetting(setting);
return collection;
}
use of com.tvd12.dahlia.core.setting.RuntimeSetting in project dahlia by youngmonkeys.
the class CommandCreateDatabaseHandler method handle.
@Override
public Object handle(CommandCreateDatabase command) {
DatabaseSetting setting = command.getSetting();
String databaseName = setting.getDatabaseName();
Database existedDatabase = databases.getDatabase(databaseName);
if (existedDatabase != null)
throw new DatabaseExistedException(databaseName);
Database database = databaseFactory.newDatabase(setting);
synchronized (runtimeSetting) {
runtimeSetting.setMaxDatabaseId(database.getId());
storage.storeRuntimeSetting(runtimeSetting);
}
databases.addDatabase(database);
DatabaseStorage databaseStorage = databaseStorageFactory.newDatabaseStorage(databaseName);
storage.addDatabaseStorage(database.getId(), databaseStorage);
databaseStorage.storeSetting(setting);
return database;
}
Aggregations