Search in sources :

Example 1 with SimpleSettings

use of com.tvd12.calabash.local.setting.SimpleSettings in project calabash by youngmonkeys.

the class LocalMapAnimalPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() throws Exception {
    SimpleSettings settings = new SimpleSettings();
    SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
    mapPersistSetting.setWriteDelay(0);
    SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
    mapSetting.setMapName(CollectionNames.ANIMAL);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistences = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistences) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Animal animal = new Animal(2, "animal 2", "cat");
    EntityMap<Long, Animal> entityMap = calabash.getEntityMap(CollectionNames.ANIMAL);
    entityMap.put(animal.getId(), animal);
    AnimalByNickQuery query = new AnimalByNickQuery(animal.getNick());
    Animal animalByQuery = entityMap.getByQuery(1L, query);
    System.out.println("animal by query: " + animalByQuery);
    Map<String, Object> statistics = new HashMap<>();
    // noinspection InfiniteLoopStatement
    while (true) {
        // noinspection BusyWait
        Thread.sleep(1000);
        ((StatisticsAware) calabash).addStatistics(statistics);
        System.out.println("statistics: " + statistics);
    }
}
Also used : SimpleEntityMapSetting(com.tvd12.calabash.local.setting.SimpleEntityMapSetting) SimpleSettings(com.tvd12.calabash.local.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) HashMap(java.util.HashMap) SimpleEntityMapPersistSetting(com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting) CalabashBuilder(com.tvd12.calabash.local.CalabashBuilder) Animal(com.tvd12.calabash.local.test.mappersist.Animal) List(java.util.List) StatisticsAware(com.tvd12.calabash.core.statistic.StatisticsAware) Calabash(com.tvd12.calabash.Calabash) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)

Example 2 with SimpleSettings

use of com.tvd12.calabash.local.setting.SimpleSettings in project calabash by youngmonkeys.

the class LocalMapPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() throws Exception {
    SimpleSettings settings = new SimpleSettings();
    SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
    mapPersistSetting.setWriteDelay(0);
    SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
    mapSetting.setMapName(CollectionNames.PERSON);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistenceList) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Person person = new Person(11, "person 6", 18);
    EntityMap<Long, Person> entityMap = calabash.getEntityMap(CollectionNames.PERSON);
    entityMap.put(person.getId(), person);
    IAtomicLong atomicLong = calabash.getAtomicLong("hello");
    long newValue = atomicLong.addAndGet(100L);
    System.out.println("atomic long new value: " + newValue);
    Map<String, Object> statistics = new HashMap<>();
    // noinspection InfiniteLoopStatement
    while (true) {
        // noinspection BusyWait
        Thread.sleep(1000);
        ((StatisticsAware) calabash).addStatistics(statistics);
        System.out.println("statistics: " + statistics);
    }
}
Also used : SimpleEntityMapSetting(com.tvd12.calabash.local.setting.SimpleEntityMapSetting) SimpleSettings(com.tvd12.calabash.local.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) HashMap(java.util.HashMap) SimpleEntityMapPersistSetting(com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting) CalabashBuilder(com.tvd12.calabash.local.CalabashBuilder) IAtomicLong(com.tvd12.calabash.core.IAtomicLong) List(java.util.List) StatisticsAware(com.tvd12.calabash.core.statistic.StatisticsAware) Calabash(com.tvd12.calabash.Calabash) IAtomicLong(com.tvd12.calabash.core.IAtomicLong) Person(com.tvd12.calabash.local.test.mappersist.Person) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)

Example 3 with SimpleSettings

use of com.tvd12.calabash.local.setting.SimpleSettings in project calabash by youngmonkeys.

