Code Examples
A repository of 155 code examples for BeepBeep
PushWithoutSink.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.Pushable;
21 import ca.uqac.lif.cep.tmf.Passthrough;
22 
23 /**
24  * What happens when trying to push events on a processor connected to
25  * no output. 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 push an event into the input of this processor, the
32  * passthrough will attempt to push it, in turn, through its output. The
33  * problem lies in the fact that <em>nothing</em> is connect to the output.
34  * In BeepBeep, pushed events cannot just disappear into thin air: they
35  * <em>must</em> be collected by some {@link ca.uqac.lif.cep.tmf.Sink Sink}
36  * (a processor with zero output streams).
37  * Thus, the expected output of this program is this:
38  * <pre>
39  * Exception in thread "main" ca.uqac.lif.cep.Pushable$PushableException:
40  * Output 0 of this processor is connected to nothing
41  * at ca.uqac.lif.cep.UniformProcessor$InputPushable.push(UniformProcessor.java:178)
42  * at basic.PushWithoutSink.main(PushWithoutSink.java:35)
43  * </pre>
44  * <p>
45  * The opposite also happens when trying to pull events from a processor
46  * connected to no input. See {@link PullWithoutSource}.
47  *
48  * @author Sytlvain HallĂ©
49  * @difficulty Easy
50  */
51 public class PushWithoutSink
52 {
53  public static void main(String[] args)
54  {
55  /// Create a Passthrough processor
56  Passthrough passthrough = new Passthrough();
57  /* Get a reference to the Pushable for its input stream */
58  Pushable p = passthrough.getPushableInput();
59  /* Try to push an event. This will throw an exception and stop
60  * the program. */
61  p.push("foo");
62  ///
63  }
64 }
static void main(String[] args)
What happens when trying to push events on a processor connected to no output.