@@ -0,0 +1,3013 @@
+/*%0A * Copyright 2013 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage net.kuujo.vertigo;%0A%0Aimport org.vertx.java.core.AsyncResult;%0Aimport org.vertx.java.core.Handler;%0Aimport org.vertx.java.core.json.JsonObject;%0A%0Aimport net.kuujo.vertigo.context.NetworkContext;%0Aimport net.kuujo.vertigo.hooks.EventBusHook;%0Aimport net.kuujo.vertigo.hooks.EventBusHookListener;%0Aimport net.kuujo.vertigo.java.RichFeederVerticle;%0Aimport net.kuujo.vertigo.java.RichWorkerVerticle;%0Aimport net.kuujo.vertigo.java.VertigoVerticle;%0Aimport net.kuujo.vertigo.message.JsonMessage;%0Aimport net.kuujo.vertigo.message.MessageId;%0Aimport net.kuujo.vertigo.network.Network;%0A%0A/**%0A * A component hook example.%0A *%0A * This example demonstrates how hooks can be used to listen for events on%0A * Vertigo components. In this case, we use the built-in EventBusHook to publish%0A * component events over the event bus.%0A *%0A * @author Jordan Halterman%0A */%0Apublic class EventBusHookNetwork extends VertigoVerticle %7B%0A%0A  public static class ExampleFeeder extends RichFeederVerticle %7B%0A    @Override%0A    protected void nextMessage() %7B%0A      emit(new JsonObject().putString(%22body%22, %22Hello world!%22));%0A    %7D%0A  %7D%0A%0A  public static class ExampleWorker extends RichWorkerVerticle %7B%0A    @Override%0A    protected void handleMessage(JsonMessage message) %7B%0A      emit(message);%0A      ack(message);%0A    %7D%0A  %7D%0A%0A  @Override%0A  @SuppressWarnings(%22unchecked%22)%0A  public void start() %7B%0A    // Set up the network.%0A    Network network = vertigo.createNetwork(%22hooks%22);%0A    network.addFeeder(%22hooks.feeder%22, ExampleFeeder.class.getName());%0A    network.addWorker(%22hooks.worker%22, ExampleWorker.class.getName())%0A      .addHook(new EventBusHook()).addInput(%22hooks.feeder%22);%0A%0A    // Deploy the network.%0A    vertigo.deployLocalNetwork(network, new Handler%3CAsyncResult%3CNetworkContext%3E%3E() %7B%0A      @Override%0A      public void handle(AsyncResult%3CNetworkContext%3E result) %7B%0A        if (result.succeeded()) %7B%0A          // Create an event bus hook listener. This special class will handle%0A          // event bus handlers and deserialization of component events.%0A          EventBusHookListener listener = new EventBusHookListener(%22hooks.worker%22, vertx.eventBus());%0A          listener.receiveHandler(new Handler%3CMessageId%3E() %7B%0A            @Override%0A            public void handle(MessageId messageId) %7B%0A              container.logger().info(%22Worker received message %22 + messageId.correlationId());%0A            %7D%0A          %7D);%0A        %7D%0A      %7D%0A    %7D);%0A  %7D%0A%0A%7D%0A

Add an event bus hook example.