Search in sources :

Example 1 with CONTINUOUS_QUERY_EVENT

use of org.apache.ignite.internal.client.thin.ClientNotificationType.CONTINUOUS_QUERY_EVENT 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);
    }
}
Also used : Factory(javax.cache.configuration.Factory) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) EventType(javax.cache.event.EventType) ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) CONTINUOUS_QUERY_EVENT(org.apache.ignite.internal.client.thin.ClientNotificationType.CONTINUOUS_QUERY_EVENT) U(org.apache.ignite.internal.util.typedef.internal.U) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ArrayList(java.util.ArrayList) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) List(java.util.List) CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) ClientException(org.apache.ignite.client.ClientException) BinaryByteBufferInputStream(org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream) Cache(javax.cache.Cache) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) JAVA_PLATFORM(org.apache.ignite.internal.client.thin.TcpClientCache.JAVA_PLATFORM) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) ClientException(org.apache.ignite.client.ClientException) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Cache (javax.cache.Cache)1 Factory (javax.cache.configuration.Factory)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 CacheEntryEventFilter (javax.cache.event.CacheEntryEventFilter)1 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)1 EventType (javax.cache.event.EventType)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 ClientDisconnectListener (org.apache.ignite.client.ClientDisconnectListener)1 ClientException (org.apache.ignite.client.ClientException)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1 BinaryByteBufferInputStream (org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream)1 BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)1 BinaryOutputStream (org.apache.ignite.internal.binary.streams.BinaryOutputStream)1 CONTINUOUS_QUERY_EVENT (org.apache.ignite.internal.client.thin.ClientNotificationType.CONTINUOUS_QUERY_EVENT)1 JAVA_PLATFORM (org.apache.ignite.internal.client.thin.TcpClientCache.JAVA_PLATFORM)1