root/src/java/com/omniti/reconnoiter/esper/DeriveViewFactory.java

Revision c75a2104258a9079bb6ef2dbe68c66e7102bbf16, 2.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 8 years ago)

step 2. .noit:derive and .noit:counter, refs #210

  • Property mode set to 100644
Line 
1 package com.omniti.reconnoiter.esper;
2
3 import java.util.List;
4 import com.espertech.esper.client.EventType;
5 import com.espertech.esper.epl.expression.ExprNode;
6 import com.espertech.esper.view.ViewParameterException;
7 import com.espertech.esper.view.ViewFactorySupport;
8 import com.espertech.esper.view.ViewFactoryContext;
9 import com.espertech.esper.view.ViewFactory;
10 import com.espertech.esper.view.View;
11 import com.espertech.esper.core.StatementContext;
12
13 public class DeriveViewFactory extends ViewFactorySupport {
14     private ViewFactoryContext viewFactoryContext;
15     private List<ExprNode> viewParameters;
16     private ExprNode timestampExpression;
17     private ExprNode valueExpression;
18
19     public void setViewParameters(ViewFactoryContext viewFactoryContext,
20                                   List<ExprNode> viewParameters) throws ViewParameterException {
21         this.viewFactoryContext = viewFactoryContext;
22         if (viewParameters.size() != 2) {
23             throw new ViewParameterException(
24                 "View requires a two parameters: x, y");
25         }
26         this.viewParameters = viewParameters;
27     }
28
29     public void attach(EventType parentEventType,
30                 StatementContext statementContext,
31                 ViewFactory optionalParentFactory,
32                 List<ViewFactory> parentViewFactories) throws ViewParameterException {
33                
34         ExprNode[] validatedNodes = ViewFactorySupport.validate("DeriveView",
35               parentEventType, statementContext, viewParameters, false);
36    
37         timestampExpression = validatedNodes[0];
38         valueExpression = validatedNodes[1];
39    
40         if ((timestampExpression.getType() != long.class) &&
41             (timestampExpression.getType() != Long.class)) {
42             throw new ViewParameterException(
43                 "View requires long-typed timestamp values in parameter 1");
44         }
45         if ((valueExpression.getType() != double.class) &&
46             (valueExpression.getType() != Double.class) &&
47             (valueExpression.getType() != long.class) &&
48             (valueExpression.getType() != Long.class)) {
49             throw new ViewParameterException(
50                 "View requires long-typed or double-typed values for in parameter 2");
51         }
52     }
53     public View makeView(StatementContext statementContext) {
54         return new DeriveView(statementContext, timestampExpression, valueExpression);
55     }
56
57     public EventType getEventType() {
58         return DeriveView.getEventType(viewFactoryContext.getEventAdapterService());
59     }
60 }
Note: See TracBrowser for help on using the browser.