|
@@ -41,8 +41,8 @@ public class Service extends AbstractService {
|
|
}
|
|
}
|
|
|
|
|
|
@RestMapping(name = "cached-worlds")
|
|
@RestMapping(name = "cached-worlds")
|
|
- public CachedWorld[] cachedWorlds(int count) {
|
|
|
|
- final int size = Math.min(500, Math.max(1, count));
|
|
|
|
|
|
+ public CachedWorld[] cachedWorlds(int q) {
|
|
|
|
+ final int size = Math.min(500, Math.max(1, q));
|
|
final CachedWorld[] worlds = new CachedWorld[size];
|
|
final CachedWorld[] worlds = new CachedWorld[size];
|
|
for (int i = 0; i < size; i++) {
|
|
for (int i = 0; i < size; i++) {
|
|
worlds[i] = source.find(CachedWorld.class, randomId());
|
|
worlds[i] = source.find(CachedWorld.class, randomId());
|
|
@@ -55,9 +55,19 @@ public class Service extends AbstractService {
|
|
return source.findAsync(World.class, randomId());
|
|
return source.findAsync(World.class, randomId());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RestMapping(name = "fortunes")
|
|
|
|
+ public CompletableFuture<HttpResult<String>> queryFortunes() {
|
|
|
|
+ return source.queryListAsync(Fortune.class).thenApply((fortunes) -> {
|
|
|
|
+ fortunes.add(new Fortune(0, "Additional fortune added at request time."));
|
|
|
|
+ Collections.sort(fortunes);
|
|
|
|
+ String html = FortunesTemplate.template(fortunes).render().toString();
|
|
|
|
+ return new HttpResult("text/html; charset=UTF-8", html);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
@RestMapping(name = "queries")
|
|
@RestMapping(name = "queries")
|
|
- public CompletableFuture<World[]> queryWorldAsync(int queries) {
|
|
|
|
- final int size = Math.min(500, Math.max(1, queries));
|
|
|
|
|
|
+ public CompletableFuture<World[]> queryWorldAsync(int q) {
|
|
|
|
+ final int size = Math.min(500, Math.max(1, q));
|
|
final World[] worlds = new World[size];
|
|
final World[] worlds = new World[size];
|
|
final AtomicInteger index = new AtomicInteger();
|
|
final AtomicInteger index = new AtomicInteger();
|
|
final Function<?, CompletableFuture> func = f -> source.findAsync(World.class, randomId())
|
|
final Function<?, CompletableFuture> func = f -> source.findAsync(World.class, randomId())
|
|
@@ -70,8 +80,8 @@ public class Service extends AbstractService {
|
|
}
|
|
}
|
|
|
|
|
|
@RestMapping(name = "updates")
|
|
@RestMapping(name = "updates")
|
|
- public CompletableFuture<World[]> updateWorldAsync(int queries) {
|
|
|
|
- final int size = Math.min(500, Math.max(1, queries));
|
|
|
|
|
|
+ public CompletableFuture<World[]> updateWorldAsync(int q) {
|
|
|
|
+ final int size = Math.min(500, Math.max(1, q));
|
|
final World[] worlds = new World[size];
|
|
final World[] worlds = new World[size];
|
|
final AtomicInteger index = new AtomicInteger();
|
|
final AtomicInteger index = new AtomicInteger();
|
|
final Function<?, CompletableFuture> func = f -> source.findAsync(World.class, randomId())
|
|
final Function<?, CompletableFuture> func = f -> source.findAsync(World.class, randomId())
|
|
@@ -90,16 +100,6 @@ public class Service extends AbstractService {
|
|
}).thenApply(v -> worlds);
|
|
}).thenApply(v -> worlds);
|
|
}
|
|
}
|
|
|
|
|
|
- @RestMapping(name = "fortunes")
|
|
|
|
- public CompletableFuture<HttpResult<String>> queryFortunes() {
|
|
|
|
- return source.queryListAsync(Fortune.class).thenApply((fortunes) -> {
|
|
|
|
- fortunes.add(new Fortune(0, "Additional fortune added at request time."));
|
|
|
|
- Collections.sort(fortunes);
|
|
|
|
- String html = FortunesTemplate.template(fortunes).render().toString();
|
|
|
|
- return new HttpResult("text/html; charset=UTF-8", html);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private int randomId() {
|
|
private int randomId() {
|
|
return 1 + random.nextInt(10000);
|
|
return 1 + random.nextInt(10000);
|
|
}
|
|
}
|