vertigo icon indicating copy to clipboard operation
vertigo copied to clipboard

Add a "NetworkExecutor" to allow networks to be executed externally

Open kuujo opened this issue 12 years ago • 0 comments

One of the most useful ways to use an executor would be to deploy a network and then execute it. But the current executor implementations do not support this. Suppose we want to have some custom verticle that registers a handler on the event bus and executes a network with any incoming data:

Cluster cluster = new LocalCluster(this);
cluster.deploy(network, new Handler<AsyncResult<NetworkContext>>() {
  public void handle(AsyncResult<NetworkContext> result) {
    if (result.succeeded()) {
      NetworkContext context = result.result();
      final NetworkExecutor executor = vertigo.createNetworkExecutor(context.getComponent("some.component"));
      eb.registerHandler("some.address", new Handler<Message<JsonObject>>() {
        public void handle(final Message<JsonObject> message) {
          executor.execute(message.body(), new Handler<AsyncResult<JsonMessage>>() {
            public void handle(AsyncResult<JsonMessage> result) {
              if (result.succeeded()) {
                message.reply(result.result().body());
              } else {
                message.reply(new JsonObject().putString("status", "error"));
              }
            }
          });
        }
      });
    }
  }
});

Currently, it's impossible to deploy and operate on a network like this externally. But the Vertigo messaging system certainly supports this. The NetworkExecutor would need only to subscribe to output from some component which could be defined in the NetworkExecutor constructor (in this example it passes a ComponentContext to the constructor).

kuujo avatar Nov 16 '13 00:11 kuujo