Code Examples
A repository of 155 code examples for BeepBeep
PipingUnaryPush.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2019 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.Pushable;
23 import ca.uqac.lif.cep.UtilityMethods;
24 import ca.uqac.lif.cep.io.Print;
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/PipingUnaryPush.png" alt="Processor graph">
32  * <p>
33  * This example works like {@link PipingBinary}, except that it operates in
34  * <em>push</em> mode instead of <em>pull</em> mode.
35  * <p>
36  * The expected output of this program is:
37  * <pre>
38  * 0,2,4,6,8,10,12,14,
39  * </pre>
40  * @see PipingBinary
41  * @author Sylvain HallĂ©
42  * @difficulty Easy
43  */
44 public class PipingUnaryPush
45 {
46  public static void main (String[] args)
47  {
48  /// Create an instance of the Doubler processor.
49  Doubler doubler = new Doubler();
50 
51  /* Create a processor that simply prints to the console every event
52  * it receives */
53  Print print = new Print();
54 
55  /* We now want to connect the output of doubler to the input of print.
56  * This connection is done by using static method connect() of the
57  * Connector object. */
58  Connector.connect(doubler, print);
59 
60  /* Let us now push events to the doubler. */
61  Pushable p = doubler.getPushableInput();
62  for (int i = 0; i < 8; i++)
63  {
64  p.push(i);
65  // Sleep a little in between so you have time to read
66  UtilityMethods.pause(1000);
67  }
68  ///
69  }
70 }
Pipe processors together using the Connector object.
static void main(String[] args)