use of io.narayana.lra.annotation.TimeLimit in project narayana by jbosstm.
the class NarayanaLRAClient method getTerminationUris.
/**
* For particular compensator class it returns termination uris based on the provided base uri.
* You get map of string and url.
*
* @param compensatorClass compensator class to examine
* @param baseUri base url used on creation of the termination map.
* @return map of urls
*/
public static Map<String, String> getTerminationUris(Class<?> compensatorClass, URI baseUri) {
Map<String, String> paths = new HashMap<>();
final boolean[] asyncTermination = { false };
Annotation resourcePathAnnotation = compensatorClass.getAnnotation(Path.class);
String resourcePath = resourcePathAnnotation == null ? "" : ((Path) resourcePathAnnotation).value().replaceAll("^/+", "");
final String uriPrefix = String.format("%s:%s%s", baseUri.getScheme(), baseUri.getSchemeSpecificPart(), resourcePath).replaceAll("/$", "");
Arrays.stream(compensatorClass.getMethods()).forEach(method -> {
Annotation pathAnnotation = method.getAnnotation(Path.class);
if (pathAnnotation != null) {
if (checkMethod(paths, COMPENSATE, (Path) pathAnnotation, method.getAnnotation(Compensate.class), uriPrefix) != 0) {
TimeLimit timeLimit = method.getAnnotation(TimeLimit.class);
if (timeLimit != null)
paths.put(TIMELIMIT_PARAM_NAME, Long.toString(timeLimit.unit().toMillis(timeLimit.limit())));
if (isAsyncCompletion(method))
asyncTermination[0] = true;
}
if (checkMethod(paths, COMPLETE, (Path) pathAnnotation, method.getAnnotation(Complete.class), uriPrefix) != 0) {
if (isAsyncCompletion(method))
asyncTermination[0] = true;
}
checkMethod(paths, STATUS, (Path) pathAnnotation, method.getAnnotation(Status.class), uriPrefix);
checkMethod(paths, FORGET, (Path) pathAnnotation, method.getAnnotation(Forget.class), uriPrefix);
checkMethod(paths, LEAVE, (Path) pathAnnotation, method.getAnnotation(Leave.class), uriPrefix);
}
});
if (asyncTermination[0] && !paths.containsKey(STATUS) && !paths.containsKey(FORGET)) {
LRALogger.i18NLogger.error_asyncTerminationBeanMissStatusAndForget(compensatorClass);
throw new GenericLRAException(Response.Status.BAD_REQUEST.getStatusCode(), "LRA participant class with asynchronous temination but no @Status or @Forget annotations");
}
StringBuilder linkHeaderValue = new StringBuilder();
if (paths.size() != 0) {
paths.forEach((k, v) -> makeLink(linkHeaderValue, null, k, v));
paths.put("Link", linkHeaderValue.toString());
}
return paths;
}
use of io.narayana.lra.annotation.TimeLimit in project narayana by jbosstm.
the class ServerLRAFilter method getTimeOut.
private long getTimeOut(Method method) {
Annotation timeLimit = method.getDeclaredAnnotation(TimeLimit.class);
if (timeLimit == null)
timeLimit = method.getDeclaringClass().getDeclaredAnnotation(TimeLimit.class);
if (timeLimit == null)
return NarayanaLRAClient.DEFAULT_TIMEOUT_MILLIS;
TimeLimit tl = (TimeLimit) timeLimit;
return tl.unit().toMillis(tl.limit());
}
use of io.narayana.lra.annotation.TimeLimit in project narayana by jbosstm.
the class ActivityController method extendTimeLimit.
@GET
@Path("/renewTimeLimit")
@Produces(MediaType.APPLICATION_JSON)
@TimeLimit(limit = 100, unit = TimeUnit.MILLISECONDS)
@LRA(value = LRA.Type.REQUIRED)
public Response extendTimeLimit(@HeaderParam(LRA_HTTP_HEADER) String lraId) {
activityService.add(new Activity(NarayanaLRAClient.getLRAId(lraId)));
try {
/*
* the incomming LRA was created with a timeLimit of 100 ms via the @TimeLimit annotation
* update the timeLimit to 300
* sleep for 200
* return from the method so the LRA will have been running for 200 ms so it should not be cancelled
*/
lraClient.renewTimeLimit(NarayanaLRAClient.lraToURL(lraId), 300, TimeUnit.MILLISECONDS);
// sleep for 200000 micro seconds (should be longer than specified in the @TimeLimit annotation)
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
return Response.status(Response.Status.OK).entity(Entity.text("Simulate buisiness logic timeoout")).build();
}
Aggregations