Code Examples
A repository of 155 code examples for BeepBeep
DuplicateContext.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 basic;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Pushable;
22 import ca.uqac.lif.cep.functions.ApplyFunction;
23 import ca.uqac.lif.cep.functions.ContextVariable;
24 import ca.uqac.lif.cep.functions.FunctionTree;
25 import ca.uqac.lif.cep.functions.StreamVariable;
26 import ca.uqac.lif.cep.io.Print;
27 import ca.uqac.lif.cep.util.Numbers;
28 
29 /**
30  * Duplicating processors and observing what happens to their
31  * Context object.
32  *
33  * @author Sylvain HallĂ©
34  * @difficulty Easy
35  */
36 public class DuplicateContext
37 {
38  public static void main(String[] args)
39  {
40  /// We first create an ApplyFunction that simply adds
41  // the value of some context element to the current event
42  ApplyFunction f1 = new ApplyFunction(new FunctionTree(
43  Numbers.addition, StreamVariable.X, new ContextVariable("foo")));
44  Connector.connect(f1, new Print()
45  .setPrefix("f1: ").setSeparator("\n"));
46 
47  // We then feed a few events to each of them
48  Pushable p_f1 = f1.getPushableInput();
49  f1.setContext("foo", 10);
50  p_f1.push(3).push(1);
51 
52  // Let us now duplicate sum1 and push events to the copy
53  ApplyFunction f2 = (ApplyFunction) f1.duplicate();
54  Connector.connect(f2, new Print()
55  .setPrefix("f2: ").setSeparator("\n"));
56  Pushable p_f2 = f2.getPushableInput();
57  p_f2.push(2).push(7).push(1);
58  ///
59  }
60 }
static void main(String[] args)
Duplicating processors and observing what happens to their Context object.