-
Notifications
You must be signed in to change notification settings - Fork 1
/
SlowRest.java
48 lines (37 loc) · 1.14 KB
/
SlowRest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.zandero.rest.example.rest;
import com.zandero.rest.annotation.ResponseWriter;
import com.zandero.rest.example.service.SlowService;
import com.zandero.rest.writer.GenericResponseWriter;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import static com.zandero.rest.example.ServerVerticle.API_ROOT;
/**
* Slow working rest for simulation purposes only
*/
@Path(API_ROOT + "/slow")
public class SlowRest {
private SlowService slowService;
@Inject
public SlowRest(SlowService injectedSlow) {
slowService = injectedSlow;
}
@GET
@Path("down/{time}")
public int slowDown(@PathParam("time") int time) {
slowService.wait(time);
return time;
}
@GET
@Path("async/{time}")
@ResponseWriter(GenericResponseWriter.class)
public Promise<String> async(@Context Vertx vertx, @PathParam("time") int time) {
Promise<String> future = Promise.promise();
slowService.async(vertx, future, time);
return future;
}
}