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