Package net.kuujo.vertigo.io.port

Examples of net.kuujo.vertigo.io.port.InputPortContext


    } else {
      Iterator<Map.Entry<String, DefaultInputPortContext>> iter = ports.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, DefaultInputPortContext> entry = iter.next();
        DefaultInputPortContext port = entry.getValue();
        InputPortContext match = null;
        for (InputPortContext p : update.ports()) {
          if (port.name().equals(p.name())) {
            match = p;
            break;
          }
View Full Code Here


      log.debug(String.format("%s - Lazily creating in port: %s", this, name));

      // Attempt to search for the port in the existing context. If the
      // port isn't an explicitly configured port then lazily create
      // and open the port. The lazy port will be empty.
      InputPortContext portContext = context.port(name);
      if (portContext == null) {
        portContext = DefaultInputPortContext.Builder.newBuilder()
            .setAddress(UUID.randomUUID().toString())
            .setName(name)
            .build();
View Full Code Here

      @Override
      public void handle(final Task task) {
        final List<InputPort> newPorts = new ArrayList<>();
        for (InputPortContext input : update.ports()) {
          if (!ports.containsKey(input.name())) {
            InputPortContext port = DefaultInputCollector.this.context.port(input.name());
            if (port != null) {
              log.debug(String.format("%s - Adding in port: %s", DefaultInputCollector.this, input));
              newPorts.add(new DefaultInputPort(vertx, port));
            }
          }
        }

        // If the input has already been started, add each input port
        // only once the port has been started. This ensures that the
        // input cannot receive messages until the port is open.
        if (started) {
          final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(newPorts.size());
          counter.setHandler(new Handler<AsyncResult<Void>>() {
            @Override
            public void handle(AsyncResult<Void> result) {
              task.complete();
            }
          });

          // Iterate through each new input port and open and add the port.
          for (final InputPort port : newPorts) {
            log.debug(String.format("%s - Opening in port: %s", DefaultInputCollector.this, port));
            port.open(new Handler<AsyncResult<Void>>() {
              @Override
              public void handle(AsyncResult<Void> result) {
                if (result.failed()) {
                  log.error(String.format("%s - Failed to open in port: %s", DefaultInputCollector.this, port));
                } else {
                  log.info(String.format("%s - Opened in port: %s", DefaultInputCollector.this, port));
                  ports.put(port.name(), port);
                }
                counter.succeed();
              }
            });
          }
        } else {
          // If the input is not already started, simply open and add the ports.
          // The ports will be open once the input is started.
          for (InputPort port : newPorts) {
            ports.put(port.name(), port);
          }
          task.complete();
        }
      }
    });
View Full Code Here

  public void update(InputPortContext context) {
    log.debug(String.format("%s - In port configuration has changed, updating connections", this));

    // Copy the context in order to ensure that future changes via the
    // observer will not effect this update.
    final InputPortContext update = context.copy();

    // All updates are run sequentially to prevent race conditions
    // during configuration changes. Without essentially locking the
    // object, it could be possible that connections are simultaneously
    // added and removed or opened and closed on the object.
    tasks.runTask(new Handler<Task>() {
      @Override
      public void handle(final Task task) {
        // Iterate through existing connections and try to determine
        // whether any of them have been removed from the network.
        Iterator<InputConnection> iter = connections.iterator();
        while (iter.hasNext()) {
          final InputConnection connection = iter.next();
          boolean exists = false;
          for (InputConnectionContext input : update.connections()) {
            if (input.address().equals(connection.address())) {
              exists = true;
              break;
            }
          }

          // If a connection was removed from the network, close
          // and remove the connection regardless of whether the
          // close is actually successful.
          if (!exists) {
            connection.close(new Handler<AsyncResult<Void>>() {
              @Override
              public void handle(AsyncResult<Void> result) {
                if (result.failed()) {
                  log.error(String.format("%s - Failed to close input connection: %s", DefaultInputPort.this, connection));
                } else {
                  log.info(String.format("%s - Closed input connection: %s", DefaultInputPort.this, connection));
                }
              }
            });
            iter.remove();
          }
        }

        // Now try to determine whether any connections were added to the network.
        final List<InputConnection> newConnections = new ArrayList<>();
        for (InputConnectionContext input : update.connections()) {
          boolean exists = false;
          for (InputConnection connection : connections) {
            if (connection.address().equals(input.address())) {
              exists = true;
              break;
View Full Code Here

        if (curi.hasEndpoint()) {
          switch (curi.getEndpoint()) {
            case ContextUri.ENDPOINT_IN:
              InputContext input = instance.input();
              if (curi.hasPort()) {
                InputPortContext inPort = input.port(curi.getPort());
                if (inPort == null) {
                  throw new IllegalArgumentException("The URI port " + curi.getPort() + " does not exist in the given input configuration");
                }
                return (T) inPort;
              }
View Full Code Here

              }
            }

            // If the input port doesn't already exist then add it.
            if (input == null) {
              InputPortContext port = DefaultInputPortContext.Builder.newBuilder()
                  .setAddress(String.format("in:%s@%s.%s.%s[%d]", connection.getTarget().getPort(), cluster, network.getName(), target.name(), targetInstance.number()))
                  .setName(connection.getTarget().getPort())
                  .build();
              DefaultInputContext.Builder.newBuilder(targetInstance.input())
                  .addPort(port).build();
View Full Code Here

TOP

Related Classes of net.kuujo.vertigo.io.port.InputPortContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.