protected final void schedule(final Object message, final long delay, final TimeUnit unit) { executor.schedule(() -> tell(message), delay, unit); }
protected final void schedule(final Object message, final long delay, final TimeUnit unit) { executor.schedule(() -> tell(message), delay, unit); }
protected final void schedule(final Object message, final long delay, final TimeUnit unit) { executor.schedule(() -> tell(message), delay, unit); }
protected final void schedule(final Object message, final long delay, final TimeUnit unit) { executor.schedule(() -> tell(message), delay, unit); }
private void tellSubscriberNewTokens(final Tokens tokens, final Actor subscriber) { subscriber.tell(new TokenDeliveredMessage(tokens)); }
private void tellSubscriberNewTokens(final Tokens tokens, final Actor subscriber) { subscriber.tell(new TokenDeliveredMessage(tokens)); }
private void requestUpdateFailedStatus(final Throwable error) { if (!currentTokensOption.isPresent()) { currentAccessTokenFuture.completeExceptionally(error); } else if (lastTokenIsStillValid()) { //keep the old token } else { currentTokensOption = Optional.empty(); currentAccessTokenFuture = CompletableFutureUtils.failed(error); } authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage());// }
private void requestUpdateFailedStatus(final Throwable error) { if (!currentTokensOption.isPresent()) { currentAccessTokenFuture.completeExceptionally(error); } else if (lastTokenIsStillValid()) { //keep the old token } else { currentTokensOption = Optional.empty(); currentAccessTokenFuture = CompletableFutureUtils.failed(error); } authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage());// }
@Override public <T> CompletableFuture<T> execute(final SphereRequest<T> sphereRequest) { final CompletableFuture<T> promiseForTheClient = new CompletableFuture<>(); final AsyncTask asyncTask = new AsyncTask(() -> { final CompletableFuture<T> realFuture = super.execute(sphereRequest); CompletableFutureUtils.transferResult(realFuture, promiseForTheClient); CompletableFutureUtils.transferResult(realFuture, promiseForTheClient); CompletableFuture<String> forHandlerFuture = new CompletableFuture<>(); realFuture.whenComplete((v, e) -> forHandlerFuture.complete("done")); return forHandlerFuture; }); actor.tell(asyncTask); return promiseForTheClient; }
private void process(final FailedTokenFetchMessage m) { isWaitingForToken = false; final boolean failReasonIsInvalidCredentials = m.cause.getCause() != null && m.cause.getCause() instanceof InvalidClientCredentialsException; if (failReasonIsInvalidCredentials) { AUTH_LOGGER.error(() -> "Can't fetch tokens due to invalid credentials.", m.cause); subscribers.forEach(subscriber -> subscriber.tell(new TokenDeliveryFailedMessage(m.cause))); } else { AUTH_LOGGER.error(() -> "Can't fetch tokens.", m.cause); final long tryAgainIn = m.attempt * DEFAULT_WAIT_TIME_UNTIL_RETRY_MILLISECONDS; schedule(new FetchTokenFromSphereMessage(m.attempt), tryAgainIn, MILLISECONDS); if (m.attempt > 2) { subscribers.forEach(subscriber -> subscriber.tell(new TokenDeliveryFailedMessage(m.cause))); } } }
@Override public <T> CompletionStage<T> execute(final SphereRequest<T> sphereRequest) { final CompletableFuture<T> promiseForTheClient = new CompletableFuture<>(); final AsyncTask asyncTask = new AsyncTask(() -> { final CompletionStage<T> realFuture = super.execute(sphereRequest); CompletableFutureUtils.transferResult(realFuture, promiseForTheClient); CompletableFuture<String> forHandlerFuture = new CompletableFuture<>(); realFuture.whenComplete((v, e) -> forHandlerFuture.complete("done")); return forHandlerFuture; }); actor.tell(asyncTask); return promiseForTheClient; }
@Override public <T> CompletionStage<T> execute(final SphereRequest<T> sphereRequest) { final CompletableFuture<T> promiseForTheClient = new CompletableFuture<>(); final AsyncTask asyncTask = new AsyncTask(() -> { final CompletionStage<T> realFuture = super.execute(sphereRequest); CompletableFutureUtils.transferResult(realFuture, promiseForTheClient); CompletableFuture<String> forHandlerFuture = new CompletableFuture<>(); realFuture.whenComplete((v, e) -> forHandlerFuture.complete("done")); return forHandlerFuture; }); actor.tell(asyncTask); return promiseForTheClient; }
@Override public <T> CompletionStage<T> execute(final SphereRequest<T> sphereRequest) { final CompletableFuture<T> promiseForTheClient = new CompletableFuture<>(); final AsyncTask asyncTask = new AsyncTask(() -> { final CompletionStage<T> realFuture = super.execute(sphereRequest); CompletableFutureUtils.transferResult(realFuture, promiseForTheClient); CompletableFuture<String> forHandlerFuture = new CompletableFuture<>(); realFuture.whenComplete((v, e) -> forHandlerFuture.complete("done")); return forHandlerFuture; }); actor.tell(asyncTask); return promiseForTheClient; }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { tokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(tokensSupplier, this::supervisedTokenSupplier, this::requestUpdateTokens, this::requestUpdateFailedStatus); authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); }
private void process(final FailedTokenFetchMessage m) { isWaitingForToken = false; AUTH_LOGGER.error(() -> "Can't fetch tokens.", m.cause); final long tryAgainIn = m.attempt * DEFAULT_WAIT_TIME_UNTIL_RETRY_MILLISECONDS; schedule(new FetchTokenFromSphereMessage(m.attempt), tryAgainIn, MILLISECONDS); if (m.attempt > 2) { subscribers.forEach(subscriber -> subscriber.tell(new TokenDeliveryFailedMessage(m.cause))); } }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { final TokensSupplier internalTokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(internalTokensSupplier); authActor.tell(new SubscribeMessage(tokenActor)); }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { tokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(tokensSupplier, this::supervisedTokenSupplier, this::requestUpdateTokens, this::requestUpdateFailedStatus); authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { final TokensSupplier internalTokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(internalTokensSupplier); authActor.tell(new SubscribeMessage(tokenActor)); }
@Override public CompletionStage<String> getNewToken() { authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); /* Two times a token will be fetched, once to update the cached token and the other time to get a new token to the caller. This way it minimizes the possibility of race conditions but is less effective. But this should be okay since it should be a rare case that his happens. */ return tokensSupplier.get().thenApplyAsync(tokens -> tokens.getAccessToken()); }
@Override public CompletionStage<String> getNewToken() { authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); /* Two times a token will be fetched, once to update the cached token and the other time to get a new token to the caller. This way it minimizes the possibility of race conditions but is less effective. But this should be okay since it should be a rare case that his happens. */ return tokensSupplier.get().thenApplyAsync(tokens -> tokens.getAccessToken()); }