Code Examples
A repository of 155 code examples for BeepBeep
DuplicateGroup.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.GroupProcessor;
22 import ca.uqac.lif.cep.Pullable;
23 import ca.uqac.lif.cep.functions.Cumulate;
24 import ca.uqac.lif.cep.functions.CumulativeFunction;
25 import ca.uqac.lif.cep.tmf.QueueSource;
26 import ca.uqac.lif.cep.tmf.Stutter;
27 import ca.uqac.lif.cep.util.Numbers;
28 
29 /**
30  * Duplicating processors without preserving their state.
31  *
32  * @author Sylvain HallĂ©
33  * @difficulty Easy
34  */
35 public class DuplicateGroup
36 {
37  public static void main(String[] args)
38  {
39  /// We first create a GroupProcessor
40  QueueSource source1 = new QueueSource().setEvents(3, 1, 4, 1, 5);
41  GroupProcessor gp1 = new GroupProcessor(1, 1);
42  {
43  Stutter st = new Stutter(2);
44  Cumulate sum = new Cumulate(
45  new CumulativeFunction<Number>(Numbers.addition));
46  Connector.connect(st, sum);
47  gp1.addProcessors(st, sum);
48  gp1.associateInput(0, st, 0);
49  gp1.associateOutput(0, sum, 0);
50  }
51  Connector.connect(source1, gp1);
52 
53  // We pull one event from gp1
54  Pullable p_gp1 = gp1.getPullableOutput();
55  System.out.println(p_gp1.pull());
56  ///
57 
58  //! Let us clone gp1 and connect it to a new source
59  QueueSource source2 = new QueueSource().setEvents(2, 7, 1, 8);
60  GroupProcessor gp2 = gp1.duplicate(true);
61  Connector.connect(source2, gp2);
62  Pullable p_gp2 = gp2.getPullableOutput();
63  System.out.println(p_gp2.pull());
64  //!
65  }
66 }
static void main(String[] args)
Duplicating processors without preserving their state.