Code Examples
A repository of 155 code examples for BeepBeep
PipingUnaryMissing.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.Doubler;
21 import ca.uqac.lif.cep.Pullable;
22 import ca.uqac.lif.cep.tmf.QueueSource;
23 
24 /**
25  * Instantiates two processors, but forgets to connect them. This example is
26  * identical to {@link PipingUnary}, but without the call to {@code connect}.
27  * <p>
28  * <img src="./doc-files/basic/PipingUnaryMissing.png" alt="Processor graph">
29  * <p>
30  * Notice how a pipe between the source and the Doubler processor is missing.
31  * Attempting to call {@code pull} on {@code doubler} will throw an exception.
32  * The expected output of the program should look like this:
33  * <pre>
34  * Exception in thread "main" ca.uqac.lif.cep.Pullable$PullableException: Input 0 of this processor is connected to nothing
35  at ca.uqac.lif.cep.SynchronousProcessor$OutputPullable.hasNext(SynchronousProcessor.java:396)
36  at ca.uqac.lif.cep.SynchronousProcessor$OutputPullable.pull(SynchronousProcessor.java:354)
37  at basic.PipingUnaryMissing.main(PipingUnaryMissing.java:51)
38  * </pre>
39  * @see PipingUnary
40  * @author Sylvain HallĂ©
41  * @difficulty Easy
42  */
43 public class PipingUnaryMissing
44 {
45  public static void main (String[] args)
46  {
47  // Create a source of arbitrary numbers
48  QueueSource source = new QueueSource();
49  source.setEvents(1, 2, 3, 4, 5, 6);
50 
51  /* Create an instance of the Doubler processor (which is defined just
52  * below in this file. */
53  Doubler doubler = new Doubler();
54 
55  /* We do NOT connect the two processors and try to call pull
56  * on doubler. This will throw an exception. */
57  ///
58  Pullable p = doubler.getPullableOutput();
59  System.out.println("The event is: " + p.pull());
60  ///
61  }
62 }
Instantiates two processors, but forgets to connect them.