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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations