Chapter 8 Working With Continuous Queries : Overview of Continuous Queries

Overview of Continuous Queries
Continuous queries listen to and process the data stream of notifications sent from the cache. Notifications are sent when entities are added to, modified or deleted from the cache.
Unlike snapshot queries, continuous queries do not examine the cached entities themselves. Entities that were created before a query starts are not visible to it— unless they are modified while the query is running.
A continuous query returns results throughout its lifetime, as changes occur. When nothing changes, the query waits.
What makes a query run as a continuous query?  A continuous query must be executed using the Query.Statement.executeWithCallback() function. Snapshot queries can also use this function. However, when you set the argument IsContinuous to true, the query runs as a continuous query. See Overview of Continuous Queries for more details.
Executing a Continuous Query
You use the Query.Statement.executeWithCallback() function with the IsContinuous argument set to true to execute a continuous query statement. See Using Data from a Callback Rule Function. and See Two Main Types of Queries for more information.
Ending a Continuous Query
A continuous query only ends when one of the following occurs:
Understanding Query Windows
Continuous queries use windows to contain the entities that are added or changed.A window is a boundary for analyzing data streams. It is a container in which events and concepts are held and processed by the query. Entities enter and leave the window as determined by the window type and how it is configured.
One query can contain multiple windows, and the contents of these windows can be analyzed and compared.
Windows can be divided into two basic types, explicit and implicit.
Explicit windows (sliding, tumbling, and time windows) define the window boundary, that is, a condition that limits the lifecycle of the entities in the window.
Ensure that the lifetime of an entity in an explicit window is shorter than the lifetime of the entity itself. Otherwise errors occur.
With implicit windows, the lifetime of the entities themselves control the lifecycle of the entities in the implicit window. Implicit windows process changes, additions, and deletions affecting the specified entities until the query ends.
Types of Windows
See Working With Sliding, Tumbling, and Time Windows for content that applies to all these types of explicit windows.
Implicit Window  A group by clause in the select statement determines that the query is a continuous query using an implicit window. See Working With Implicit Windows.
Sliding Window  Has a specified queue size, into which entities flow. When the queue is full and a new entity arrives, the oldest entity in the queue is removed from the window (FIFO). See Sliding Window Examples
Tumbling Window  Has a specified queue size, specified as a certain number of entities, and empties each time the maximum size is exceeded. Emptying the window completes one cycle. The lifetime of an entity in the window, therefore, is one cycle. See Tumbling Window Examples
Time Window  Specifies a time period during which entities remain in the window. See Time Window Examples.