All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ldaptive.AbstractRetryMetadata Maven / Gradle / Ivy

There is a newer version: 2.4.1
Show newest version
/* See LICENSE for licensing and NOTICE for copyright. */
package org.ldaptive;

import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Common implementation of retry metadata.
 *
 * @author  Middleware Services
 */
public abstract class AbstractRetryMetadata implements RetryMetadata
{

  /** Time at which the last success occurred. */
  protected Instant successTime;

  /** Time at which the failure occurred. */
  protected Instant failureTime;

  /** Attempt count. */
  private final AtomicInteger attempts = new AtomicInteger();


  @Override
  public Instant getSuccessTime()
  {
    return successTime;
  }


  @Override
  public Instant getFailureTime()
  {
    return failureTime;
  }


  @Override
  public int getAttempts()
  {
    return attempts.get();
  }


  @Override
  public void recordSuccess(final Instant time)
  {
    successTime = time;
  }


  @Override
  public void recordFailure(final Instant time)
  {
    failureTime = time;
    attempts.incrementAndGet();
  }


  @Override
  public String toString()
  {
    return getClass().getName() + "@" + hashCode() + "::" +
      "attempts=" + attempts + ", " +
      "failureTime=" + failureTime;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy