Package net.kuujo.vertigo.io.connection

Examples of net.kuujo.vertigo.io.connection.InputConnection


      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;
            }
          }
          if (!exists) {
            log.debug(String.format("%s - Creating connection: %s", DefaultInputPort.this, input));
            newConnections.add(new DefaultInputConnection(vertx, input));
          }
        }

        // If the port is open then that means connections have already
        // been set up. We need to add the new connections carefully
        // because it's possible that user code may be sending messages
        // on the port. If messages are sent to a connection that's not
        // yet open then an exception will be thrown.
        if (open) {
          final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(newConnections.size());
          counter.setHandler(new Handler<AsyncResult<Void>>() {
            @Override
            public void handle(AsyncResult<Void> result) {
              task.complete();
            }
          });

          // Start each connection and add the connection to the connections
          // list only once the connection has been successfully opened.
          // The update lock by the task runner will ensure that we don't
          // accidentally open up two of the same connection even if the
          // configuration is updated again.
          for (final InputConnection connection : newConnections) {
            connection.open(new Handler<AsyncResult<Void>>() {
              @Override
              public void handle(AsyncResult<Void> result) {
                if (result.failed()) {
                  log.error(String.format("%s - Failed to open input connection: %s", DefaultInputPort.this, connection));
                } else {
View Full Code Here


          // Only add connections to the connections list once the connection
          // has been opened. This ensures that we don't attempt to send messages
          // on a close connection.
          connections.clear();
          for (InputConnectionContext connectionContext : context.connections()) {
            final InputConnection connection = new DefaultInputConnection(vertx, connectionContext);
            connection.open(new Handler<AsyncResult<Void>>() {
              @Override
              public void handle(AsyncResult<Void> result) {
                if (result.failed()) {
                  log.error(String.format("%s - Failed to open input connection: %s", DefaultInputPort.this, connection));
                  startCounter.fail(result.cause());
View Full Code Here

TOP

Related Classes of net.kuujo.vertigo.io.connection.InputConnection

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.