1
2 // Create our fiber
3 ThreadFiber fiber = new ThreadFiber();
4 fiber.start();
5
6 // Channel for messages to flow on
7 Channel<String> messages = new MemoryChannel<String>();
8
9 // Create our FieldMouse and subscribe him to the channel
10 final FieldMouse fieldMouse = new FieldMouse();
11 messages.subscribe(fiber, new Callback<String>() {
12 @Override
13 public void onMessage(String message) {
14 fieldMouse.eatCheese(message);
15 }
16 });
17
18 // Tell our mouse to eat cheese
19 messages.publish("cheddar");
20
21 fieldMouse.latch.await();
1 // Create our fiber
2 ThreadFiber fiber = new ThreadFiber();
3 fiber.start();
4
5 // Create heysync hub
6 Hub hub = new Hub();
7
8 // Create our FieldMouse and add him as a receiver to our hub
9 FieldMouse fieldMouse = new FieldMouse();
10 hub.addReceiver(fieldMouse, fiber);
11
12 // Get the dispatcher for all registered Mice
13 Mouse dispatcher = hub.dispatcherFor(Mouse.class);
14
15 // Tell our mouse to eat cheese
16 dispatcher.eatCheese("cheddar");
17
18 fieldMouse.latch.await();
You can clone the project with Git by running:
$ git clone git://github.com/osi/heysync