Search in sources :

Example 1 with IAtomicLong

use of com.tvd12.calabash.core.IAtomicLong 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");
}
Also used : CalabaseClient(com.tvd12.calabash.client.CalabaseClient) IAtomicLong(com.tvd12.calabash.core.IAtomicLong)

Example 2 with IAtomicLong

use of com.tvd12.calabash.core.IAtomicLong 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 IAtomicLong

use of com.tvd12.calabash.core.IAtomicLong in project calabash by youngmonkeys.

the class SimpleAtomicLongManager method newAtomicLong.

protected IAtomicLong newAtomicLong(String name) {
    synchronized (atomicLongs) {
        IAtomicLong atomicLong = atomicLongs.get(name);
        if (atomicLong == null) {
            atomicLong = new AtomicLongImpl(name, map);
            atomicLongs.put(name, atomicLong);
        }
        return atomicLong;
    }
}
Also used : AtomicLongImpl(com.tvd12.calabash.server.core.impl.AtomicLongImpl) IAtomicLong(com.tvd12.calabash.core.IAtomicLong)

Example 4 with IAtomicLong

use of com.tvd12.calabash.core.IAtomicLong in project calabash by youngmonkeys.

the class SimpleAtomicLongManager method newAtomicLong.

protected IAtomicLong newAtomicLong(String name) {
    synchronized (atomicLongs) {
        IAtomicLong atomicLong = atomicLongs.get(name);
        if (atomicLong == null) {
            atomicLong = new AtomicLongImpl(name, map);
            atomicLongs.put(name, atomicLong);
        }
        return atomicLong;
    }
}
Also used : AtomicLongImpl(com.tvd12.calabash.local.impl.AtomicLongImpl) IAtomicLong(com.tvd12.calabash.core.IAtomicLong)

Example 5 with IAtomicLong

use of com.tvd12.calabash.core.IAtomicLong in project calabash by youngmonkeys.

the class AtomicLongProvider method newAtomicLong.

protected IAtomicLong newAtomicLong(String name) {
    synchronized (atomicLongs) {
        IAtomicLong atomicLong = atomicLongs.get(name);
        if (atomicLong == null) {
            atomicLong = atomicLongFactory.newAtomicLong(name);
            atomicLongs.put(name, atomicLong);
        }
        return atomicLong;
    }
}
Also used : IAtomicLong(com.tvd12.calabash.core.IAtomicLong)

Aggregations

IAtomicLong (com.tvd12.calabash.core.IAtomicLong)5 Calabash (com.tvd12.calabash.Calabash)1 CalabaseClient (com.tvd12.calabash.client.CalabaseClient)1 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)1 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)1 AtomicLongImpl (com.tvd12.calabash.local.impl.AtomicLongImpl)1 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)1 SimpleEntityMapSetting (com.tvd12.calabash.local.setting.SimpleEntityMapSetting)1 SimpleSettings (com.tvd12.calabash.local.setting.SimpleSettings)1 Person (com.tvd12.calabash.local.test.mappersist.Person)1 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)1 AtomicLongImpl (com.tvd12.calabash.server.core.impl.AtomicLongImpl)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 HashMap (java.util.HashMap)1 List (java.util.List)1