the class LocalMapPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() {
    EzyEntityCodec entityCodec = newEntityCodec();
    SimpleSettings settings = new SimpleSettings();
    SimpleMapPersistSetting mapPersistSetting = new SimpleMapPersistSetting();
    SimpleMapSetting mapSetting = new SimpleMapSetting();
    mapSetting.setMapName(CollectionNames.PERSON);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistenceList) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    BytesMapPersistFactory bytesMapPersistFactory = EntityBytesMapPersistFactory.builder().entityCodec(entityCodec).entityMapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Calabash calabash = CalabashServerContext.builder().settings(settings).bytesMapPersistFactory(bytesMapPersistFactory).build();
    ByteArray keyBytes = new ByteArray(entityCodec.serialize(1L));
    byte[] values = entityCodec.serialize(new Person(9L, "bar", 29));
    BytesMap bytesMap = calabash.getBytesMap(CollectionNames.PERSON);
    bytesMap.put(keyBytes, values);
}
Also used : SimpleSettings(com.tvd12.calabash.server.core.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) BytesMap(com.tvd12.calabash.core.BytesMap) SimpleMapSetting(com.tvd12.calabash.server.core.setting.SimpleMapSetting) ByteArray(com.tvd12.calabash.core.util.ByteArray) List(java.util.List) SimpleMapPersistSetting(com.tvd12.calabash.persist.setting.SimpleMapPersistSetting) Calabash(com.tvd12.calabash.Calabash) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory) EntityBytesMapPersistFactory(com.tvd12.calabash.persist.factory.EntityBytesMapPersistFactory) BytesMapPersistFactory(com.tvd12.calabash.persist.factory.BytesMapPersistFactory)

Example 4 with SimpleSettings

use of com.tvd12.calabash.local.setting.SimpleSettings in project calabash by youngmonkeys.

the class LocalExample method main.

public static void main(String[] args) {
    Settings settings = new SimpleSettings();
    MapPersistManager mapPersistManager = new SimpleMapPersistManager();
    BytesMapBackupExecutor backupExecutor = new SimpleBytesMapBackupExecutor();
    BytesMapPersistExecutor persistExecutor = SimpleBytesMapPersistExecutor.builder().mapPersistManager(mapPersistManager).build();
    BytesMap bytesMap = BytesMapImpl.builder().mapSetting(settings.getMapSetting("test")).mapBackupExecutor(backupExecutor).mapPersistExecutor(persistExecutor).build();
    bytesMap.loadAll();
    bytesMap.put(new ByteArray(new byte[] { 1, 2, 3 }), new byte[] { 1, 2, 3 });
    System.out.println(Arrays.toString(bytesMap.get(new ByteArray(new byte[] { 1, 2, 3 }))));
}
Also used : BytesMapBackupExecutor(com.tvd12.calabash.server.core.executor.BytesMapBackupExecutor) SimpleBytesMapBackupExecutor(com.tvd12.calabash.server.core.executor.SimpleBytesMapBackupExecutor) SimpleBytesMapPersistExecutor(com.tvd12.calabash.server.core.executor.SimpleBytesMapPersistExecutor) BytesMapPersistExecutor(com.tvd12.calabash.server.core.executor.BytesMapPersistExecutor) SimpleMapPersistManager(com.tvd12.calabash.persist.manager.SimpleMapPersistManager) SimpleSettings(com.tvd12.calabash.server.core.setting.SimpleSettings) SimpleBytesMapBackupExecutor(com.tvd12.calabash.server.core.executor.SimpleBytesMapBackupExecutor) BytesMap(com.tvd12.calabash.core.BytesMap) ByteArray(com.tvd12.calabash.core.util.ByteArray) SimpleSettings(com.tvd12.calabash.server.core.setting.SimpleSettings) Settings(com.tvd12.calabash.server.core.setting.Settings) MapPersistManager(com.tvd12.calabash.persist.manager.MapPersistManager) SimpleMapPersistManager(com.tvd12.calabash.persist.manager.SimpleMapPersistManager)

Aggregations

Calabash (com.tvd12.calabash.Calabash)3 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)3 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)3 List (java.util.List)3 BytesMap (com.tvd12.calabash.core.BytesMap)2 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)2 ByteArray (com.tvd12.calabash.core.util.ByteArray)2 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)2 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)2 SimpleEntityMapSetting (com.tvd12.calabash.local.setting.SimpleEntityMapSetting)2 SimpleSettings (com.tvd12.calabash.local.setting.SimpleSettings)2 SimpleSettings (com.tvd12.calabash.server.core.setting.SimpleSettings)2 HashMap (java.util.HashMap)2 IAtomicLong (com.tvd12.calabash.core.IAtomicLong)1 Animal (com.tvd12.calabash.local.test.mappersist.Animal)1 Person (com.tvd12.calabash.local.test.mappersist.Person)1 BytesMapPersistFactory (com.tvd12.calabash.persist.factory.BytesMapPersistFactory)1 EntityBytesMapPersistFactory (com.tvd12.calabash.persist.factory.EntityBytesMapPersistFactory)1 MapPersistManager (com.tvd12.calabash.persist.manager.MapPersistManager)1 SimpleMapPersistManager (com.tvd12.calabash.persist.manager.SimpleMapPersistManager)1