public void checkConnections() {
    // First we check to see if we have at least 16 valid connections
    for (Connection c : this.connections) {
      if (!c.isValid()) {
        // Remove this connection
        this.connections.remove(c);

        // Add another connection
        // This is done in a separate thread so as to not disturb the
        // rest of the program
        Thread connectionFinder =
            new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    for (Connection c1 : getConnections()) {
                      if (c1.isValid()) {
                        addConnections(c1.getPeerList());
                      }
                    }
                  }
                });
        connectionFinder.start();
      }
    }
  }
Пример #2
0
 public boolean isConnectionValid() {
   try {
     return conn.isValid(0);
   } catch (SQLException e) {
     printSQLException(e);
     return false;
   }
 }
 protected Connection getConnection() {
   try {
     if (connection != null && connection.isValid(6)) return connection;
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return connection = createConnection();
 }
  /** @param peerList */
  public void addConnections(BigFastList<StringBuffer> peerList) {
    // Go through the peerList of a node we are directly connected to

    for (StringBuffer s : peerList) {
      // Create a new connection object
      Connection c = new Connection(s, this.getCurCoin());
      // Check if the connection can be established
      if (c.isValid() && !checkDuplicate(c)) {

        // Add a connection and break
        this.connections.add(c);
        // We break after only one successful connection is added to
        // ensure node diversity
        break;
      } // otherwise try with the next IP
    }
  }
Пример #5
0
 public boolean isValid(int i) throws SQLException {
   return conn.isValid(i);
 }