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

COVERAGE SUMMARY FOR SOURCE FILE [PatternStreamReceiver.java]

nameclass, %method, %block, %line, %
PatternStreamReceiver.java100% (1/1)80%  (4/5)88%  (83/94)83%  (24/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PatternStreamReceiver100% (1/1)80%  (4/5)88%  (83/94)83%  (24/29)
getWindow (): SchedulerQueue 0%   (0/1)0%   (0/2)0%   (0/1)
run (): void 100% (1/1)84%  (48/57)76%  (13/17)
PatternStreamReceiver (String, List, ThreadPoolExecutor): void 100% (1/1)100% (21/21)100% (7/7)
getStreamId (): String 100% (1/1)100% (3/3)100% (1/1)
receive (StreamEvent): void 100% (1/1)100% (11/11)100% (3/3)

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.pattern;
19 
20import org.wso2.siddhi.core.event.StreamEvent;
21import org.wso2.siddhi.core.util.SchedulerQueue;
22import org.wso2.siddhi.core.stream.StreamElement;
23import org.wso2.siddhi.core.stream.recevier.StreamReceiver;
24 
25import java.util.List;
26import java.util.concurrent.ThreadPoolExecutor;
27 
28public class PatternStreamReceiver implements StreamReceiver, StreamElement, Runnable {
29 
30    //  private List<SingleStream> inputStreamList;
31    private String streamId;
32    private ThreadPoolExecutor threadPoolExecutor;
33    private SchedulerQueue<StreamEvent> inputQueue = new SchedulerQueue<StreamEvent>();
34    private List<PatternSingleStreamReceiver> patternSingleStreamReceiverList;
35    private int patternSingleStreamReceiverListSize;
36 
37    public PatternStreamReceiver(String streamId,
38                                 List<PatternSingleStreamReceiver> patternSingleStreamReceiverList,
39                                 ThreadPoolExecutor threadPoolExecutor) {
40        this.streamId = streamId;
41        this.patternSingleStreamReceiverList = patternSingleStreamReceiverList;
42        this.threadPoolExecutor = threadPoolExecutor;
43        this.patternSingleStreamReceiverListSize = patternSingleStreamReceiverList.size();
44    }
45 
46    @Override
47    public void receive(StreamEvent streamEvent) throws InterruptedException {
48//        //System.out.println(event);
49        if (!inputQueue.put(streamEvent)) {
50            threadPoolExecutor.submit(this);
51        }
52    }
53 
54    @Override
55    public void run() {
56        int eventCounter = 0;
57        while (true) {
58            StreamEvent streamEvent = inputQueue.poll();
59            if (streamEvent == null) {
60                break;
61            } else if (eventCounter > 10) {
62                threadPoolExecutor.submit(this);
63                break;
64            }
65            eventCounter++;
66            try {
67                //in reverse order to execute the later states first to overcome to dependencies of count states
68                for (int i = patternSingleStreamReceiverListSize - 1; i >= 0; i--) {
69                    patternSingleStreamReceiverList.get(i).moveNextEventsToCurrentEvents();
70                }
71                for (int i = patternSingleStreamReceiverListSize - 1; i >= 0; i--) {
72                    patternSingleStreamReceiverList.get(i).receive(streamEvent);
73                }
74            } catch (Throwable e) {
75                e.printStackTrace();
76            }
77 
78        }
79    }
80 
81    public String getStreamId() {
82        return streamId;
83    }
84 
85    @Override
86    public SchedulerQueue<StreamEvent> getWindow() {
87        return null;
88    }
89 
90 
91}

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