use of com.tvd12.calabash.core.EntityMap in project calabash by youngmonkeys.
the class CalabashClientTest method test.
@SuppressWarnings("unchecked")
public void test() throws Exception {
CalabaseClient client = CalabashClientFactory.builder().build().newClient();
EntityMap<String, String> map = client.getMap("world", String.class, String.class);
System.out.println("Map: " + map);
map.set("Hello", "World");
System.out.println("set ok");
map.put("Foo", "Bar");
System.out.println("put ok");
map.putAll(EzyMapBuilder.mapBuilder().put("Who", "Are You?").build());
System.out.println("Hello " + map.get("Hello"));
System.out.println("Hello " + map.get(Sets.newHashSet("Hello", "Who")));
IAtomicLong atomicLong = client.getAtomicLong("hello");
System.out.println("AtomicLong.id = " + atomicLong);
System.out.println("AtomicLong.value1 = " + atomicLong.incrementAndGet());
System.out.println("AtomicLong.value2 = " + atomicLong.addAndGet(100));
MessageChannel<String> messageChannel = client.getMessageChannel("hello", String.class);
messageChannel.addSubscriber(message -> {
System.out.println("received message: " + message);
});
System.out.println("message channel: " + messageChannel);
Thread.sleep(500);
messageChannel.publish("Don't do that");
System.out.println("publish message ok");
}
use of com.tvd12.calabash.core.EntityMap in project calabash by youngmonkeys.
the class SimpleEntityMapFactory method newMap.
@Override
public EntityMap newMap(String mapName) {
EntityMap map = createMap(mapName);
newMapPersist(mapName);
return map;
}
use of com.tvd12.calabash.core.EntityMap 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);
}
}
use of com.tvd12.calabash.core.EntityMap 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);
}
}
use of com.tvd12.calabash.core.EntityMap in project calabash by youngmonkeys.
the class SimpleEntityMapManager method newMap.
protected EntityMap newMap(String mapName) {
synchronized (maps) {
EntityMap map = maps.get(mapName);
if (map == null) {
map = mapFactory.newMap(mapName);
maps.put(mapName, map);
}
return map;
}
}
Aggregations