Code Examples
A repository of 155 code examples for BeepBeep
basic.ForkPull Class Reference

Use the Fork processor to replicate input events in multiple output streams. More...

Static Public Member Functions

static void main (String[] args) throws InterruptedException
 

Detailed Description

Use the Fork processor to replicate input events in multiple output streams.

Graphically, the processors of this example can be drawn as follows:

Processor graph

The expected output of this program is:

P0 foo
P1 foo
P2 foo
P0 bar
P1 bar
P2 bar
Author
Sylvain Hallé Easy

Definition at line 44 of file ForkPull.java.

Member Function Documentation

◆ main()

static void basic.ForkPull.main ( String []  args) throws InterruptedException
static

Create a queue source with a few numbers

Definition at line 46 of file ForkPull.java.

47  {
48  /// Create a queue source with a few numbers
49  QueueSource source = new QueueSource().setEvents(1, 2, 3, 4, 5);
50 
51  /* We create a fork processor that will replicate each input event
52  * in two output streams. The "2" passed as an argument to the fork's
53  * constructor signifies this. Then we connect the source to the
54  * fork's input pipe. */
55  Fork fork = new Fork(2);
56  Connector.connect(source, fork);
57 
58  /* We get Pullables on both outputs of the fork. */
59  Pullable p0 = fork.getPullableOutput(0);
60  Pullable p1 = fork.getPullableOutput(1);
61 
62  /* Let's now pull an event from p0. The output is 1. */
63  System.out.println("Output from p0: " + p0.pull());
64 
65  /* Let's now pull an event from p1. Surprisingly, the output is 1.
66  * This can be explained by the fact that each input event in the
67  * fork is replicated to all its output pipes. The fact that we
68  * pulled an event from p0 has no effect on p1, and vice versa. */
69  System.out.println("Output from p1: " + p1.pull());
70  ///
71 
72  /* The independence between the fork's two outputs is further
73  * illustrated by this sequence of calls. Notice how each pullable
74  * moves through the input stream independently of calls to the
75  * other pullable. */
76  //*
77  System.out.println("Output from p0: " + p0.pull());
78  System.out.println("Output from p0: " + p0.pull());
79  System.out.println("Output from p1: " + p1.pull());
80  System.out.println("Output from p0: " + p0.pull());
81  System.out.println("Output from p1: " + p1.pull());
82  //*
83  }

The documentation for this class was generated from the following file: