Package com.couchbase.client

Examples of com.couchbase.client.CouchbaseConnection


  private boolean tryBinaryBootstrapForNode(InetSocketAddress node)
    throws Exception {
    ConfigurationConnectionFactory fact =
      new ConfigurationConnectionFactory(seedNodes, bucket, password);
    CouchbaseConnectionFactory cf = connectionFactory;
    CouchbaseConnection connection;

    List<ConnectionObserver> initialObservers = new ArrayList<ConnectionObserver>();
    final CountDownLatch latch = new CountDownLatch(1);
    initialObservers.add(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress socketAddress, int i) {
        latch.countDown();
      }

      @Override
      public void connectionLost(SocketAddress socketAddress) {
        // not needed
      }
    });

    try {
       connection = new CouchbaseConfigConnection(
        cf.getReadBufSize(), fact, Collections.singletonList(node),
        initialObservers, cf.getFailureMode(),
        cf.getOperationFactory()
      );

      boolean result = latch.await(5, TimeUnit.SECONDS);
      if (!result) {
        throw new IOException("Connection could not be established to carrier"
          + " port in the given time interval.");
      }
    } catch (Exception ex) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.", ex);
      return false;
    }

    if (!bucket.equals(ANONYMOUS_BUCKET)) {
      AuthThreadMonitor monitor = new AuthThreadMonitor();
      List<MemcachedNode> connectedNodes = new ArrayList<MemcachedNode>(
        connection.getLocator().getAll());
      for (MemcachedNode connectedNode : connectedNodes) {
        if (connectedNode.getSocketAddress().equals(node)) {
          monitor.authConnection(connection, cf.getOperationFactory(),
            cf.getAuthDescriptor(), connectedNode);
        }
      }
    }

    List<String> configs = getConfigsFromBinaryConnection(connection);

    if (configs.isEmpty()) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.");
      connection.shutdown();
      return false;
    }

    String appliedConfig = connection.replaceConfigWildcards(
      configs.get(0));
    Bucket config = configurationParser.parseBucket(appliedConfig);
    setConfig(config);
    connection.addObserver(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress sa, int reconnectCount) {
        getLogger().debug("Carrier Config Connection established to " + sa);
      }

      @Override
      public void connectionLost(SocketAddress sa) {
        getLogger().debug("Carrier Config Connection lost from " + sa);
        CouchbaseConnection conn = binaryConnection.getAndSet(null);
        try {
          conn.shutdown();
        } catch (IOException e) {
          getLogger().debug("Could not shut down Carrier Config Connection", e);
        }
        signalOutdated();
      }
View Full Code Here


  private boolean tryBinaryBootstrapForNode(InetSocketAddress node)
    throws Exception {
    ConfigurationConnectionFactory fact =
      new ConfigurationConnectionFactory(seedNodes, bucket, password);
    CouchbaseConnectionFactory cf = connectionFactory;
    CouchbaseConnection connection;

    List<ConnectionObserver> initialObservers = new ArrayList<ConnectionObserver>();
    final CountDownLatch latch = new CountDownLatch(1);
    initialObservers.add(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress socketAddress, int i) {
        latch.countDown();
      }

      @Override
      public void connectionLost(SocketAddress socketAddress) {
        // not needed
      }
    });

    try {
       connection = new CouchbaseConfigConnection(
        cf.getReadBufSize(), fact, Collections.singletonList(node),
        initialObservers, cf.getFailureMode(),
        cf.getOperationFactory()
      );

      boolean result = latch.await(5, TimeUnit.SECONDS);
      if (!result) {
        throw new IOException("Connection could not be established to carrier"
          + " port in the given time interval.");
      }
    } catch (Exception ex) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.", ex);
      return false;
    }

    if (!bucket.equals(ANONYMOUS_BUCKET)) {
      AuthThreadMonitor monitor = new AuthThreadMonitor();
      List<MemcachedNode> connectedNodes = new ArrayList<MemcachedNode>(
        connection.getLocator().getAll());
      for (MemcachedNode connectedNode : connectedNodes) {
        if (connectedNode.getSocketAddress().equals(node)) {
          monitor.authConnection(connection, cf.getOperationFactory(),
            cf.getAuthDescriptor(), connectedNode);
        }
      }
    }

    List<String> configs = getConfigsFromBinaryConnection(connection);

    if (configs.isEmpty()) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.");
      connection.shutdown();
      return false;
    }

    String appliedConfig = connection.replaceConfigWildcards(
      configs.get(0));
    Bucket config = configurationParser.parseBucket(appliedConfig);
    setConfig(config);
    connection.addObserver(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress sa, int reconnectCount) {
        getLogger().debug("Carrier Config Connection established to " + sa);
      }

      @Override
      public void connectionLost(SocketAddress sa) {
        getLogger().debug("Carrier Config Connection lost from " + sa);
        CouchbaseConnection conn = binaryConnection.getAndSet(null);
        try {
          conn.shutdown();
        } catch (IOException e) {
          getLogger().debug("Could not shut down Carrier Config Connection", e);
        }
        signalOutdated();
      }
View Full Code Here

  private boolean tryBinaryBootstrapForNode(InetSocketAddress node)
    throws Exception {
    ConfigurationConnectionFactory fact =
      new ConfigurationConnectionFactory(seedNodes, bucket, password);
    CouchbaseConnectionFactory cf = connectionFactory;
    CouchbaseConnection connection;

    try {
       connection = new CouchbaseConfigConnection(
        cf.getReadBufSize(), fact, Collections.singletonList(node),
        cf.getInitialObservers(), cf.getFailureMode(),
        cf.getOperationFactory()
      );
    } catch (Exception ex) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.", ex);
      return false;
    }

    if (!bucket.equals(ANONYMOUS_BUCKET)) {
      AuthThreadMonitor monitor = new AuthThreadMonitor();
      List<MemcachedNode> connectedNodes = new ArrayList<MemcachedNode>(
        connection.getLocator().getAll());
      for (MemcachedNode connectedNode : connectedNodes) {
        monitor.authConnection(connection, cf.getOperationFactory(),
          cf.getAuthDescriptor(), connectedNode);
      }
    }

    List<String> configs = getConfigsFromBinaryConnection(connection);

    if (configs.isEmpty()) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.");
      connection.shutdown();
      return false;
    }

    String appliedConfig = connection.replaceConfigWildcards(
      configs.get(0));
    Bucket config = configurationParser.parseBucket(appliedConfig);
    setConfig(config);
    binaryConnection.set(connection);
    return true;
View Full Code Here

        return true;
    }
    ConfigurationConnectionFactory fact =
      new ConfigurationConnectionFactory(seedNodes, bucket, password);
    CouchbaseConnectionFactory cf = connectionFactory;
    CouchbaseConnection connection = null;

    List<ConnectionObserver> initialObservers = new ArrayList<ConnectionObserver>();
    final CountDownLatch latch = new CountDownLatch(1);
    initialObservers.add(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress socketAddress, int i) {
        latch.countDown();
      }

      @Override
      public void connectionLost(SocketAddress socketAddress) {
        // not needed
      }
    });

    try {
       connection = new CouchbaseConfigConnection(
        cf.getReadBufSize(), fact, Collections.singletonList(node),
        initialObservers, cf.getFailureMode(),
        cf.getOperationFactory()
      );

      boolean result = latch.await(5, TimeUnit.SECONDS);
      if (!result) {
        throw new IOException("Connection could not be established to carrier"
          + " port in the given time interval.");
      }
    } catch (Exception ex) {
      if (connection != null) {
        connection.shutdown();
      }
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.", ex);
      return false;
    }

    if (!bucket.equals(ANONYMOUS_BUCKET)) {
      AuthThreadMonitor monitor = new AuthThreadMonitor();
      List<MemcachedNode> connectedNodes = new ArrayList<MemcachedNode>(
        connection.getLocator().getAll());
      for (MemcachedNode connectedNode : connectedNodes) {
        if (connectedNode.getSocketAddress().equals(node)) {
          monitor.authConnection(connection, cf.getOperationFactory(),
            cf.getAuthDescriptor(), connectedNode);
        }
      }
    }

    List<String> configs = getConfigsFromBinaryConnection(connection);

    if (configs.isEmpty()) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.");
      connection.shutdown();
      return false;
    }

    String appliedConfig = connection.replaceConfigWildcards(
      configs.get(0));
    try {
        Bucket config = configurationParser.parseBucket(appliedConfig);
        setConfig(config);
    } catch(Exception ex) {
        getLogger().warn("Could not parse config, retrying bootstrap.", ex);
        connection.shutdown();
        return false;
    }

    connection.addObserver(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress sa, int reconnectCount) {
        getLogger().debug("Carrier Config Connection established to " + sa);
      }

      @Override
      public void connectionLost(SocketAddress sa) {
        getLogger().debug("Carrier Config Connection lost from " + sa);
        CouchbaseConnection conn = binaryConnection.getAndSet(null);
        try {
          conn.shutdown();

        } catch (IOException e) {
          getLogger().debug("Could not shut down Carrier Config Connection", e);
        }
        signalOutdated();
      }
    });

    CouchbaseConnection old = binaryConnection.get();
    if (old != null) {
        old.shutdown();
    }
    binaryConnection.set(connection);
    return true;
  }
