1 | /* |
2 | * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. |
3 | * |
4 | * WSO2 Inc. licenses this file to you under the Apache License, |
5 | * Version 2.0 (the "License"); you may not use this file except |
6 | * in compliance with the License. |
7 | * You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, |
12 | * software distributed under the License is distributed on an |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | * KIND, either express or implied. See the License for the |
15 | * specific language governing permissions and limitations |
16 | * under the License. |
17 | */ |
18 | package org.wso2.siddhi.core.stream.recevier.sequence; |
19 | |
20 | import org.wso2.siddhi.core.event.Event; |
21 | import org.wso2.siddhi.core.event.ListEvent; |
22 | import org.wso2.siddhi.core.event.StreamEvent; |
23 | import org.wso2.siddhi.core.event.in.InListEvent; |
24 | import org.wso2.siddhi.core.event.in.StateEvent; |
25 | import org.wso2.siddhi.core.statemachine.sequence.CountSequenceState; |
26 | import org.wso2.siddhi.core.stream.StreamProcessor; |
27 | |
28 | public class CountSequenceSingleStreamReceiver extends SequenceSingleStreamReceiver { |
29 | |
30 | private int min = -1; |
31 | private int max = -1; |
32 | private boolean passed; |
33 | |
34 | public CountSequenceSingleStreamReceiver(CountSequenceState state, |
35 | StreamProcessor firstSimpleStreamProcessor, |
36 | int complexEventSize) { |
37 | super(state, firstSimpleStreamProcessor, complexEventSize); |
38 | this.min = state.getMin(); |
39 | this.max = state.getMax(); |
40 | |
41 | } |
42 | |
43 | // @Override |
44 | // public void receive(Event event) { |
45 | // if (checkReset(event)) { |
46 | // return; |
47 | // } |
48 | // //System.out.println("cr state=" + currentState + " event=" + event + " ||currentEvents=" + currentEvents); |
49 | // for (StateEvent currentEvent : currentEvents) { |
50 | // |
51 | // if (currentEvent.getEventState() <= (state.getStateNumber())) { |
52 | // SingleEventList singleEventList = (SingleEventList) currentEvent.getStreamEvent(currentState); |
53 | // if (singleEventList == null) { |
54 | // singleEventList = new SingleEventList(max); |
55 | // currentEvent.setStreamEvent(currentState, singleEventList); |
56 | // } |
57 | // setPassed(false); |
58 | // singleEventList.addEvent(((Event) event)); |
59 | // firstSimpleStreamProcessor.process(currentEvent); |
60 | // |
61 | // if (!isPassed()) { |
62 | // singleEventList.removeLast(); //to stop aggregation of not passed events |
63 | //// nextEvents.add(currentEvent); //only to add to itself |
64 | // } |
65 | // init(); |
66 | // |
67 | // } |
68 | // } |
69 | //// currentEvents.clear(); |
70 | //// } |
71 | // } |
72 | |
73 | protected void sendForProcess(StreamEvent streamEvent) { |
74 | //System.out.println("cr state=" + currentState + " event=" + streamEvent + " ||currentEvents=" + currentEvents); |
75 | for (StateEvent currentEvent : currentEvents) { |
76 | |
77 | if (currentEvent.getEventState() <= (state.getStateNumber())) { |
78 | ListEvent listEvent = (ListEvent) currentEvent.getStreamEvent(currentState); |
79 | if (listEvent == null) { |
80 | listEvent = new InListEvent(max); |
81 | currentEvent.setStreamEvent(currentState, listEvent); |
82 | } |
83 | setPassed(false); |
84 | if (!listEvent.addEvent(((Event) streamEvent))) { |
85 | continue; |
86 | } |
87 | firstSimpleStreamProcessor.process(currentEvent); |
88 | |
89 | if (!isPassed()) { |
90 | listEvent.removeLast(); //to stop aggregation of not passed events |
91 | // nextEvents.add(currentEvent); //only to add to itself |
92 | } |
93 | // init(); |
94 | } |
95 | } |
96 | } |
97 | |
98 | // protected InComplexEvent createFirstEvent(int complexEventSize) { |
99 | // return new InComplexEvent(new SingleEventBundle[complexEventSize]); |
100 | // } |
101 | |
102 | public synchronized void addToNextEvents(StateEvent stateEvent) { |
103 | // //System.out.println("in"); |
104 | if (min == 0) { |
105 | state.getSequenceStreamPacker().process(stateEvent.cloneEvent(currentState)); |
106 | // |
107 | // if (stateEvent.getEventState() < currentState) { |
108 | // if (nextState != null) { |
109 | // if (nextState instanceof OrSequenceState) { |
110 | // ((OrSequenceState) nextState).getPartnerState().getSequenceSingleStreamReceiver().addToNextEvents(stateEvent); |
111 | // } |
112 | // nextState.getSequenceSingleStreamReceiver().addToNextEvents(stateEvent); |
113 | //// nextEvents.add(stateEvent);//to keep the reference of the next events |
114 | // } |
115 | // } |
116 | } else { |
117 | nextEvents.add(stateEvent); |
118 | } |
119 | } |
120 | |
121 | public synchronized void setPassed(boolean passed) { |
122 | this.passed = passed; |
123 | } |
124 | |
125 | public synchronized boolean isPassed() { |
126 | return passed; |
127 | } |
128 | |
129 | public void addOnlyToNextEvents(StateEvent stateEvent) { |
130 | nextEvents.add(stateEvent); |
131 | } |
132 | } |