com.espertech.esper.plugin
Interface PlugInAggregationMultiFunctionHandler


public interface PlugInAggregationMultiFunctionHandler

Part of the aggregation multi-function extension API, this class represents one of more aggregation function expression instances. This class is responsible for providing a state reader (called accessor) for returning value from aggregation state, and for providing return type information of the accessor, and for providing state factory information.

Note the information returned by getReturnType() must match the value objects returned by getAccessor().

For example, assuming you have an EPL statement such as select search(), query() from MyEvent then you would likely use one handler class and two handler objects (one for search and one for query).


Method Summary
 AggregationAccessor getAccessor()
          Returns the read function (an 'accessor').
 AggregationAgent getAggregationAgent(PlugInAggregationMultiFunctionAgentContext agentContext)
           
 AggregationStateKey getAggregationStateUniqueKey()
          Return a state-key object that determines how the engine shares aggregation state between multiple aggregation functions that may appear in the same EPL statement.
 EPType getReturnType()
          Provide return type.
 PlugInAggregationMultiFunctionStateFactory getStateFactory()
          Return the state factory for the sharable aggregation function state.
 

Method Detail

getAccessor

AggregationAccessor getAccessor()
Returns the read function (an 'accessor').

Typically your application creates one accessor class for each aggregation function name. So if you have two aggregation functions such as "query" and "search" you would have two accessor classes, one for "query" and one for "search".

Each aggregation function as it occurs in an EPL statement obtains its own accessor. Your application can return the same accessor object for all aggregation functions, or different accessor objects for each aggregation function.

The objects returned by your accessor must match the return type declared through getReturnType().

Returns:
accessor

getReturnType

EPType getReturnType()
Provide return type.

The accessor return values must match the return type declared herein.

Use EPTypeHelper.singleValue(Class) (Class)} to indicate that the accessor returns a single value. The accessor should return the single value upon invocation of AggregationAccessor.getValue(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor should return a null value for all other accessor methods.

Use EPTypeHelper.collectionOfEvents(com.espertech.esper.client.EventType) to indicate that the accessor returns a collection of events. The accessor should return a value in AggregationAccessor.getEnumerableEvents(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor can also return an array of underlying event objects in AggregationAccessor.getValue(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor should return a null value for all other accessor methods.

Use EPTypeHelper.singleEvent(com.espertech.esper.client.EventType) to indicate that the accessor returns a single event. The accessor should return a value in AggregationAccessor.getEnumerableEvent(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor can also return the underlying event object in AggregationAccessor.getValue(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor should return a null value for all other accessor methods.

Use EPTypeHelper.collectionOfSingleValue(Class) to indicate that the accessor returns a collection of single values (scalar, object etc.). The accessor should return a java.util.Collection in AggregationAccessor.getValue(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor should return a null value for all other accessor methods.

Use EPTypeHelper.array(Class) to indicate that the accessor returns an array of single values. The accessor should return an array in AggregationAccessor.getValue(com.espertech.esper.epl.agg.access.AggregationState, com.espertech.esper.client.EventBean[], boolean, com.espertech.esper.epl.expression.core.ExprEvaluatorContext). The accessor should return a null value for all other accessor methods.

Returns:
expression result type

getAggregationStateUniqueKey

AggregationStateKey getAggregationStateUniqueKey()
Return a state-key object that determines how the engine shares aggregation state between multiple aggregation functions that may appear in the same EPL statement.

The engine applies equals-semantics to determine state sharing. If two AggregationStateKey instances are equal (implement hashCode and equals) then the engine shares a single aggregation state instance for the two aggregation function expressions.

If your aggregation function never needs shared state simple return new AggregationStateKey(){}.

If your aggregation function always shares state simple declare private static final AggregationStateKey MY_KEY = new AggregationStateKey() {}; and return MY_KEY; (if using multiple handlers declare the key on the factory level).

Returns:
state key

getStateFactory

PlugInAggregationMultiFunctionStateFactory getStateFactory()
Return the state factory for the sharable aggregation function state.

The engine only obtains a state factory once for all shared aggregation state.

Returns:
state factory

getAggregationAgent

AggregationAgent getAggregationAgent(PlugInAggregationMultiFunctionAgentContext agentContext)

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com