org.eclipse.microprofile.faulttolerance.ExecutionContext Java Examples

The following examples show how to use org.eclipse.microprofile.faulttolerance.ExecutionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultFallbackHandlerProvider.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Override
public <T> FallbackHandler<T> get(FaultToleranceOperation operation) {
    if (operation.hasFallback()) {
        //noinspection Convert2Lambda
        return new FallbackHandler<T>() {
            @Override
            public T handle(ExecutionContext context) {
                Unmanaged<FallbackHandler<T>> unmanaged = new Unmanaged<>(beanManager,
                        operation.getFallback().get(FallbackConfig.VALUE));
                Unmanaged.UnmanagedInstance<FallbackHandler<T>> unmanagedInstance = unmanaged.newInstance();
                FallbackHandler<T> handler = unmanagedInstance.produce().inject().postConstruct().get();
                try {
                    return handler.handle(context);
                } finally {
                    // The instance exists to service a single invocation only
                    unmanagedInstance.preDestroy().dispose();
                }
            }
        };
    }
    return null;
}
 
Example #2
Source File: QuarkusFallbackHandlerProvider.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public <T> FallbackHandler<T> get(FaultToleranceOperation operation) {
    if (operation.hasFallback()) {
        return new FallbackHandler<T>() {
            @SuppressWarnings("unchecked")
            @Override
            public T handle(ExecutionContext context) {
                Class<? extends FallbackHandler<?>> clazz = operation.getFallback().get(FallbackConfig.VALUE);
                FallbackHandler<T> fallbackHandlerInstance = (FallbackHandler<T>) instance.select(clazz).get();
                try {
                    return fallbackHandlerInstance.handle(context);
                } finally {
                    // The instance exists to service a single invocation only
                    instance.destroy(fallbackHandlerInstance);
                }
            }
        };
    }
    return null;
}
 
Example #3
Source File: NotificationFallbackHandler.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public OccasionResponse handle(ExecutionContext context) {

  Object[] connectParameters = context.getParameters();
  String message = (String) connectParameters[0];
  Orchestrator orchestrator = (Orchestrator) connectParameters[1];
  String jwtTokenString = (String) connectParameters[2];
  String notification11ServiceUrl = (String) connectParameters[3];
  String twitterRecepientHandle = (String) connectParameters[4];

  JsonObjectBuilder content = Json.createObjectBuilder();
  content.add(JSON_KEY_TWITTER_HANDLE, twitterRecepientHandle);
  content.add(JSON_KEY_TWITTER_NOTIF_MODE, JSON_KEY_TWITTER_NOTIF_MODE_POST_MENTION);
  content.add(JSON_KEY_MESSAGE, message);
  JsonObjectBuilder notification = Json.createObjectBuilder();
  notification.add(JSON_KEY_NOTIFICATION, content.build());
  String payload = notification.build().toString();

  Response notificationResponse = null;
  try {
    notificationResponse =
        orchestrator.makeConnection("POST", notification11ServiceUrl, payload, jwtTokenString);
  } catch (IOException e) {
    e.printStackTrace();
  }
  OccasionResponse occasionResponse =
      new OccasionResponse(notificationResponse, OccasionResponse.NOTIFICATION_TYPE_TWEET, null);
  return occasionResponse;
}
 
Example #4
Source File: NotificationFallbackHandler.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
  Object[] tweetParameters = context.getParameters();
  String message = (String) tweetParameters[0];
  Logger fbLogger = (Logger) tweetParameters[2];
  fbLogger.info(message);
  return null;
}
 
Example #5
Source File: FallbackMetricHandler.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public Void handle(ExecutionContext context) {
    if (fallbackBean.getFallbackAction() == Action.PASS) {
        return null;
    }
    else if (fallbackBean.getFallbackAction() == Action.FAIL){
        throw new TestException();
    }
    else {
        throw new NonFallbackException();
    }
}
 
Example #6
Source File: WeatherDayStatusFallbackHandler.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext executionContext) {
    LOGGER.log(Level.SEVERE, "Fallback was triggered due a fail");
    return "Hi, today is a sunny day!";
}
 
Example #7
Source File: FutureStringFallbackHandler.java    From smallrye-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public Future<String> handle(ExecutionContext executionContext) {
    return FALLBACK;
}
 
Example #8
Source File: DummyFallbackHandler.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback";
}
 
Example #9
Source File: SecondStringFallbackHandler.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "second fallback for " + context.getMethod().getName() + context.getFailure().getClass().getName();
}
 
Example #10
Source File: StringFallbackHandlerWithBean.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback for " + context.getMethod().getName() + " myBean.getCount()=" + myBean.getCount();
}
 
Example #11
Source File: StringFallbackHandler.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback for " + context.getMethod().getName();
}
 
Example #12
Source File: FallbackHandlerA.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
   return "FallbackHandlerA";
}
 
Example #13
Source File: FallbackHandlerB.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "FallbackHandlerB";
}
 
Example #14
Source File: IncompatibleFallbackHandler.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fourty-two";
}
 
Example #15
Source File: AsyncRestClientFallbackTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public CompletionStage<String> handle(ExecutionContext context) {
    return completedFuture("pong");
}
 
Example #16
Source File: RestClientFallbackTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "pong";
}
 
Example #17
Source File: FallbackBean.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return RecoverFallback.class.getName();
}
 
Example #18
Source File: MyFallbackHandler.java    From smallrye-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext executionContext) {
    return FALLBACK;
}
 
Example #19
Source File: StringFallbackHandler.java    From smallrye-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback for " + context.getMethod().getName();
}