Code Examples
A repository of 155 code examples for BeepBeep
GroupSimple.java
1 package basic;
2 
3 import ca.uqac.lif.cep.Connector;
4 import ca.uqac.lif.cep.GroupProcessor;
5 import ca.uqac.lif.cep.Pullable;
6 import ca.uqac.lif.cep.functions.ApplyFunction;
7 import ca.uqac.lif.cep.tmf.Fork;
8 import ca.uqac.lif.cep.tmf.QueueSource;
9 import ca.uqac.lif.cep.tmf.Trim;
10 import ca.uqac.lif.cep.util.Numbers;
11 
12 /**
13  * Encapsulate a chain of processors into a
14  * {@link ca.uqac.lif.cep.Group Group}.
15  * The chain of processors in this example can be
16  * represented graphically as:
17  * <p>
18  * <img src="./doc-files/basic/GroupSimple.png" alt="Processor graph">
19  * @see SumTwo
20  * @author Sylvain HallĂ©
21  * @difficulty Easy
22  * {@link GroupProcessor#associateInput(int, ca.uqac.lif.cep.Processor, int)
23  */
24 public class GroupSimple
25 {
26  public static void main(String[] args)
27  {
28  /// Create a source of arbitrary numbers
29  QueueSource source = new QueueSource().setEvents(1, 2, 3, 4, 5, 6);
30 
31  // Fork the stream in two and connect it to the source
32  GroupProcessor group = new GroupProcessor(1, 1);
33  {
34  Fork fork = new Fork(2);
35  ApplyFunction add = new ApplyFunction(Numbers.addition);
36  Connector.connect(fork, 0, add, 0);
37  Trim trim = new Trim(1);
38  Connector.connect(fork, 1, trim, 0);
39  Connector.connect(trim, 0, add, 1);
40  group.addProcessors(fork, trim, add);
41  group.associateInput(0, fork, 0);
42  group.associateOutput(0, add, 0);
43  }
44 
45  // Connect the source to the group
46  Connector.connect(source, group);
47 
48  /* Let us now print what we receive by pulling on the output of
49  * group. */
50  Pullable p = group.getPullableOutput();
51  for (int i = 0; i < 6; i++)
52  {
53  float x = (Float) p.pull();
54  System.out.println("The event is: " + x);
55  }
56  ///
57  }
58 }
Encapsulate a chain of processors into a Group.
static void main(String[] args)