Package net.kuujo.vertigo.io.port

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


      log.debug(String.format("%s - Lazily creating out 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.
      OutputPortContext portContext = context.port(name);
      if (portContext == null) {
        portContext = DefaultOutputPortContext.Builder.newBuilder()
            .setAddress(UUID.randomUUID().toString())
            .setName(name)
            .build();
View Full Code Here


      @Override
      public void handle(final Task task) {
        final List<OutputPort> newPorts = new ArrayList<>();
        for (OutputPortContext output : update.ports()) {
          if (!ports.containsKey(output.name())) {
            OutputPortContext port = DefaultOutputCollector.this.context.port(output.name());
            if (port != null) {
              log.debug(String.format("%s - Adding out port: %s", DefaultOutputCollector.this, output));
              newPorts.add(new DefaultOutputPort(vertx, port));
            }
          }
        }

        // If the output has already been started, add each output port
        // only once the port has been started. This ensures that messages
        // cannot be sent on the output port until connections have opened.
        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 output port and open and add the port.
          for (final OutputPort port : newPorts) {
            log.debug(String.format("%s - Opening out port: %s", DefaultOutputCollector.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 out port: %s", DefaultOutputCollector.this, port));
                } else {
                  log.info(String.format("%s - Opened out port: %s", DefaultOutputCollector.this, port));
                  ports.put(port.name(), port);
                }
                counter.succeed();
              }
            });
          }
        } else {
          // If the output is not already started, simply open and add the ports.
          // The ports will be open once the output is started.
          for (OutputPort port : newPorts) {
            ports.put(port.name(), port);
          }
          task.complete();
        }
      }
    });
View Full Code Here

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

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

    // Copy the context in order to ensure that future changes via the
    // observer will not effect this update.
    final OutputPortContext 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 streams and try to determine
        // whether any of them have been removed from the network.
        Iterator<OutputStream> iter = streams.iterator();
        while (iter.hasNext()) {
          final OutputStream stream = iter.next();
          boolean exists = false;
          for (OutputStreamContext output : update.streams()) {
            if (output.address().equals(stream.address())) {
              exists = true;
              break;
            }
          }

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

        // Now try to determine whether any streams were added to the network.
        final List<OutputStream> newStreams = new ArrayList<>();
        for (OutputStreamContext output : update.streams()) {
          boolean exists = false;
          for (OutputStream stream : streams) {
            if (stream.address().equals(output.address())) {
              exists = true;
              break;
View Full Code Here

              }
              return (T) input;
            case ContextUri.ENDPOINT_OUT:
              OutputContext output = instance.output();
              if (curi.hasPort()) {
                OutputPortContext outPort = output.port(curi.getPort());
                if (outPort == null) {
                  throw new IllegalArgumentException("The URI port " + curi.getPort() + " does not exist in the given output configuration");
                }
                return (T) outPort;
              }
View Full Code Here

            }
          }

          // If the output port doesn't already exist then add it.
          if (output == null) {
            OutputPortContext port = DefaultOutputPortContext.Builder.newBuilder()
                .setAddress(String.format("out:%s@%s.%s.%s[%d]", connection.getSource().getPort(), cluster, network.getName(), source.name(), sourceInstance.number()))
                .setName(connection.getSource().getPort())
                .build();
            DefaultOutputContext.Builder.newBuilder(sourceInstance.output())
                .addPort(port).build();
            output = DefaultOutputPortContext.Builder.newBuilder(port);
          }

          // Set up an output stream from the output port.
          DefaultOutputStreamContext.Builder outStream = DefaultOutputStreamContext.Builder.newBuilder();
          outStream.setAddress(String.format("out:%s@%s.%s.%s[%d]->in:%s@%s.%s.%s[]", connection.getSource().getPort(), cluster, network.getName(), source.name(), sourceInstance.number(), connection.getTarget().getPort(), cluster, network.getName(), target.name()));
          outStream.setSelector(connection.getSelector());

          // For each target instance, add a unique input connection for the output.
          for (InstanceContext targetInstance : target.instances()) {
            // Check if the port already exists on the target's input.
            DefaultInputPortContext.Builder input = null;
            for (InputPortContext port : targetInstance.input().ports()) {
              if (port.name().equals(connection.getTarget().getPort())) {
                input = DefaultInputPortContext.Builder.newBuilder(port);
                break;
              }
            }
View Full Code Here

TOP

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

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.