docs: private void write(ConsistencyLevel cl, int retryCount) {
  
      System.out.printf("Writing at %s (retry count: %d)%n", cl, retryCount);
  
      BatchStatement batch =
          BatchStatement.newInstance(UNLOGGED)
              .add(
                  SimpleStatement.newInstance(
                      "INSERT INTO downgrading.sensor_data "
                          + "(sensor_id, date, timestamp, value) "
                          + "VALUES ("
                          + "756716f7-2e54-4715-9f00-91dcbea6cf50,"
                          + "'2018-02-26',"
                          + "'2018-02-26T13:53:46.345+01:00',"
                          + "2.34)"))
              .add(
                  SimpleStatement.newInstance(
                      "INSERT INTO downgrading.sensor_data "
                          + "(sensor_id, date, timestamp, value) "
                          + "VALUES ("
                          + "756716f7-2e54-4715-9f00-91dcbea6cf50,"
                          + "'2018-02-26',"
                          + "'2018-02-26T13:54:27.488+01:00',"
                          + "2.47)"))
              .add(
                  SimpleStatement.newInstance(
                      "INSERT INTO downgrading.sensor_data "
                          + "(sensor_id, date, timestamp, value) "
                          + "VALUES ("
                          + "756716f7-2e54-4715-9f00-91dcbea6cf50,"
                          + "'2018-02-26',"
                          + "'2018-02-26T13:56:33.739+01:00',"
                          + "2.52)"))
              .setConsistencyLevel(cl);
  
      try {
  
        session.execute(batch);
        System.out.println("Write succeeded at " + cl);
  
      } catch (DriverException e) {
  
        if (retryCount == maxRetries) {
          throw e;
        }
  
        e = unwrapAllNodesFailedException(e);
  
        System.out.println("Write failed: " + e);
  
        // General intent:
        // 1) If we know the write has been fully persisted on at least one replica,
        // ignore the exception since the write will be eventually propagated to other replicas.
        // 2) If the write couldn't be persisted at all, abort as it is unlikely that a retry would
        // succeed.
        // 3) If the write was only partially persisted, retry at the highest consistency
        // level that is likely to succeed.
  
        if (e instanceof UnavailableException) {
  
          // With an UnavailableException, we know that the write wasn't even attempted.
          // Downgrade to the number of replicas reported alive and retry.
          int aliveReplicas = ((UnavailableException) e).getAlive();
  
          ConsistencyLevel downgraded = downgrade(cl, aliveReplicas, e);
          write(downgraded, retryCount + 1);
  
        } else if (e instanceof WriteTimeoutException) {
  
          DefaultWriteType writeType = (DefaultWriteType) ((WriteTimeoutException) e).getWriteType();
          int acknowledgements = ((WriteTimeoutException) e).getReceived();
  
          switch (writeType) {
            case SIMPLE:
            case BATCH:
              // For simple and batch writes, as long as one replica acknowledged the write,
              // ignore the exception; if none responded however, abort as it is unlikely that
              // a retry would ever succeed.
              if (acknowledgements == 0) {
                throw e;
              }
              break;
  
            case UNLOGGED_BATCH:
              // For unlogged batches, the write might have been persisted only partially,
              // so we can't simply ignore the exception: instead, we need to retry with
              // consistency level equal to the number of acknowledged writes.
              ConsistencyLevel downgraded = downgrade(cl, acknowledgements, e);
              write(downgraded, retryCount + 1);
              break;
  
            case BATCH_LOG:
              // Rare edge case: the peers that were chosen by the coordinator
              // to receive the distributed batch log failed to respond.
              // Simply retry with same consistency level.
              write(cl, retryCount + 1);
              break;
  
            default:
              // Other write types are uncommon and should not be retried.
              throw e;
          }
  
        } else {
  
          // Unexpected error: just retry with same consistency level
          // and hope to talk to a healthier coordinator.
          write(cl, retryCount + 1);
        }
      }
    }