Search in sources :

Example 1 with BroadcasterCacheInspector

use of org.atmosphere.cache.BroadcasterCacheInspector in project atmosphere by Atmosphere.

the class BroadcasterConfig method configureBroadcasterCache.

private void configureBroadcasterCache() {
    try {
        String className = config.framework().getBroadcasterCacheClassName();
        if (className != null) {
            broadcasterCache = config.framework().newClassInstance(BroadcasterCache.class, (Class<BroadcasterCache>) IOUtils.loadClass(getClass(), className));
            configureSharedCacheExecutor();
            broadcasterCache.configure(config);
        }
        for (BroadcasterCacheInspector b : config.framework().inspectors()) {
            broadcasterCache.inspector(b);
        }
        for (BroadcasterCacheListener l : config.framework().broadcasterCacheListeners()) {
            broadcasterCache.addBroadcasterCacheListener(l);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector)

Example 2 with BroadcasterCacheInspector

use of org.atmosphere.cache.BroadcasterCacheInspector in project atmosphere by Atmosphere.

the class BroadcasterCacheTest method testCache.

@Test
public void testCache() throws ExecutionException, InterruptedException, ServletException {
    broadcaster.getBroadcasterConfig().setBroadcasterCache(new AbstractBroadcasterCache() {

        @Override
        public CacheMessage addToCache(String id, String uuid, BroadcastMessage e) {
            CacheMessage c = put(e, System.nanoTime(), uuid, broadcaster.getID());
            cachedMessage.set(messages);
            return c;
        }

        @Override
        public List<Object> retrieveFromCache(String id, String uuid) {
            return Collections.<Object>emptyList();
        }
    }).getBroadcasterCache().inspector(new BroadcasterCacheInspector() {

        @Override
        public boolean inspect(BroadcastMessage message) {
            return true;
        }
    });
    broadcaster.broadcast("foo", ar).get();
    assertEquals(cachedMessage.get().size(), 0);
}
Also used : CacheMessage(org.atmosphere.cache.CacheMessage) AbstractBroadcasterCache(org.atmosphere.cache.AbstractBroadcasterCache) BroadcastMessage(org.atmosphere.cache.BroadcastMessage) List(java.util.List) BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector) Test(org.testng.annotations.Test)

Example 3 with BroadcasterCacheInspector

use of org.atmosphere.cache.BroadcasterCacheInspector in project atmosphere by Atmosphere.

the class BroadcasterCacheTest method testEmptyCache.

@Test
public void testEmptyCache() throws ExecutionException, InterruptedException, ServletException {
    final CountDownLatch latch = new CountDownLatch(1);
    broadcaster.getBroadcasterConfig().setBroadcasterCache(new AbstractBroadcasterCache() {

        @Override
        public CacheMessage addToCache(String id, String uuid, BroadcastMessage e) {
            CacheMessage c = put(e, System.nanoTime(), uuid, broadcaster.getID());
            cachedMessage.set(messages);
            latch.countDown();
            return c;
        }

        @Override
        public List<Object> retrieveFromCache(String id, String uuid) {
            return Collections.<Object>emptyList();
        }
    }).getBroadcasterCache().inspector(new BroadcasterCacheInspector() {

        @Override
        public boolean inspect(BroadcastMessage message) {
            return true;
        }
    });
    broadcaster.broadcast("foo", ar);
    latch.await(10, TimeUnit.SECONDS);
    assertEquals(cachedMessage.get().size(), 1);
}
Also used : CacheMessage(org.atmosphere.cache.CacheMessage) AbstractBroadcasterCache(org.atmosphere.cache.AbstractBroadcasterCache) BroadcastMessage(org.atmosphere.cache.BroadcastMessage) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector) Test(org.testng.annotations.Test)

Example 4 with BroadcasterCacheInspector

use of org.atmosphere.cache.BroadcasterCacheInspector in project atmosphere by Atmosphere.

the class BroadcasterCacheTest method testRejectedCache.

@Test
public void testRejectedCache() throws ExecutionException, InterruptedException, ServletException {
    broadcaster.getBroadcasterConfig().setBroadcasterCache(new AbstractBroadcasterCache() {

        @Override
        public CacheMessage addToCache(String id, String uuid, BroadcastMessage e) {
            CacheMessage c = put(e, System.nanoTime(), uuid, broadcaster.getID());
            cachedMessage.set(messages);
            return c;
        }

        @Override
        public List<Object> retrieveFromCache(String id, String uuid) {
            return Collections.<Object>emptyList();
        }
    }).getBroadcasterCache().inspector(new BroadcasterCacheInspector() {

        @Override
        public boolean inspect(BroadcastMessage message) {
            return false;
        }
    });
    broadcaster.broadcast("foo", ar).get();
    assertEquals(cachedMessage.get().size(), 0);
}
Also used : CacheMessage(org.atmosphere.cache.CacheMessage) AbstractBroadcasterCache(org.atmosphere.cache.AbstractBroadcasterCache) BroadcastMessage(org.atmosphere.cache.BroadcastMessage) List(java.util.List) BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector) Test(org.testng.annotations.Test)

Example 5 with BroadcasterCacheInspector

use of org.atmosphere.cache.BroadcasterCacheInspector in project atmosphere by Atmosphere.

the class BroadcasterCacheTest method testEmptyRejectedCache.

@Test
public void testEmptyRejectedCache() throws ExecutionException, InterruptedException, ServletException {
    final CountDownLatch latch = new CountDownLatch(1);
    broadcaster.getBroadcasterConfig().setBroadcasterCache(new AbstractBroadcasterCache() {

        @Override
        public CacheMessage addToCache(String id, String uuid, BroadcastMessage e) {
            CacheMessage c = put(e, System.nanoTime(), uuid, broadcaster.getID());
            cachedMessage.set(messages);
            latch.countDown();
            return c;
        }

        @Override
        public List<Object> retrieveFromCache(String id, String uuid) {
            return Collections.<Object>emptyList();
        }
    }).getBroadcasterCache().inspector(new BroadcasterCacheInspector() {

        @Override
        public boolean inspect(BroadcastMessage message) {
            return false;
        }
    });
    broadcaster.broadcast("foo", ar);
    latch.await(10, TimeUnit.SECONDS);
    assertEquals(cachedMessage.get().size(), 0);
}
Also used : CacheMessage(org.atmosphere.cache.CacheMessage) AbstractBroadcasterCache(org.atmosphere.cache.AbstractBroadcasterCache) BroadcastMessage(org.atmosphere.cache.BroadcastMessage) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector) Test(org.testng.annotations.Test)

Aggregations

BroadcasterCacheInspector (org.atmosphere.cache.BroadcasterCacheInspector)5 List (java.util.List)4 AbstractBroadcasterCache (org.atmosphere.cache.AbstractBroadcasterCache)4 BroadcastMessage (org.atmosphere.cache.BroadcastMessage)4 CacheMessage (org.atmosphere.cache.CacheMessage)4 Test (org.testng.annotations.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)2