use of org.apache.ignite.client.ClientDisconnectListener 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 org.apache.ignite.client.ClientDisconnectListener in project ignite by apache.
the class TcpClientCache method registerCacheEntryListener.
/**
* {@inheritDoc}
*/
@Override
public void registerCacheEntryListener(CacheEntryListenerConfiguration<K, V> cfg, ClientDisconnectListener disconnectLsnr) {
A.ensure(!cfg.isSynchronous(), "Unsupported cfg.isSynchronous() flag value");
A.notNull(cfg.getCacheEntryListenerFactory(), "cfg.getCacheEntryListenerFactory()");
ClientCacheEntryListenerHandler<K, V> hnd = new ClientCacheEntryListenerHandler<>(jCacheAdapter, ch, marsh, keepBinary);
if (lsnrsRegistry.registerCacheEntryListener(name, cfg, hnd)) {
CacheEntryListener<? super K, ? super V> locLsnr = cfg.getCacheEntryListenerFactory().create();
ClientDisconnectListener disconnectLsnr0 = e -> {
if (disconnectLsnr != null)
disconnectLsnr.onDisconnected(e);
lsnrsRegistry.deregisterCacheEntryListener(name, cfg);
};
hnd.startListen(new ClientJCacheEntryListenerAdapter<>(locLsnr), disconnectLsnr0, cfg.getCacheEntryEventFilterFactory(), ContinuousQuery.DFLT_PAGE_SIZE, ContinuousQuery.DFLT_TIME_INTERVAL, locLsnr instanceof CacheEntryExpiredListener);
} else
throw new IllegalStateException("Listener is already registered for configuration: " + cfg);
}
use of org.apache.ignite.client.ClientDisconnectListener in project ignite by apache.
the class ClientCacheEntryListenerHandler method onChannelClosed.
/**
* {@inheritDoc}
*/
@Override
public void onChannelClosed(Exception reason) {
ClientDisconnectListener lsnr = disconnectLsnr;
if (lsnr != null)
lsnr.onDisconnected(reason);
U.closeQuiet(this);
}
use of org.apache.ignite.client.ClientDisconnectListener in project ignite by apache.
the class ClientCacheEntryListenerHandler method startListen.
/**
* Send request to the server and start
*/
public synchronized void startListen(CacheEntryUpdatedListener<K, V> locLsnr, ClientDisconnectListener disconnectLsnr, Factory<? extends CacheEntryEventFilter<? super K, ? super V>> rmtFilterFactory, int pageSize, long timeInterval, boolean includeExpired) {
assert locLsnr != null;
if (clientCh != null)
throw new IllegalStateException("Listener was already started");
this.locLsnr = locLsnr;
this.disconnectLsnr = disconnectLsnr;
Consumer<PayloadOutputChannel> qryWriter = payloadCh -> {
BinaryOutputStream out = payloadCh.out();
out.writeInt(ClientUtils.cacheId(jCacheAdapter.getName()));
out.writeByte(keepBinary ? KEEP_BINARY_FLAG_MASK : 0);
out.writeInt(pageSize);
out.writeLong(timeInterval);
out.writeBoolean(includeExpired);
if (rmtFilterFactory == null)
out.writeByte(GridBinaryMarshaller.NULL);
else {
utils.writeObject(out, rmtFilterFactory);
out.writeByte(JAVA_PLATFORM);
}
};
Function<PayloadInputChannel, T2<ClientChannel, Long>> qryReader = payloadCh -> {
ClientChannel ch = payloadCh.clientChannel();
Long rsrcId = payloadCh.in().readLong();
ch.addNotificationListener(CONTINUOUS_QUERY_EVENT, rsrcId, this);
return new T2<>(ch, rsrcId);
};
try {
T2<ClientChannel, Long> params = ch.service(ClientOperation.QUERY_CONTINUOUS, qryWriter, qryReader);
clientCh = params.get1();
rsrcId = params.get2();
} catch (ClientError e) {
throw new ClientException(e);
}
}
Aggregations