Code Examples
A repository of 155 code examples for BeepBeep
PullWithoutSource.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 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.Pullable;
21 import ca.uqac.lif.cep.tmf.Passthrough;
22 
23 /**
24  * What happens when trying to pull events on a processor connected to
25  * no input. The chain of processors in this example is very simple, it
26  * is composed of a single {@link ca.uqac.lif.cep.tmf.Passthrough Passthrough}
27  * processor:
28  * <p>
29  * <img src="./doc-files/basic/Passthrough.png" alt="Processor chain">
30  * <p>
31  * When attempting to pull an event into the input of this processor, the
32  * passthrough will attempt to pull it, in turn, from its input. The
33  * problem lies in the fact that <em>nothing</em> is connect to the input.
34  * In BeepBeep, every input stream of every processor
35  * <em>must</em> be connected to something. The only way to close a chain is
36  * by using a {@link ca.uqac.lif.cep.tmf.Source Source}
37  * (a processor with zero input stream).
38  * Thus, the expected output of this program is this:
39  * <pre>
40  * Exception in thread "main" ca.uqac.lif.cep.Pullable$PullableException:
41  * Input 0 of this processor is connected to nothing
42  * at ca.uqac.lif.cep.UniformProcessor$OutputPullable.hasNext(UniformProcessor.java:303)
43  * at ca.uqac.lif.cep.UniformProcessor$OutputPullable.pull(UniformProcessor.java:263)
44  * at basic.PullWithoutSource.main(PullWithoutSource.java:62)
45  * </pre>
46  * <p>
47  * The opposite also happens when trying to pull events from a processor
48  * connected to no input. See {@link PushWithoutSink}.
49  *
50  * @author Sylvain HallĂ©
51  * @difficulty Easy
52  */
53 public class PullWithoutSource
54 {
55  public static void main(String[] args)
56  {
57  /// Create a Passthrough processor
58  Passthrough passthrough = new Passthrough();
59  /* Get a reference to the Pullable for its input stream */
60  Pullable p = passthrough.getPullableOutput();
61  /* Try to pull an event. This will throw an exception and stop
62  * the program. */
63  p.pull();
64  ///
65  }
66 }
What happens when trying to pull events on a processor connected to no input.
static void main(String[] args)