Package com.aerospike.client.cluster

Examples of com.aerospike.client.cluster.Connection


        // Execute command until successful, timed out or maximum iterations have been reached.
    while (true) {
      Node node = null;
      try {   
        node = getNode();
        Connection conn = node.getConnection(remainingMillis);
       
        try {
          // Reset timeout in send buffer (destined for server) and socket.
          Buffer.intToBytes(remainingMillis, sendBuffer, 22);
         
          // Send command.
          send(conn);
         
          // Parse results.
          parseResult(conn.getInputStream());
         
          // Reflect healthy status.
          conn.updateLastUsed();
          node.restoreHealth();
         
          // Put connection back in pool.
          node.putConnection(conn);
         
          // Command has completed successfully.  Exit method.
          return;
        }
        catch (AerospikeException ae) {
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
          throw ae;
        }
        catch (RuntimeException re) {
          // All runtime exceptions are considered fatal.  Do not retry.
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
          throw re;
        }
        catch (IOException ioe) {
          // IO errors are considered temporary anomalies.  Retry.
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
         
          if (Log.debugEnabled()) {
            Log.debug("Node " + node + ": " + Util.getErrorMessage(ioe));
          }
          // IO error means connection to server node is unhealthy.
View Full Code Here


   * @param name          name of value to retrieve
   * @return            info value
   */
  public static String request(InetSocketAddress socketAddress, String name)
    throws AerospikeException
    Connection conn = new Connection(socketAddress, DEFAULT_TIMEOUT);
   
    try {
      return request(conn, name);
    }
    finally {
      conn.close();
    }
  }
View Full Code Here

   * @param names          names of values to retrieve
   * @return            info name/value pairs
   */
  public static HashMap<String,String> request(InetSocketAddress socketAddress, String... names)
    throws AerospikeException {
    Connection conn = new Connection(socketAddress, DEFAULT_TIMEOUT);
   
    try {
      return request(conn, names);
    }
    finally {
      conn.close();
    }   
  }
View Full Code Here

   * @param socketAddress      <code>InetSocketAddress</code> of server node
   * @return            info name/value pairs
   */
  public static HashMap<String,String> request(InetSocketAddress socketAddress)
    throws AerospikeException {
    Connection conn = new Connection(socketAddress, DEFAULT_TIMEOUT);

    try {
      return request(conn);
    }
    finally {
      conn.close();
    }   
  }
View Full Code Here

   * @param name          name of value to retrieve
   * @return            info value
   */
  public static String request(Node node, String name)
    throws AerospikeException {
    Connection conn = node.getConnection(DEFAULT_TIMEOUT);
   
    try {
      String response = Info.request(conn, name);
      node.putConnection(conn);
      return response;
    }
    catch (AerospikeException ae) {
      conn.close();
      throw ae;
    }
    catch (RuntimeException re) {
      conn.close();
      throw re;
    }
  }
View Full Code Here

   
    // Send UDF to one node. That node will distribute the UDF to other nodes.
    String command = sb.toString();
    Node node = cluster.getRandomNode();
    int timeout = (policy == null)? 0 : policy.timeout;
    Connection conn = node.getConnection(timeout);
   
    try {     
      Info info = new Info(conn, command);
      NameValueParser parser = info.getNameValueParser();
     
      while (parser.next()) {
        String name = parser.getName();

        if (name.equals("error")) {
          throw new AerospikeException(serverPath + " registration failed: " + parser.getValue());
        }
      }
      node.putConnection(conn);
      return new RegisterTask(cluster, serverPath);
    }
    catch (AerospikeException ae) {
      conn.close();
      throw ae;
    }
    catch (RuntimeException re) {
      conn.close();
      throw new AerospikeException(re);
    }
  }
View Full Code Here

  }
 
  private String sendInfoCommand(Policy policy, String command) throws AerospikeException {   
    Node node = cluster.getRandomNode();
    int timeout = (policy == null)? 0 : policy.timeout;
    Connection conn = node.getConnection(timeout);
    Info info;
   
    try {
      info = new Info(conn, command);
      node.putConnection(conn);
    }
    catch (AerospikeException ae) {
      conn.close();
      throw ae;
    }
    catch (RuntimeException re) {
      conn.close();
      throw new AerospikeException(re);
    }
    return info.getValue();
  }
View Full Code Here

        // Execute command until successful, timed out or maximum iterations have been reached.
    while (true) {
      Node node = null;
      try {   
        node = getNode();
        Connection conn = node.getConnection(remainingMillis);
       
        try {
          // Set command buffer.
          writeBuffer();

          // Reset timeout in send buffer (destined for server) and socket.
          Buffer.intToBytes(remainingMillis, dataBuffer, 22);
         
          // Send command.
          conn.write(dataBuffer, dataOffset);
         
          // Parse results.
          parseResult(conn);
         
          // Reflect healthy status.
          conn.updateLastUsed();
          node.restoreHealth();
         
          // Put connection back in pool.
          node.putConnection(conn);
         
          // Command has completed successfully.  Exit method.
          return;
        }
        catch (AerospikeException ae) {
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
          throw ae;
        }
        catch (RuntimeException re) {
          // All runtime exceptions are considered fatal.  Do not retry.
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
          throw re;
        }
        catch (IOException ioe) {
          // IO errors are considered temporary anomalies.  Retry.
          // Close socket to flush out possible garbage.  Do not put back in pool.
          conn.close();
         
          if (Log.debugEnabled()) {
            Log.debug("Node " + node + ": " + Util.getErrorMessage(ioe));
          }
          // IO error means connection to server node is unhealthy.
View Full Code Here

   
    // Send UDF to one node. That node will distribute the UDF to other nodes.
    String command = sb.toString();
    Node node = cluster.getRandomNode();
    int timeout = (policy == null)? 0 : policy.timeout;
    Connection conn = node.getConnection(timeout);
   
    try {     
      Info info = new Info(conn, command);
      NameValueParser parser = info.getNameValueParser();
      String error = null;
      String file = null;
      String line = null;
      String message = null;
     
      while (parser.next()) {
        String name = parser.getName();

        if (name.equals("error")) {
          error = parser.getValue();
        }
        else if (name.equals("file")) {
          file = parser.getValue();       
        }
        else if (name.equals("line")) {
          line = parser.getValue();       
        }
        else if (name.equals("message")) {
          message = parser.getStringBase64();         
        }
      }
     
      if (error != null) {     
        throw new AerospikeException("Registration failed: " + error + Environment.Newline +
          "File: " + file + Environment.Newline +
          "Line: " + line + Environment.Newline +
          "Message: " + message
          );
      }
     
      node.putConnection(conn);
      return new RegisterTask(cluster, serverPath);
    }
    catch (AerospikeException ae) {
      conn.close();
      throw ae;
    }
    catch (RuntimeException re) {
      conn.close();
      throw new AerospikeException(re);
    }
  }
View Full Code Here

  }
 
  private String sendInfoCommand(Policy policy, String command) throws AerospikeException {   
    Node node = cluster.getRandomNode();
    int timeout = (policy == null)? 0 : policy.timeout;
    Connection conn = node.getConnection(timeout);
    Info info;
   
    try {
      info = new Info(conn, command);
      node.putConnection(conn);
    }
    catch (AerospikeException ae) {
      conn.close();
      throw ae;
    }
    catch (RuntimeException re) {
      conn.close();
      throw new AerospikeException(re);
    }
    return info.getValue();
  }
View Full Code Here

TOP

Related Classes of com.aerospike.client.cluster.Connection

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.