EMMA Coverage Report (generated Tue Jul 10 07:50:22 IST 2012)
[all classes][org.wso2.siddhi.core.stream.recevier.sequence]

COVERAGE SUMMARY FOR SOURCE FILE [SequenceSingleStreamReceiver.java]

nameclass, %method, %block, %line, %
SequenceSingleStreamReceiver.java100% (1/1)75%  (6/8)94%  (111/118)94%  (31/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SequenceSingleStreamReceiver100% (1/1)75%  (6/8)94%  (111/118)94%  (31/33)
getStreamId (): String 0%   (0/1)0%   (0/5)0%   (0/1)
getWindow (): SchedulerQueue 0%   (0/1)0%   (0/2)0%   (0/1)
SequenceSingleStreamReceiver (SequenceState, StreamProcessor, int): void 100% (1/1)100% (34/34)100% (10/10)
addToNextEvents (StateEvent): void 100% (1/1)100% (6/6)100% (2/2)
init (): void 100% (1/1)100% (13/13)100% (3/3)
moveNextEventsToCurrentEvents (): void 100% (1/1)100% (10/10)100% (3/3)
receive (StreamEvent): void 100% (1/1)100% (16/16)100% (6/6)
sendForProcess (StreamEvent): void 100% (1/1)100% (32/32)100% (7/7)

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*/
18package org.wso2.siddhi.core.stream.recevier.sequence;
19 
20import org.wso2.siddhi.core.event.StreamEvent;
21import org.wso2.siddhi.core.event.in.StateEvent;
22import org.wso2.siddhi.core.util.SchedulerQueue;
23import org.wso2.siddhi.core.statemachine.sequence.SequenceState;
24import org.wso2.siddhi.core.stream.StreamElement;
25import org.wso2.siddhi.core.stream.StreamProcessor;
26import org.wso2.siddhi.core.stream.recevier.StreamReceiver;
27 
28import java.util.LinkedList;
29import java.util.List;
30 
31public class SequenceSingleStreamReceiver implements StreamReceiver, StreamElement {
32    protected int complexEventSize;
33    protected SequenceState state;
34    protected SequenceState nextState;
35    protected StreamProcessor firstSimpleStreamProcessor;
36    protected List<StateEvent> currentEvents = new LinkedList<StateEvent>();
37    protected List<StateEvent> nextEvents = new LinkedList<StateEvent>();
38    //    private final boolean first;
39    protected final int currentState;
40 
41 
42    public SequenceSingleStreamReceiver(SequenceState state,
43                                        StreamProcessor firstSimpleStreamProcessor,
44                                        int complexEventSize) {
45        this.state = state;
46        this.nextState = state.getNextState();
47        this.currentState = state.getStateNumber();
48        this.complexEventSize = complexEventSize;
49        this.firstSimpleStreamProcessor = firstSimpleStreamProcessor;
50        this.firstSimpleStreamProcessor.setPrevious(this);
51//        init(state, complexEventSize);
52    }
53 
54    public void init() {
55        if (state.isFirst()) {
56            //first event
57            addToNextEvents(new StateEvent(new StreamEvent[complexEventSize]));
58        }
59    }
60 
61    @Override
62    public void receive(StreamEvent streamEvent) {
63        if (streamEvent instanceof SequenceResetEvent) {
64            //System.out.println("Before Sequence Reset || currentEvents=" +currentEvents.size()+" nextEvents="+nextEvents.size());
65            currentEvents.clear();
66            nextEvents.clear();
67            //System.out.println("After  Sequence Reset || currentEvents=" +currentEvents.size()+" nextEvents="+nextEvents.size());
68        }else {
69            sendForProcess((StreamEvent) streamEvent);
70        }
71        init();
72 
73//        currentEvents.clear();
74//        }
75    }
76 
77    protected void sendForProcess(StreamEvent event) {
78        //System.out.println("sr state=" +currentState+" event="+ event+" ||currentEvents="+currentEvents);
79        for (StateEvent currentEvent : currentEvents) {
80            currentEvent.setStreamEvent(currentState, event);
81            firstSimpleStreamProcessor.process(currentEvent);
82            if ( currentEvent.getEventState()<currentState) {
83                currentEvent.setStreamEvent(currentState, null);
84            }
85        }
86    }
87 
88    public String getStreamId() {
89        return state.getSingleStream().getStreamId();
90    }
91 
92    @Override
93    public SchedulerQueue<StreamEvent> getWindow() {
94        return null;
95    }
96 
97    public synchronized void addToNextEvents(StateEvent stateEvent) {
98//        //System.out.println("add to next ss");
99        nextEvents.add(stateEvent);
100    }
101 
102    public synchronized void moveNextEventsToCurrentEvents() {
103        //todo need to check which is faster
104        // 1
105//        currentEvents.clear();
106//        currentEvents.addAll(nextEvents);
107//        nextEvents.clear();
108 
109//        // 2
110        currentEvents = nextEvents;
111        nextEvents = new LinkedList<StateEvent>();
112    }
113 
114}

[all classes][org.wso2.siddhi.core.stream.recevier.sequence]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov