Search in sources :

Example 1 with ClientDisconnectListener

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[]
    }
}
Also used : ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 2 with ClientDisconnectListener

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);
}
Also used : PlatformExpiryPolicy.convertDuration(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy.convertDuration) ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) TcpClientTransaction(org.apache.ignite.internal.client.thin.TcpClientTransactions.TcpClientTransaction) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) CacheEntryExpiredListener(javax.cache.event.CacheEntryExpiredListener) Function(java.util.function.Function) ClientCache(org.apache.ignite.client.ClientCache) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ClientException(org.apache.ignite.client.ClientException) CacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration) CacheEntryListener(javax.cache.event.CacheEntryListener) Map(java.util.Map) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Cache(javax.cache.Cache) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) EXPIRY_POLICY(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.EXPIRY_POLICY) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) Query(org.apache.ignite.cache.query.Query) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CachePeekMode(org.apache.ignite.cache.CachePeekMode) FactoryBuilder(javax.cache.configuration.FactoryBuilder) A(org.apache.ignite.internal.util.typedef.internal.A) IgniteClientFuture(org.apache.ignite.client.IgniteClientFuture) Set(java.util.Set) IOException(java.io.IOException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) QueryCursor(org.apache.ignite.cache.query.QueryCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CacheEntryExpiredListener(javax.cache.event.CacheEntryExpiredListener) ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener)

Example 3 with ClientDisconnectListener

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);
}
Also used : ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener)

Example 4 with ClientDisconnectListener

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

ClientDisconnectListener (org.apache.ignite.client.ClientDisconnectListener)4 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)3 ClientException (org.apache.ignite.client.ClientException)3 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Cache (javax.cache.Cache)2 CacheEntryEvent (javax.cache.event.CacheEntryEvent)2 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)2 BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)2 BinaryOutputStream (org.apache.ignite.internal.binary.streams.BinaryOutputStream)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 CacheEntryListenerConfiguration (javax.cache.configuration.CacheEntryListenerConfiguration)1 Factory (javax.cache.configuration.Factory)1 FactoryBuilder (javax.cache.configuration.FactoryBuilder)1