Code Examples
A repository of 155 code examples for BeepBeep
BinaryPush.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.Adder;
21 import ca.uqac.lif.cep.Connector;
22 import ca.uqac.lif.cep.Pushable;
23 import ca.uqac.lif.cep.io.Print;
24 
25 /**
26  * Push events into a processor of input arity 2.
27  * The chain of processors in this example can be represented
28  * graphically as:
29  * <p>
30  * <img src="./doc-files/basic/BinaryPush.png" alt="Processor graph">
31  * <p>
32  * The expected output of this program is:
33  * <pre>
34  * 0,2,4,6,8,10,12,14,
35  * </pre>
36  * @see PipingUnaryPush
37  * @author Sylvain HallĂ©
38  * @difficulty Easy
39  */
40 public class BinaryPush
41 {
42  public static void main(String[] args)
43  {
44  /// We create an instance of the adder processor
45  Adder add = new Adder();
46 
47  // We then create a Print processor, which prints its input
48  // to the console
49  Print print = new Print().setSeparator("\n");
50 
51  // We connect the output of add to the input of print
52  Connector.connect(add, print);
53 
54  // We now get a hold of the adder's pushables. Since add is of input
55  // arity 2, it has two such pushables, numbered 0 and 1. Notice how
56  // we use a different version of getPushableInput, which takes an
57  // integer as an argument
58  Pushable p0 = add.getPushableInput(0);
59  Pushable p1 = add.getPushableInput(1);
60  ///
61 
62  //* Let us push an event into p0. Nothing is printed, as the Adder
63  // requires one event on each of its input pipes to do something.
64  p0.push(3);
65  System.out.println("This is the first printed line");
66 
67  // Let us push an event into p1. Since an event was ready to be
68  // consumed at p0, adder can proceed with the addition and push its
69  // result to print.
70  p1.push(1);
71 
72  // We now push two events in a row to p1. As above, nothing is printed
73  p1.push(4);
74  p1.push(1);
75  System.out.println("This is the third printed line");
76 
77  // We push two events to p0. Since events in p1 are ready to be
78  // consumed, each push on p0 triggers the evaluation of a new addition
79  p0.push(5);
80  p0.push(9);
81  //*
82  }
83 }
static void main(String[] args)
Definition: BinaryPush.java:42
Push events into a processor of input arity 2.
Definition: BinaryPush.java:40