Code Examples
A repository of 155 code examples for BeepBeep
OpenClose.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package ltl;
19 
20 import static ca.uqac.lif.cep.Connector.BOTTOM;
21 import static ca.uqac.lif.cep.Connector.INPUT;
22 import static ca.uqac.lif.cep.Connector.OUTPUT;
23 import static ca.uqac.lif.cep.Connector.TOP;
24 
25 import ca.uqac.lif.cep.Connector;
26 import ca.uqac.lif.cep.Pushable;
27 import ca.uqac.lif.cep.functions.ApplyFunction;
28 import ca.uqac.lif.cep.functions.ApplyFunctionPartial;
29 import ca.uqac.lif.cep.functions.Constant;
30 import ca.uqac.lif.cep.functions.FunctionTree;
31 import ca.uqac.lif.cep.functions.StreamVariable;
32 import ca.uqac.lif.cep.io.Print;
33 import ca.uqac.lif.cep.ltl.Eventually;
34 import ca.uqac.lif.cep.tmf.Filter;
35 import ca.uqac.lif.cep.tmf.Fork;
36 import ca.uqac.lif.cep.util.Booleans;
37 import ca.uqac.lif.cep.util.Equals;
38 
39 /**
40  * Using an LTL expression to filter events in an input stream.
41  * It is illustrated as follows:
42  * <p>
43  * <img src="./doc-files/ltl/OpenClose.png" alt="Processor graph">
44  * <p>
45  * @author Sylvain HallĂ©
46  *
47  */
48 public class OpenClose
49 {
50 
51  public static void main(String[] args)
52  {
53  ///
54  Fork f1 = new Fork(2);
55  ApplyFunctionPartial imp = new ApplyFunctionPartial(
56  new FunctionTree(Booleans.implies,
57  new FunctionTree(Equals.instance,
58  StreamVariable.X, new Constant("open")),
59  StreamVariable.Y));
60  ApplyFunction close = new ApplyFunction(
61  new FunctionTree(Equals.instance,
62  StreamVariable.X, new Constant("close")));
63  Eventually e = new Eventually();
64  Fork f2 = new Fork(2);
65  Connector.connect(f1, BOTTOM, f2, INPUT);
66  Connector.connect(f2, TOP, imp, TOP);
67  Connector.connect(f2, BOTTOM, close, INPUT);
68  Connector.connect(close, e);
69  Connector.connect(e, OUTPUT, imp, BOTTOM);
70  Filter filter = new Filter();
71  Connector.connect(f1, TOP, filter, TOP);
72  Connector.connect(imp, OUTPUT, filter, BOTTOM);
73  Print print = new Print();
74  print.setPrefix("Output: ").setSeparator("\n");
75  Connector.connect(filter, print);
76  Pushable p = f1.getPushableInput();
77  System.out.println("Pushing nop");
78  p.push("nop");
79  System.out.println("Pushing open");
80  p.push("open");
81  System.out.println("Pushing read");
82  p.push("read");
83  System.out.println("Pushing close");
84  p.push("close");
85  ///
86  }
87 
88 }
Using an LTL expression to filter events in an input stream.
Definition: OpenClose.java:48