当前位置: 首页>>代码示例>>Java>>正文


Java StopStrategies类代码示例

本文整理汇总了Java中com.github.rholder.retry.StopStrategies的典型用法代码示例。如果您正苦于以下问题:Java StopStrategies类的具体用法?Java StopStrategies怎么用?Java StopStrategies使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StopStrategies类属于com.github.rholder.retry包,在下文中一共展示了StopStrategies类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restore

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public void restore() {
  // Failing here means restarting the styx scheduler and replaying all events again. This is quite time consuming
  // and distressing when deploying, so try hard.
  final Retryer<Object> retryer = RetryerBuilder.newBuilder()
      .retryIfException()
      .withWaitStrategy(WaitStrategies.exponentialWait(10, TimeUnit.SECONDS))
      .withStopStrategy(StopStrategies.stopAfterAttempt(10))
      .withRetryListener(this::onRestorePollPodsAttempt)
      .build();

  try {
    retryer.call(Executors.callable(this::tryPollPods));
  } catch (ExecutionException | RetryException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:18,代码来源:KubernetesDockerRunner.java

示例2: executeFunctionWithRetrying

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private String executeFunctionWithRetrying(Callable<String> callable) throws RetryException, ExecutionException {
    try {
        Retryer<String> retryer = RetryerBuilder.<String>newBuilder()
                .retryIfExceptionOfType(TemporaryWriteException.class)
                .withRetryListener(retryLogger)
                .withWaitStrategy(WaitStrategies.exponentialWait(100, 5, TimeUnit.MINUTES))
                .withStopStrategy(StopStrategies.stopAfterAttempt(MAX_RETRY))
                .build();

        return retryer.call(callable);
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw e;
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:20,代码来源:GraqlController.java

示例3: execute

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public <T> Future<T> execute(final PowerBiOperation<T> val) {
    // use a retryer to keep attempting to send data to powerBI if we receive a rate limit exception.
    // use exponential backoff to create a window of time for the request to come through.

    // TODO : the time to wait is actually in the response header, come back and add that value.
    final Retryer<T> retryer = RetryerBuilder.<T>newBuilder()
            // we are retrying on these exceptions because they are able to be handled by just retrying this callable
            // again (assuming that the maximum retries value is greater than 1 and this isn't the last retry attempt
            // before giving up.
            .retryIfExceptionOfType(RateLimitExceededException.class)
            .retryIfExceptionOfType(RequestAuthenticationException.class)
            .withAttemptTimeLimiter(AttemptTimeLimiters.<T>fixedTimeLimit(maximumWaitTime, TimeUnit.MILLISECONDS))
            .withStopStrategy(StopStrategies.stopAfterAttempt(maximumRetries))
            .build();

    return executor.submit(new Callable<T>() {
        @Override
        public T call() throws Exception {
            return retryer.call(new PowerBiCallable<>(val, clientBuilder));
        }
    });
}
 
开发者ID:satalyst,项目名称:powerbi-rest-java,代码行数:24,代码来源:DefaultPowerBiConnection.java

示例4: ensureRebuiltRetryer

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private Retryer<NoteDbChangeState> ensureRebuiltRetryer(Stopwatch sw) {
  if (testEnsureRebuiltRetryer != null) {
    return testEnsureRebuiltRetryer;
  }
  // Retry the ensureRebuilt step with backoff until half the timeout has
  // expired, leaving the remaining half for the rest of the steps.
  long remainingNanos = (MILLISECONDS.toNanos(timeoutMs) / 2) - sw.elapsed(NANOSECONDS);
  remainingNanos = Math.max(remainingNanos, 0);
  return RetryerBuilder.<NoteDbChangeState>newBuilder()
      .retryIfException(e -> (e instanceof IOException) || (e instanceof OrmException))
      .withWaitStrategy(
          WaitStrategies.join(
              WaitStrategies.exponentialWait(250, MILLISECONDS),
              WaitStrategies.randomWait(50, MILLISECONDS)))
      .withStopStrategy(StopStrategies.stopAfterDelay(remainingNanos, NANOSECONDS))
      .build();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:PrimaryStorageMigrator.java

示例5: migrateToNoteDbFailsRebuildingOnceAndRetries

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void migrateToNoteDbFailsRebuildingOnceAndRetries() throws Exception {
  Change.Id id = createChange().getChange().getId();

  Change c = db.changes().get(id);
  c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
  db.changes().update(Collections.singleton(c));
  rebuilderWrapper.failNextUpdate();

  migrator =
      newMigrator(
          RetryerBuilder.<NoteDbChangeState>newBuilder()
              .retryIfException()
              .withStopStrategy(StopStrategies.neverStop())
              .build());
  migrator.migrateToNoteDbPrimary(id);
  assertNoteDbPrimary(id);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:19,代码来源:NoteDbPrimaryIT.java

示例6: migrateToNoteDbFailsRebuildingAndStops

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void migrateToNoteDbFailsRebuildingAndStops() throws Exception {
  Change.Id id = createChange().getChange().getId();

  Change c = db.changes().get(id);
  c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
  db.changes().update(Collections.singleton(c));
  rebuilderWrapper.failNextUpdate();

  migrator =
      newMigrator(
          RetryerBuilder.<NoteDbChangeState>newBuilder()
              .retryIfException()
              .withStopStrategy(StopStrategies.stopAfterAttempt(1))
              .build());
  exception.expect(OrmException.class);
  exception.expectMessage("Retrying failed");
  migrator.migrateToNoteDbPrimary(id);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:NoteDbPrimaryIT.java

示例7: failAfterRetryerGivesUp

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void failAfterRetryerGivesUp() throws Exception {
  AtomicInteger bgCounter = new AtomicInteger(1234);
  RepoSequence s =
      newSequence(
          "id",
          1,
          10,
          () -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))),
          RetryerBuilder.<RefUpdate.Result>newBuilder()
              .withStopStrategy(StopStrategies.stopAfterAttempt(3))
              .build());
  exception.expect(OrmException.class);
  exception.expectMessage("failed to update refs/sequences/id: LOCK_FAILURE");
  s.next();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:RepoSequenceTest.java

示例8: increaseToFailAfterRetryerGivesUp

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void increaseToFailAfterRetryerGivesUp() throws Exception {
  AtomicInteger bgCounter = new AtomicInteger(1234);
  RepoSequence s =
      newSequence(
          "id",
          1,
          10,
          () -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))),
          RetryerBuilder.<RefUpdate.Result>newBuilder()
              .withStopStrategy(StopStrategies.stopAfterAttempt(3))
              .build());
  exception.expect(OrmException.class);
  exception.expectMessage("failed to update refs/sequences/id: LOCK_FAILURE");
  s.increaseTo(2);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:RepoSequenceTest.java

示例9: createRemoteConnection

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public RemoteConnection createRemoteConnection(String remoteAddress, RemoteType remoteType,
    LoginCredential loginCredential, int port) {

  Callable<RemoteConnection> callable = () -> remoteConnectionFactory
      .createRemoteConnection(remoteAddress, remoteType, loginCredential, port);

  Retryer<RemoteConnection> remoteConnectionRetryer =
      RetryerBuilder.<RemoteConnection>newBuilder().retryIfRuntimeException()
          .retryIfException(throwable -> throwable instanceof RemoteException)
          .withStopStrategy(StopStrategies.stopAfterAttempt(connectionRetries))
          .withWaitStrategy(WaitStrategies
              .exponentialWait(exponentialMultiplier, exponentialMaxTime, TimeUnit.SECONDS))
          .build();

  try {
    return remoteConnectionRetryer.call(callable);
  } catch (ExecutionException | RetryException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:22,代码来源:RetryingConnectionFactory.java

示例10: BaseJdbcBufferedInserter

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public BaseJdbcBufferedInserter(State state, Connection conn) {
  this.conn = conn;
  this.batchSize = state.getPropAsInt(WRITER_JDBC_INSERT_BATCH_SIZE, DEFAULT_WRITER_JDBC_INSERT_BATCH_SIZE);
  if (this.batchSize < 1) {
    throw new IllegalArgumentException(WRITER_JDBC_INSERT_BATCH_SIZE + " should be a positive number");
  }

  int maxWait = state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_TIMEOUT, DEFAULT_WRITER_JDBC_INSERT_RETRY_TIMEOUT);
  int maxAttempts =
      state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT, DEFAULT_WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT);

  //retry after 2, 4, 8, 16... sec, allow at most maxWait sec delay
  this.retryer = RetryerBuilder.<Boolean> newBuilder().retryIfException()
      .withWaitStrategy(WaitStrategies.exponentialWait(1000, maxWait, TimeUnit.SECONDS))
      .withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)).build();
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:17,代码来源:BaseJdbcBufferedInserter.java

示例11: createRetryBuilder

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
/**
 * @return RetryerBuilder that retries on all exceptions except NonTransientException with exponential back off
 */
public static RetryerBuilder<Void> createRetryBuilder(State state) {
  Predicate<Throwable> transients = new Predicate<Throwable>() {
    @Override
    public boolean apply(Throwable t) {
      return !(t instanceof NonTransientException);
    }
  };

  long multiplier = state.getPropAsLong(RETRY_MULTIPLIER, 500L);
  long maxWaitMsPerInterval = state.getPropAsLong(RETRY_MAX_WAIT_MS_PER_INTERVAL, 10000);
  int maxAttempts = state.getPropAsInt(RETRY_MAX_ATTEMPTS, 5);
  return RetryerBuilder.<Void> newBuilder()
      .retryIfException(transients)
      .withWaitStrategy(WaitStrategies.exponentialWait(multiplier, maxWaitMsPerInterval, TimeUnit.MILLISECONDS)) //1, 2, 4, 8, 16 seconds delay
      .withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)); //Total 5 attempts and fail.
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:20,代码来源:RetryWriter.java

示例12: mock

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public static void mock() {
    Waits.setInstance(new Wait() {
        @Override
        public void time(Duration waitTime) {
            // don't wait
        }

        @Override
        @SuppressWarnings("unchecked")
        protected <T> Retryer<T> getRetryer(Predicate<? super T> predicate, Duration timeout, Duration interval) {
            int numRetries = (int) (timeout.getTime() / interval.getTime());
            // we emulate the number of retries
            return RetryerBuilder.<T> newBuilder()
                    .retryIfResult(Predicates.not((Predicate<T>) predicate))
                    .retryIfRuntimeException()
                    .withWaitStrategy(WaitStrategies.noWait())
                    .withStopStrategy(StopStrategies.stopAfterAttempt(numRetries))
                    .build();
        }
    });
}
 
开发者ID:viltgroup,项目名称:minium,代码行数:22,代码来源:WaitMocks.java

示例13: SingularityClient

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public SingularityClient(String contextPath, HttpClient httpClient, Provider<List<String>> hostsProvider, Optional<SingularityClientCredentials> credentials, boolean ssl, int retryAttempts, Predicate<HttpResponse> retryStrategy) {
  this.httpClient = httpClient;
  this.contextPath = contextPath;

  this.hostsProvider = hostsProvider;
  this.random = new Random();

  this.credentials = credentials;
  this.ssl = ssl;

  this.httpResponseRetryer = RetryerBuilder.<HttpResponse>newBuilder()
      .withStopStrategy(StopStrategies.stopAfterAttempt(retryAttempts))
      .withWaitStrategy(WaitStrategies.exponentialWait())
      .retryIfResult(retryStrategy::test)
      .retryIfException()
      .build();
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:18,代码来源:SingularityClient.java

示例14: notifyService

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public void notifyService(String action) throws Exception {
  long start = System.currentTimeMillis();
  Retryer<AgentCheckInResponse> retryer = RetryerBuilder.<AgentCheckInResponse>newBuilder()
      .retryIfException()
      .withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxNotifyServiceAttempts()))
      .withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
      .build();

  AgentCheckInResponse agentCheckInResponse = retryer.call(checkInCallable(action, false));
  while ((agentCheckInResponse.getState() != TrafficSourceState.DONE
      && System.currentTimeMillis() - start < configuration.getAgentCheckInTimeoutMs())) {
    try {
      Thread.sleep(agentCheckInResponse.getWaitTime());
    } catch (InterruptedException ie) {
      LOG.error("Interrupted waiting for check in with service, shutting down early");
      break;
    }
    agentCheckInResponse = retryer.call(checkInCallable(action, true));
  }
  LOG.info("Finished agent check in");
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:22,代码来源:LifecycleHelper.java

示例15: getGlobalStateWithRetry

import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private Collection<BaragonServiceState> getGlobalStateWithRetry() throws AgentServiceNotifyException {
  Callable<Collection<BaragonServiceState>> callable = new Callable<Collection<BaragonServiceState>>() {
    public Collection<BaragonServiceState> call() throws Exception {
      return getGlobalState();
    }
  };

  Retryer<Collection<BaragonServiceState>> retryer = RetryerBuilder.<Collection<BaragonServiceState>>newBuilder()
      .retryIfException()
      .withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxGetGloablStateAttempts()))
      .withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
      .build();

  try {
    return retryer.call(callable);
  } catch (Exception e) {
    LOG.error("Could not get global state from Baragon Service");
    throw Throwables.propagate(e);
  }
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:21,代码来源:LifecycleHelper.java


注:本文中的com.github.rholder.retry.StopStrategies类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。