Package org.apache.ignite.cache.query

## Class ContinuousQueryWithTransformer<K,​V,​T>

- java.lang.Object
- - org.apache.ignite.cache.query.Query<javax.cache.Cache.Entry<K,​V>>
  - - org.apache.ignite.cache.query.AbstractContinuousQuery<K,​V>
    - - org.apache.ignite.cache.query.ContinuousQueryWithTransformer<K,​V,​T>

- All Implemented Interfaces:
    `Serializable`

      public final class ContinuousQueryWithTransformer<K,​V,​T>
      extends AbstractContinuousQuery<K,​V>

  API for configuring continuous cache queries with transformer.

  Continuous queries allow to register a remote filter and a local listener for cache updates. If an update event passes the filter, it will be transformed with transformer and sent to the node that executed the query and local listener will be notified.

  Additionally, you can execute initial query to get currently existing data. Query can be of any type (SQL, TEXT or SCAN) and can be set via `setInitialQuery(Query)` method.

  Query can be executed either on all nodes in topology using `IgniteCache.query(Query)` method, or only on the local node, if `Query.setLocal(boolean)` parameter is set to `true`. Note that in case query is distributed and a new node joins, it will get the remote filter for the query during discovery process before it actually joins topology, so no updates will be missed. This will execute query on all nodes that have cache you are working with and listener will start to receive notifications for cache updates.

  To stop receiving updates call `QueryCursor.close()` method. Note that this works even if you didn't provide initial query. Cursor will be empty in this case, but it will still unregister listeners when `QueryCursor.close()` is called.

  `IgniteAsyncCallback` annotation is supported for `CacheEntryEventFilter` (see `setRemoteFilterFactory(Factory)`) and `CacheEntryUpdatedListener` (see `setRemoteTransformerFactory(Factory)`) and `CacheEntryUpdatedListener` (see `setLocalListener(EventListener)` and `ContinuousQueryWithTransformer.EventListener`). If filter and/or listener are annotated with `IgniteAsyncCallback` then annotated callback is executed in async callback pool (see `IgniteConfiguration.getAsyncCallbackPoolSize()`) and notification order is kept the same as update order for given cache key.

  See Also:
    `ContinuousQuery`, `IgniteAsyncCallback`, `IgniteConfiguration.getAsyncCallbackPoolSize()`, Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `ContinuousQueryWithTransformer.EventListener<T>` | Interface for local listener of `ContinuousQueryWithTransformer` to implement.

  - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.cache.query.AbstractContinuousQuery

      `DFLT_AUTO_UNSUBSCRIBE, DFLT_PAGE_SIZE, DFLT_TIME_INTERVAL`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ContinuousQueryWithTransformer()` | Creates new continuous query with transformer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ContinuousQueryWithTransformer.EventListener<T>` | `getLocalListener()` | Gets local transformed event listener
    `javax.cache.configuration.Factory<? extends IgniteClosure<javax.cache.event.CacheEntryEvent<? extends K,​? extends V>,​T>>` | `getRemoteTransformerFactory()` | Gets remote transformer factory
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setAutoUnsubscribe​(boolean autoUnsubscribe)` | Sets automatic unsubscribe flag.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setInitialQuery​(Query<javax.cache.Cache.Entry<K,​V>> initQry)` | Sets initial query.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setLocal​(boolean loc)` | Sets whether this query should be executed on local node only.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setLocalListener​(ContinuousQueryWithTransformer.EventListener<T> locLsnr)` | Sets local callback.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setPageSize​(int pageSize)` | Sets optional page size, if `0`, then default is used.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setRemoteFilterFactory​(javax.cache.configuration.Factory<? extends javax.cache.event.CacheEntryEventFilter<K,​V>> rmtFilterFactory)` | Sets optional key-value filter factory.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setRemoteTransformerFactory​(javax.cache.configuration.Factory<? extends IgniteClosure<javax.cache.event.CacheEntryEvent<? extends K,​? extends V>,​T>> factory)` | Sets transformer factory.
    `ContinuousQueryWithTransformer<K,​V,​T>` | `setTimeInterval​(long timeInterval)` | Sets time interval.

    - ### Methods inherited from class org.apache.ignite.cache.query.AbstractContinuousQuery

      `getInitialQuery, getRemoteFilterFactory, getTimeInterval, isAutoUnsubscribe, isIncludeExpired, setIncludeExpired`

    - ### Methods inherited from class org.apache.ignite.cache.query.Query

      `getPageSize, isLocal, prepare, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ContinuousQueryWithTransformer

          public ContinuousQueryWithTransformer()

      Creates new continuous query with transformer.

  - ### Method Detail

    - #### setInitialQuery

          public ContinuousQueryWithTransformer<K,​V,​T> setInitialQuery​(Query<javax.cache.Cache.Entry<K,​V>> initQry)

      Sets initial query.

      This query will be executed before continuous listener is registered which allows to iterate through entries which already existed at the time continuous query is executed.

      Overrides:
        `setInitialQuery` in class `AbstractContinuousQuery<K,​V>`
      Parameters:
        `initQry` - Initial query.
      Returns:
        `this` for chaining.

    - #### setRemoteFilterFactory

          public ContinuousQueryWithTransformer<K,​V,​T> setRemoteFilterFactory​(javax.cache.configuration.Factory<? extends javax.cache.event.CacheEntryEventFilter<K,​V>> rmtFilterFactory)

      Sets optional key-value filter factory. This factory produces filter is called before entry is sent to the master node.

      WARNING: all operations that involve any kind of JVM-local or distributed locking (e.g., synchronization or transactional cache operations), should be executed asynchronously without blocking the thread that called the filter. Otherwise, you can get deadlocks.

      If remote filter are annotated with `IgniteAsyncCallback` then it is executed in async callback pool (see `IgniteConfiguration.getAsyncCallbackPoolSize()`) that allow to perform a cache operations.

      Overrides:
        `setRemoteFilterFactory` in class `AbstractContinuousQuery<K,​V>`
      Parameters:
        `rmtFilterFactory` - Key-value filter factory.
      Returns:
        `this` for chaining.
      See Also:
        `IgniteAsyncCallback`, `IgniteConfiguration.getAsyncCallbackPoolSize()`

    - #### setRemoteTransformerFactory

          public ContinuousQueryWithTransformer<K,​V,​T> setRemoteTransformerFactory​(javax.cache.configuration.Factory<? extends IgniteClosure<javax.cache.event.CacheEntryEvent<? extends K,​? extends V>,​T>> factory)

      Sets transformer factory. This factory produces transformer is called after and only if entry passes the filter.

      WARNING: all operations that involve any kind of JVM-local or distributed locking (e.g., synchronization or transactional cache operations), should be executed asynchronously without blocking the thread that called the filter. Otherwise, you can get deadlocks.

      Parameters:
        `factory` - Remote transformer factory.
      Returns:
        `this` for chaining.

    - #### getRemoteTransformerFactory

          public javax.cache.configuration.Factory<? extends IgniteClosure<javax.cache.event.CacheEntryEvent<? extends K,​? extends V>,​T>> getRemoteTransformerFactory()

      Gets remote transformer factory
      Returns:
        Remote Transformer Factory

    - #### setLocalListener

          public ContinuousQueryWithTransformer<K,​V,​T> setLocalListener​(ContinuousQueryWithTransformer.EventListener<T> locLsnr)

      Sets local callback. This callback is called only in local node when new updates are received.

      The callback predicate accepts results of transformed by `AbstractContinuousQuery.getRemoteFilterFactory()` events

      WARNING: all operations that involve any kind of JVM-local or distributed locking (e.g., synchronization or transactional cache operations), should be executed asynchronously without blocking the thread that called the callback. Otherwise, you can get deadlocks.

      If local listener are annotated with `IgniteAsyncCallback` then it is executed in async callback pool (see `IgniteConfiguration.getAsyncCallbackPoolSize()`) that allow to perform a cache operations.

      Parameters:
        `locLsnr` - Local callback.
      Returns:
        `this` for chaining.
      See Also:
        `IgniteAsyncCallback`, `IgniteConfiguration.getAsyncCallbackPoolSize()`, `ContinuousQuery.setLocalListener(CacheEntryUpdatedListener)`

    - #### getLocalListener

          public ContinuousQueryWithTransformer.EventListener<T> getLocalListener()

      Gets local transformed event listener
      Returns:
        local transformed event listener

    - #### setTimeInterval

          public ContinuousQueryWithTransformer<K,​V,​T> setTimeInterval​(long timeInterval)

      Sets time interval.

      When a cache update happens, entry is first put into a buffer. Entries from buffer will be sent to the master node only if the buffer is full (its size can be provided via `Query.setPageSize(int)` method) or time provided via this method is exceeded.

      Default time interval is `0` which means that time check is disabled and entries will be sent only when buffer is full.

      Overrides:
        `setTimeInterval` in class `AbstractContinuousQuery<K,​V>`
      Parameters:
        `timeInterval` - Time interval.
      Returns:
        `this` for chaining.

    - #### setAutoUnsubscribe

          public ContinuousQueryWithTransformer<K,​V,​T> setAutoUnsubscribe​(boolean autoUnsubscribe)

      Sets automatic unsubscribe flag.

      This flag indicates that query filters on remote nodes should be automatically unregistered if master node (node that initiated the query) leaves topology. If this flag is `false`, filters will be unregistered only when the query is cancelled from master node, and won't ever be unregistered if master node leaves grid.

      Default value for this flag is `true`.

      Overrides:
        `setAutoUnsubscribe` in class `AbstractContinuousQuery<K,​V>`
      Parameters:
        `autoUnsubscribe` - Automatic unsubscription flag.
      Returns:
        `this` for chaining.

    - #### setPageSize

          public ContinuousQueryWithTransformer<K,​V,​T> setPageSize​(int pageSize)

      Sets optional page size, if `0`, then default is used.
      Overrides:
        `setPageSize` in class `Query<javax.cache.Cache.Entry<K,​V>>`
      Parameters:
        `pageSize` - Optional page size.
      Returns:
        `this` for chaining.

    - #### setLocal

          public ContinuousQueryWithTransformer<K,​V,​T> setLocal​(boolean loc)

      Sets whether this query should be executed on local node only.
      Overrides:
        `setLocal` in class `Query<javax.cache.Cache.Entry<K,​V>>`
      Parameters:
        `loc` - Local flag.
      Returns:
        `this` for chaining.