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.query.api.stream; |
19 | |
20 | import org.wso2.siddhi.query.api.query.QueryEventStream; |
21 | import org.wso2.siddhi.query.api.condition.Condition; |
22 | import org.wso2.siddhi.query.api.definition.StreamDefinition; |
23 | import org.wso2.siddhi.query.api.stream.handler.Handler; |
24 | import org.wso2.siddhi.query.api.stream.pattern.element.PatternElement; |
25 | import org.wso2.siddhi.query.api.stream.sequence.element.SequenceElement; |
26 | |
27 | import java.util.ArrayList; |
28 | import java.util.List; |
29 | import java.util.Map; |
30 | |
31 | public class SingleStream implements Stream, SequenceElement, PatternElement { |
32 | |
33 | protected String streamId; |
34 | protected StreamDefinition streamDefinition; |
35 | protected String streamReferenceId; |
36 | protected List<Handler> handlerList = new ArrayList<Handler>(); |
37 | protected boolean isCounterStream = false; |
38 | |
39 | protected SingleStream(String streamId) { |
40 | this(streamId, streamId); |
41 | } |
42 | |
43 | public SingleStream(String streamReferenceId, String streamId) { |
44 | this.streamId = streamId; |
45 | this.streamReferenceId = streamReferenceId; |
46 | } |
47 | |
48 | public SingleStream handler(Handler.Type type, String name, Object... parameters) { |
49 | handlerList.add(new Handler(name, type, parameters)); |
50 | return this; |
51 | } |
52 | |
53 | public SingleStream addHandler(Handler handler) { |
54 | handlerList.add(handler); |
55 | return this; |
56 | } |
57 | |
58 | public String getStreamId() { |
59 | return streamId; |
60 | } |
61 | |
62 | public String getStreamReferenceId() { |
63 | return streamReferenceId; |
64 | } |
65 | |
66 | public SingleStream setStreamReferenceId(String streamReferenceId) { |
67 | this.streamReferenceId = streamReferenceId; |
68 | return this; |
69 | } |
70 | |
71 | public List<Handler> getHandlerList() { |
72 | return handlerList; |
73 | } |
74 | |
75 | public SingleStream handler(Condition filterCondition) { |
76 | handlerList.add(new Handler(null, Handler.Type.FILTER, new Object[]{filterCondition})); |
77 | return this; |
78 | } |
79 | |
80 | @Override |
81 | public List<String> getStreamIds() { |
82 | List<String> list = new ArrayList<String>(); |
83 | list.add(streamId); |
84 | return list; |
85 | } |
86 | |
87 | public void setCounterStream(boolean counterStream) { |
88 | isCounterStream = counterStream; |
89 | } |
90 | |
91 | @Override |
92 | public List<QueryEventStream> constructQueryEventStreamList( |
93 | Map<String, StreamDefinition> streamDefinitionMap, |
94 | List<QueryEventStream> queryEventStreams) { |
95 | streamDefinition = streamDefinitionMap.get(streamId); |
96 | QueryEventStream queryEventStream = new QueryEventStream(streamId, streamReferenceId, streamDefinition); |
97 | queryEventStream.setCounterStream(isCounterStream); |
98 | queryEventStreams.add(queryEventStream); |
99 | return queryEventStreams; |
100 | } |
101 | |
102 | |
103 | } |