use of javax.cache.event.CacheEntryListenerException in project camel by apache.
the class JCacheConsumerTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("myFilter", new CacheEntryEventFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
if (event.getEventType() == EventType.REMOVED) {
return false;
}
return !event.getValue().toString().startsWith("to-filter-");
}
});
return registry;
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class JavaThinClient method continuousQueries.
void continuousQueries() throws Exception {
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient client = Ignition.startClient(clientCfg)) {
// tag::continuous-queries[]
ClientCache<Integer, String> cache = client.getOrCreateCache("myCache");
ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException {
// react to the update events here
}
});
ClientDisconnectListener disconnectListener = new ClientDisconnectListener() {
@Override
public void onDisconnected(Exception reason) {
// react to the disconnect event here
}
};
cache.query(query, disconnectListener);
// end::continuous-queries[]
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class UsingContinuousQueries method localListenerExample.
public static void localListenerExample() {
try (Ignite ignite = Ignition.start()) {
// tag::localListener[]
IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");
ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException {
// react to the update events here
}
});
cache.query(query);
// end::localListener[]
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class PlatformContinuousQueryRemoteFilter method evaluate.
/**
* {@inheritDoc}
*/
@Override
public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
long ptr0 = ptr;
if (ptr0 == 0)
deploy();
lock.readLock().lock();
try {
if (closed)
throw new CacheEntryListenerException("Failed to evaluate the filter because it has been closed.");
PlatformContext platformCtx = PlatformUtils.platformContext(grid);
return PlatformUtils.evaluateContinuousQueryEvent(platformCtx, ptr, evt);
} finally {
lock.readLock().unlock();
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class PlatformContinuousQueryRemoteFilter method deploy.
/**
* Deploy filter to native platform.
*/
private void deploy() {
lock.writeLock().lock();
try {
// 1. Do not deploy if the filter has been closed concurrently.
if (closed)
throw new CacheEntryListenerException("Failed to deploy the filter because it has been closed.");
// 2. Deploy.
PlatformContext ctx = PlatformUtils.platformContext(grid);
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(filter);
out.synchronize();
ptr = ctx.gateway().continuousQueryFilterCreate(mem.pointer());
} catch (Exception e) {
// 3. Close in case of failure.
close();
throw new CacheEntryListenerException("Failed to deploy the filter.", e);
}
} finally {
lock.writeLock().unlock();
}
}
Aggregations