Code Examples
A repository of 155 code examples for BeepBeep
PipingUnary.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2016 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 basic;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Doubler;
22 import ca.uqac.lif.cep.Pullable;
23 import ca.uqac.lif.cep.UtilityMethods;
24 import ca.uqac.lif.cep.tmf.QueueSource;
25 
26 /**
27  * Pipe processors together using the {@link ca.uqac.lif.cep.Connector Connector}
28  * object. The chain of processors in this example can be represented
29  * graphically as:
30  * <p>
31  * <img src="./doc-files/basic/PipingUnary.png" alt="Processor graph">
32  * @see PipingBinary
33  * @author Sylvain HallĂ©
34  * @difficulty Easy
35  */
36 public class PipingUnary
37 {
38  public static void main (String[] args)
39  {
40  /// Create a source of arbitrary numbers
41  QueueSource source = new QueueSource();
42  source.setEvents(1, 2, 3, 4, 5, 6);
43 
44  /* Create an instance of the Doubler processor (which is defined just
45  * below in this file. */
46  Doubler doubler = new Doubler();
47 
48  /* We now want to connect the output of source to the input of doubler.
49  * This connection is done by using static method connect() of the
50  * Connector object. Here, source has only one output stream, and
51  * doubler has only one input stream. Therefore, we can simply call
52  * connect() by giving the "upstream" processor first, and the
53  * "downstream" processor second. The Connector will know that it needs
54  * to connect the (only) output of source to the (only) input of
55  * doubler. */
56  Connector.connect(source, doubler);
57 
58  /* Let us now print what we receive by pulling on the output of
59  * doubler. */
60  Pullable p = doubler.getPullableOutput();
61  for (int i = 0; i < 8; i++)
62  {
63  int x = (Integer) p.pull();
64  System.out.println("The event is: " + x);
65  // Sleep a little so you have time to read
66  UtilityMethods.pause(1000);
67  }
68  ///
69  }
70 }
static void main(String[] args)
Pipe processors together using the Connector object.