|
@@ -55,7 +55,6 @@ public class Application extends Controller {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static Result json() {
|
|
|
final ObjectNode result = OBJECT_MAPPER.createObjectNode();
|
|
|
result.put("message", "Hello World!");
|
|
@@ -64,34 +63,34 @@ public class Application extends Controller {
|
|
|
|
|
|
@Predicated(predicate = IsDbAvailable.class, failed = SERVICE_UNAVAILABLE)
|
|
|
public static Result db(final Integer queries) {
|
|
|
- return async(
|
|
|
- future(new Callable<Result>() {
|
|
|
- @Override
|
|
|
- public Result call() {
|
|
|
- final Random random = ThreadLocalRandom.current();
|
|
|
- final List<F.Promise<? extends World>> promises = new ArrayList<F.Promise<? extends World>>(queries);
|
|
|
- for (int i = 0; i < queries; ++i) {
|
|
|
- // There's no convenience method for submitting a future on an EC in Java. There is
|
|
|
- // an issue that will address this though: https://github.com/playframework/Play20/issues/972
|
|
|
- // Meanwhile we call the Akka future directly and wrap its result in a promise.
|
|
|
- final F.Promise p = Akka.asPromise(Futures.future(
|
|
|
- findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
|
|
|
- promises.add(p);
|
|
|
- }
|
|
|
- final List<World> worlds = F.Promise.sequence(promises).get();
|
|
|
- return ok(Json.toJson(worlds));
|
|
|
- }
|
|
|
-
|
|
|
- private Callable<World> findWorld(final Long id) {
|
|
|
- return new Callable<World>() {
|
|
|
- @Override
|
|
|
- public World call() {
|
|
|
- return World.find.byId(id);
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
- })
|
|
|
- );
|
|
|
+ final Random random = ThreadLocalRandom.current();
|
|
|
+ final List<F.Promise<? extends World>> promises = new ArrayList<F.Promise<? extends World>>(queries);
|
|
|
+ for (int i = 0; i < queries; ++i) {
|
|
|
+ // There's no convenience method for submitting a future on an EC in Java. There is
|
|
|
+ // an issue that will address this though: https://github.com/playframework/Play20/issues/972
|
|
|
+ // Meanwhile we call the Akka future directly and wrap its result in a promise.
|
|
|
+ final F.Promise p = Akka.asPromise(Futures.future(
|
|
|
+ findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
|
|
|
+ promises.add(p);
|
|
|
+ }
|
|
|
+ return async(F.Promise.sequence(promises).map(new F.Function<List<World>, Result>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result apply(List<World> worlds) {
|
|
|
+ return ok(Json.toJson(worlds));
|
|
|
+ }
|
|
|
+
|
|
|
+ }));
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private static Callable<World> findWorld(final Long id) {
|
|
|
+ return new Callable<World>() {
|
|
|
+ @Override
|
|
|
+ public World call() {
|
|
|
+ return World.find.byId(id);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
}
|