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

org.testifyproject.failsafe.AsyncFailsafeConfig Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package org.testifyproject.failsafe;

import java.util.concurrent.ScheduledExecutorService;

import org.testifyproject.failsafe.event.ContextualResultListener;
import org.testifyproject.failsafe.function.CheckedBiConsumer;
import org.testifyproject.failsafe.function.CheckedConsumer;
import org.testifyproject.failsafe.util.concurrent.Scheduler;

/**
 * Async Failsafe configuration.
 * 

* Async execution event listeners are called asynchronously on the {@link Scheduler} or * {@link ScheduledExecutorService} associated with the Failsafe call. * * @author Jonathan Halterman * @param result type * @param failsafe type - {@link SyncFailsafe} or {@link AsyncFailsafe} */ @SuppressWarnings("unchecked") public class AsyncFailsafeConfig extends FailsafeConfig { final Scheduler scheduler; AsyncFailsafeConfig(FailsafeConfig config, Scheduler scheduler) { super(config); this.scheduler = scheduler; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution is aborted according to the retry policy. */ public F onAbortAsync(ContextualResultListener listener) { registry().abort().add(Listeners.of(listener, null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution is aborted according to the retry policy. */ public F onAbortAsync(CheckedConsumer listener) { registry().abort().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution is aborted according to the retry policy. */ public F onAbortAsync(CheckedBiConsumer listener) { registry().abort().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution is completed. */ public F onCompleteAsync(ContextualResultListener listener) { registry().complete().add(Listeners.of(listener, null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution is completed. */ public F onCompleteAsync(CheckedBiConsumer listener) { registry().complete().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failed execution attempt. */ public F onFailedAttemptAsync(ContextualResultListener listener) { registry().failedAttempt().add(Listeners.of(listener, null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failed execution attempt. */ public F onFailedAttemptAsync(CheckedConsumer listener) { registry().failedAttempt().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failed execution attempt. */ public F onFailedAttemptAsync(CheckedBiConsumer listener) { registry().failedAttempt().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failure occurs that cannot be retried. */ public F onFailureAsync(ContextualResultListener listener) { registry().failure().add(Listeners.of(listener, null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failure occurs that cannot be retried. */ public F onFailureAsync(CheckedConsumer listener) { registry().failure().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * failure occurs that cannot be retried. */ public F onFailureAsync(CheckedBiConsumer listener) { registry().failure().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution fails and the max retry attempts or duration are exceeded. */ public F onRetriesExceededAsync(CheckedConsumer listener) { registry().retriesExceeded().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler when an * execution fails and the max retry attempts or duration are exceeded. */ public F onRetriesExceededAsync(CheckedBiConsumer listener) { registry().retriesExceeded().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler before a * retry is attempted. */ public F onRetryAsync(ContextualResultListener listener) { registry().retry().add(Listeners.of(listener, null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler before a * retry is attempted. */ public F onRetryAsync(CheckedConsumer listener) { registry().retry().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler before a * retry is attempted. */ public F onRetryAsync(CheckedBiConsumer listener) { registry().retry().add(Listeners.of(Listeners.of(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * successful execution. */ public F onSuccessAsync(CheckedBiConsumer listener) { registry().success().add(Listeners.of(Listeners.ofResult(listener), null, scheduler)); return (F) this; } /** * Registers the {@code listener} to be called asynchronously on Failsafe's configured executor or Scheduler after a * successful execution. */ public F onSuccessAsync(CheckedConsumer listener) { registry().success().add(Listeners.of(Listeners.ofResult(listener), null, scheduler)); return (F) this; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy