Search in sources :

Example 6 with ByteArray

use of com.tvd12.calabash.core.util.ByteArray 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 7 with ByteArray

use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.

the class MapRequestController method mapGetMany.

@Rpc(Commands.MAP_GET_MANY)
public List<byte[]> mapGetMany(MapGetManyRequest request) {
    BytesMap map = getBytesMap(request.getMapId());
    List<ByteArray> keys = ByteArray.wrap(request.getKeys());
    Map<ByteArray, byte[]> m = map.get(keys);
    List<byte[]> answer = new ArrayList<>(keys.size());
    for (ByteArray key : keys) {
        answer.add(m.get(key));
    }
    return answer;
}
Also used : BytesMap(com.tvd12.calabash.core.BytesMap) ArrayList(java.util.ArrayList) ByteArray(com.tvd12.calabash.core.util.ByteArray) Rpc(com.tvd12.quick.rpc.server.annotation.Rpc)

Example 8 with ByteArray

use of com.tvd12.calabash.core.util.ByteArray 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)

Example 9 with ByteArray

use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.

the class SimpleBytesMapPersistExecutor method persist.

@Override
public void persist(MapSetting mapSetting, Map<ByteArray, byte[]> m) {
    BytesMapPersist mapPersist = getMapPersist(mapSetting);
    if (mapPersist != null) {
        PersistSaveManyAction action = new PersistSaveManyAction(m);
        addPersistActionToQueue(mapSetting, action);
    }
}
Also used : BytesMapPersist(com.tvd12.calabash.persist.BytesMapPersist)

Example 10 with ByteArray

use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.

the class SimpleBytesMapPersistExecutor method delete.

@Override
public void delete(MapSetting mapSetting, Set<ByteArray> keys) {
    BytesMapPersist mapPersist = getMapPersist(mapSetting);
    if (mapPersist != null) {
        PersistDeleteManyAction action = new PersistDeleteManyAction(keys);
        addPersistActionToQueue(mapSetting, action);
    }
}
Also used : BytesMapPersist(com.tvd12.calabash.persist.BytesMapPersist)

Aggregations

ByteArray (com.tvd12.calabash.core.util.ByteArray)10 BytesMapPersist (com.tvd12.calabash.persist.BytesMapPersist)4 BytesMap (com.tvd12.calabash.core.BytesMap)3 HashMap (java.util.HashMap)3 SimpleSettings (com.tvd12.calabash.server.core.setting.SimpleSettings)2 Calabash (com.tvd12.calabash.Calabash)1 BytesMapPersistFactory (com.tvd12.calabash.persist.factory.BytesMapPersistFactory)1 EntityBytesMapPersistFactory (com.tvd12.calabash.persist.factory.EntityBytesMapPersistFactory)1 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)1 MapPersistManager (com.tvd12.calabash.persist.manager.MapPersistManager)1 SimpleMapPersistManager (com.tvd12.calabash.persist.manager.SimpleMapPersistManager)1 SimpleMapPersistSetting (com.tvd12.calabash.persist.setting.SimpleMapPersistSetting)1 BytesMapBackupExecutor (com.tvd12.calabash.server.core.executor.BytesMapBackupExecutor)1 BytesMapPersistExecutor (com.tvd12.calabash.server.core.executor.BytesMapPersistExecutor)1 SimpleBytesMapBackupExecutor (com.tvd12.calabash.server.core.executor.SimpleBytesMapBackupExecutor)1 SimpleBytesMapPersistExecutor (com.tvd12.calabash.server.core.executor.SimpleBytesMapPersistExecutor)1 Settings (com.tvd12.calabash.server.core.setting.Settings)1 SimpleMapSetting (com.tvd12.calabash.server.core.setting.SimpleMapSetting)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 Rpc (com.tvd12.quick.rpc.server.annotation.Rpc)1