Code Examples
A repository of 155 code examples for BeepBeep
UpdateTableStreamExample.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 plots;
19 
20 import ca.uqac.lif.cep.Connector;
21 import static ca.uqac.lif.cep.Connector.TOP;
22 import static ca.uqac.lif.cep.Connector.BOTTOM;
23 import static ca.uqac.lif.cep.Connector.OUTPUT;
24 import ca.uqac.lif.cep.io.Print;
25 import ca.uqac.lif.cep.mtnp.UpdateTable;
26 import ca.uqac.lif.cep.mtnp.UpdateTableStream;
27 import ca.uqac.lif.cep.tmf.Pump;
28 import ca.uqac.lif.cep.tmf.QueueSource;
29 
30 /**
31  * Update a table from two streams of numbers.
32  * This example generates dummy (x,y) pairs of numbers, accumulates them
33  * into a table, and prints the table made from these numbers.
34  * @author Sylvain HallĂ©
35  * @difficulty Easy
36  */
38 {
39 
40  public static void main(String[] args) throws InterruptedException
41  {
42  /// We create two streams of numbers
43  QueueSource src1 = new QueueSource().setEvents(1, 2, 3, 4, 5);
44  QueueSource src2 = new QueueSource().setEvents(2, 3, 5, 7, 4);
45 
46  /* These x-stream and y-stream are then pushed into an
47  * {@link UpdateTableStream} processor. We instantiate this processor,
48  * telling it to create an empty {@link Table} object with two
49  * columns, called "x" and "y". */
50  UpdateTable table = new UpdateTableStream("x", "y");
51 
52  /* This creates a processor with two input streams, one for the "x"
53  * values, and the other for the "y" values. Each pair of values from
54  * the x and y streams is used to append a new line to the (initially
55  * empty) table. We connect the two
56  * outputs of the random processor to these two inputs. */
57  Connector.connect(src1, OUTPUT, table, TOP);
58  Connector.connect(src2, OUTPUT, table, BOTTOM);
59 
60  /* We print the contents of the resulting table. */
61  Pump pump = new Pump();
62  Print print = new Print().setSeparator("\n");
63  Connector.connect(table, pump, print);
64 
65  /* Ready to start the pump! */
66  pump.turn(4);
67  ///
68  }
69 }
Update a table from two streams of numbers.