Code Examples
A repository of 155 code examples for BeepBeep
QueueSinkUsage.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2016 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 java.util.Queue;
21 
22 import ca.uqac.lif.cep.Pushable;
23 import ca.uqac.lif.cep.tmf.QueueSink;
24 
25 /**
26  * Push events into a {@link ca.uqac.lif.cep.tmf.QueueSink QueueSink}
27  * processor. Graphically, the queue sink is represented as follows:
28  * <p>
29  * <img src="./doc-files/basic/QueueSinkUsage.png" alt="Processor graph">
30  * <p>
31  * Since it is a <em>sink</em>, it has no output stream.
32  * <p>
33  * The expected output of this program is:
34  * <pre>
35  * Events in the sink: [foo, bar]
36  * Events in the sink: [bar, baz]
37  * </pre>
38  * @author Sylvain Hallé
39  * @difficulty Easy
40  */
41 public class QueueSinkUsage
42 {
43  public static void main(String[] args)
44  {
45  /// Create a sink
46  QueueSink sink = new QueueSink();
47  // Get a reference to the sink's Pushable
48  Pushable p = sink.getPushableInput();
49  // Push a few events into the sink
50  p.push("foo");
51  p.push("bar");
52  // Get a reference to the sink's queue, where events are stored
53  Queue<Object> queue = sink.getQueue();
54  System.out.println("Events in the sink: " + queue);
55  // Events remain in the queue as long as you pop them out
56  queue.remove(); // Removes the first event
57  p.push("baz"); // Push another one
58  System.out.println("Events in the sink: " + queue);
59  ///
60  }
61 
62 }
Push events into a QueueSink processor.
static void main(String[] args)