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

COVERAGE SUMMARY FOR SOURCE FILE [SingleStreamReceiver.java]

nameclass, %method, %block, %line, %
SingleStreamReceiver.java100% (1/1)80%  (4/5)84%  (57/68)81%  (21/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SingleStreamReceiver100% (1/1)80%  (4/5)84%  (57/68)81%  (21/26)
getWindow (): SchedulerQueue 0%   (0/1)0%   (0/2)0%   (0/1)
run (): void 100% (1/1)70%  (21/30)71%  (10/14)
SingleStreamReceiver (SingleStream, StreamProcessor, ThreadPoolExecutor): void 100% (1/1)100% (21/21)100% (7/7)
getStreamId (): String 100% (1/1)100% (4/4)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;
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.StreamProcessor;
24import org.wso2.siddhi.query.api.stream.SingleStream;
25 
26import java.util.concurrent.ThreadPoolExecutor;
27 
28public class SingleStreamReceiver implements Runnable, StreamReceiver,
29                                             StreamElement {
30    private SingleStream inputStream;
31    private ThreadPoolExecutor threadPoolExecutor;
32    private SchedulerQueue<StreamEvent> inputQueue = new SchedulerQueue<StreamEvent>();
33    private StreamProcessor firstStreamProcessor;
34 
35    public SingleStreamReceiver(SingleStream inputStream,
36                                StreamProcessor firstStreamProcessor,
37                                ThreadPoolExecutor threadPoolExecutor) {
38        this.inputStream = inputStream;
39        this.firstStreamProcessor = firstStreamProcessor;
40        this.firstStreamProcessor.setPrevious(this);
41        this.threadPoolExecutor = threadPoolExecutor;
42    }
43 
44    @Override
45    public void receive(StreamEvent streamEvent) throws InterruptedException {
46//        //System.out.println(event);
47        if (!inputQueue.put(streamEvent)) {
48            threadPoolExecutor.submit(this);
49        }
50    }
51 
52    @Override
53    public void run() {
54        int eventCounter = 0;
55        while (true) {
56            StreamEvent streamEvent = inputQueue.poll();
57            if (streamEvent == null) {
58                break;
59            } else if (eventCounter > 10) {
60                threadPoolExecutor.submit(this);
61                break;
62            }
63            eventCounter++;
64            try {
65                firstStreamProcessor.process(streamEvent);
66            } catch (Throwable e) {
67                e.printStackTrace();
68            }
69 
70        }
71    }
72 
73    public String getStreamId() {
74        return inputStream.getStreamId();
75    }
76 
77    @Override
78    public SchedulerQueue<StreamEvent> getWindow() {
79        return null;
80    }
81 
82}

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