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 Project: smallrye-fault-tolerance   Author: smallrye   File: DefaultFallbackHandlerProvider.java    License: 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 Project: quarkus   Author: quarkusio   File: QuarkusFallbackHandlerProvider.java    License: 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 Project: sample-acmegifts   Author: OpenLiberty   File: NotificationFallbackHandler.java    License: 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 Project: sample-acmegifts   Author: OpenLiberty   File: NotificationFallbackHandler.java    License: 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 Project: microprofile-fault-tolerance   Author: eclipse   File: FallbackMetricHandler.java    License: 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 Project: smallrye-fault-tolerance   Author: smallrye   File: FutureStringFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Future<String> handle(ExecutionContext executionContext) {
    return FALLBACK;
}
 
Example #7
Source Project: smallrye-fault-tolerance   Author: smallrye   File: StringFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback for " + context.getMethod().getName();
}
 
Example #8
Source Project: smallrye-fault-tolerance   Author: smallrye   File: MyFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext executionContext) {
    return FALLBACK;
}
 
Example #9
Source Project: quarkus   Author: quarkusio   File: FallbackBean.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return RecoverFallback.class.getName();
}
 
Example #10
Source Project: quarkus   Author: quarkusio   File: RestClientFallbackTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "pong";
}
 
Example #11
Source Project: quarkus   Author: quarkusio   File: AsyncRestClientFallbackTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public CompletionStage<String> handle(ExecutionContext context) {
    return completedFuture("pong");
}
 
Example #12
Source Project: microprofile-fault-tolerance   Author: eclipse   File: IncompatibleFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fourty-two";
}
 
Example #13
Source Project: microprofile-fault-tolerance   Author: eclipse   File: FallbackHandlerB.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "FallbackHandlerB";
}
 
Example #14
Source Project: microprofile-fault-tolerance   Author: eclipse   File: FallbackHandlerA.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
   return "FallbackHandlerA";
}
 
Example #15
Source Project: microprofile-fault-tolerance   Author: eclipse   File: StringFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback for " + context.getMethod().getName();
}
 
Example #16
Source Project: microprofile-fault-tolerance   Author: eclipse   File: StringFallbackHandlerWithBean.java    License: 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 #17
Source Project: microprofile-fault-tolerance   Author: eclipse   File: SecondStringFallbackHandler.java    License: 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 #18
Source Project: thorntail   Author: thorntail   File: DummyFallbackHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String handle(ExecutionContext context) {
    return "fallback";
}
 
Example #19
Source Project: tomee   Author: apache   File: WeatherDayStatusFallbackHandler.java    License: 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!";
}