Search in sources :

Example 1 with RuntimeSetting

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;
}
Also used : EzyObject(com.tvd12.ezyfox.entity.EzyObject) RuntimeSetting(com.tvd12.dahlia.core.setting.RuntimeSetting)

Example 2 with RuntimeSetting

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;
}
Also used : EzyObject(com.tvd12.ezyfox.entity.EzyObject)

Example 3 with RuntimeSetting

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;
}
Also used : CollectionFactory(com.tvd12.dahlia.core.factory.CollectionFactory) RuntimeSetting(com.tvd12.dahlia.core.setting.RuntimeSetting) Storage(com.tvd12.dahlia.core.storage.Storage) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage) Databases(com.tvd12.dahlia.core.entity.Databases) DatabaseFactory(com.tvd12.dahlia.core.factory.DatabaseFactory) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 4 with RuntimeSetting

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;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) DatabaseNotFoundException(com.tvd12.dahlia.exception.DatabaseNotFoundException) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) Database(com.tvd12.dahlia.core.entity.Database) CommandCreateCollection(com.tvd12.dahlia.core.command.CommandCreateCollection) Collection(com.tvd12.dahlia.core.entity.Collection) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 5 with RuntimeSetting

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;
}
Also used : Database(com.tvd12.dahlia.core.entity.Database) CommandCreateDatabase(com.tvd12.dahlia.core.command.CommandCreateDatabase) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Aggregations

RuntimeSetting (com.tvd12.dahlia.core.setting.RuntimeSetting)3 Database (com.tvd12.dahlia.core.entity.Database)2 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)2 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)2 DatabaseStorage (com.tvd12.dahlia.core.storage.DatabaseStorage)2 EzyObject (com.tvd12.ezyfox.entity.EzyObject)2 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)1 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)1 Collection (com.tvd12.dahlia.core.entity.Collection)1 Databases (com.tvd12.dahlia.core.entity.Databases)1 CollectionFactory (com.tvd12.dahlia.core.factory.CollectionFactory)1 DatabaseFactory (com.tvd12.dahlia.core.factory.DatabaseFactory)1 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)1 Storage (com.tvd12.dahlia.core.storage.Storage)1 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)1 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)1 DatabaseNotFoundException (com.tvd12.dahlia.exception.DatabaseNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1