Code Examples
A repository of 155 code examples for BeepBeep
QueueSourceUsage.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
ca.uqac.lif.cep.Pullable;
21
import
ca.uqac.lif.cep.tmf.QueueSource;
22
23
/**
24
* Pull events from the
25
* {@link ca.uqac.lif.cep.tmf.QueueSource QueueSource} processor.
26
* Graphically, the queue source is represented as follows:
27
* <p>
28
* <img src="./doc-files/basic/QueueSourceUsage.png" alt="Processor graph">
29
* <p>
30
* Since it is a <em>source</em>, it has no input streams. We represent
31
* in a rectangle the queue of events that the source will dispense.
32
* @author Sylvain Hallé
33
* @difficulty Easy
34
*/
35
public
class
QueueSourceUsage
36
{
37
public
static
void
main
(String[] args)
38
{
39
/// Create an empty queue source
40
QueueSource source =
new
QueueSource();
41
// Tell the source what events to output by giving it an array;
42
// in this case, we output the first powers of 2
43
source.setEvents(1, 2, 4, 8, 16, 32);
44
// Get a pullable to the source
45
Pullable p = source.getPullableOutput();
46
// Pull 8 events from the source. The queue source loops through
47
// its array of events; hence after reaching the last (32), it
48
// will restart from the beginning of its list.
49
for
(
int
i = 0; i < 8; i++)
50
{
51
// Method pull() returns an Object, hence we must manually cast
52
// it as an integer (this is indeed what we get)
53
int
x = (Integer) p.pull();
54
System.out.println(
"The event is: "
+ x);
55
}
56
///
57
}
58
}
basic.QueueSourceUsage.main
static void main(String[] args)
Definition:
QueueSourceUsage.java:37
basic.QueueSourceUsage
Pull events from the QueueSource processor.
Definition:
QueueSourceUsage.java:35
Source
src
basic
QueueSourceUsage.java
Generated by
1.8.13