View Full Code Here

        return true;
    }
    ConfigurationConnectionFactory fact =
      new ConfigurationConnectionFactory(seedNodes, bucket, password);
    CouchbaseConnectionFactory cf = connectionFactory;
    CouchbaseConnection connection = null;

    List<ConnectionObserver> initialObservers = new ArrayList<ConnectionObserver>();
    final CountDownLatch latch = new CountDownLatch(1);
    initialObservers.add(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress socketAddress, int i) {
        latch.countDown();
      }

      @Override
      public void connectionLost(SocketAddress socketAddress) {
        // not needed
      }
    });

    try {
       connection = new CouchbaseConfigConnection(
        cf.getReadBufSize(), fact, Collections.singletonList(node),
        initialObservers, cf.getFailureMode(),
        cf.getOperationFactory()
      );

      boolean result = latch.await(5, TimeUnit.SECONDS);
      if (!result) {
        throw new IOException("Connection could not be established to carrier"
          + " port in the given time interval.");
      }
    } catch (Exception ex) {
      if (connection != null) {
        connection.shutdown();
      }
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.", ex);
      return false;
    }

    if (!bucket.equals(ANONYMOUS_BUCKET)) {
      AuthThreadMonitor monitor = new AuthThreadMonitor();
      List<MemcachedNode> connectedNodes = new ArrayList<MemcachedNode>(
        connection.getLocator().getAll());
      for (MemcachedNode connectedNode : connectedNodes) {
        if (connectedNode.getSocketAddress().equals(node)) {
          monitor.authConnection(connection, cf.getOperationFactory(),
            cf.getAuthDescriptor(), connectedNode);
        }
      }
    }

    List<String> configs = getConfigsFromBinaryConnection(connection);

    if (configs.isEmpty()) {
      getLogger().debug("(Carrier Publication) Could not load config from "
        + node.getHostName() + ", trying next node.");
      connection.shutdown();
      return false;
    }

    String appliedConfig = connection.replaceConfigWildcards(
      configs.get(0));
    try {
        Bucket config = configurationParser.parseBucket(appliedConfig);
        setConfig(config);
    } catch(Exception ex) {
        getLogger().warn("Could not parse config, retrying bootstrap.", ex);
        connection.shutdown();
        return false;
    }

    connection.addObserver(new ConnectionObserver() {
      @Override
      public void connectionEstablished(SocketAddress sa, int reconnectCount) {
        getLogger().debug("Carrier Config Connection established to " + sa);
      }

      @Override
      public void connectionLost(SocketAddress sa) {
        getLogger().debug("Carrier Config Connection lost from " + sa);
        CouchbaseConnection conn = binaryConnection.getAndSet(null);
        try {
          conn.shutdown();

        } catch (IOException e) {
          getLogger().debug("Could not shut down Carrier Config Connection", e);
        }
        signalOutdated();
      }
    });

    CouchbaseConnection old = binaryConnection.get();
    if (old != null) {
        old.shutdown();
    }
    binaryConnection.set(connection);
    return true;
  }
View Full Code Here

TOP

Related Classes of com.couchbase.client.CouchbaseConnection

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.