本文整理汇总了Java中javax.ws.rs.core.MediaType.SERVER_SENT_EVENTS属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.SERVER_SENT_EVENTS属性的具体用法?Java MediaType.SERVER_SENT_EVENTS怎么用?Java MediaType.SERVER_SENT_EVENTS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.core.MediaType
的用法示例。
在下文中一共展示了MediaType.SERVER_SENT_EVENTS属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startDomain
@POST
@Path("domains/{id}")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void startDomain(@PathParam("id") final String id, @Context SseEventSink eventSink) {
executorService.submit(() -> {
try {
eventSink.send(sse.newEventBuilder().name("domain-progress").data(String.class, "starting domain " + id + " ...").build());
Thread.sleep(200);
eventSink.send(sse.newEvent("domain-progress", "50%"));
Thread.sleep(200);
eventSink.send(sse.newEvent("domain-progress", "60%"));
Thread.sleep(200);
eventSink.send(sse.newEvent("domain-progress", "70%"));
Thread.sleep(200);
eventSink.send(sse.newEvent("domain-progress", "99%"));
Thread.sleep(200);
eventSink.send(sse.newEvent("domain-progress", "Done."));
eventSink.close();
} catch (final InterruptedException e) {
e.printStackTrace();
}
});
}
示例2: eventStream
@POST
@Path("progress/{report_id}")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void eventStream(@PathParam("report_id") final String id,
@Context SseEventSink es,
@Context Sse sse) {
executorService.execute(() -> {
try {
eventSink.send(sse.newEventBuilder().name("report-progress")
.data(String.class, "Commencing process for report " + id + " ...").build());
es.send(sse.newEvent("Progress", "25%"));
Thread.sleep(500);
es.send(sse.newEvent("Progress", "50%"));
Thread.sleep(500);
es.send(sse.newEvent("Progress", "75%"));
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
示例3: index
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Observable<JsonObject> index(@Context AppGlobals globals){
UUID uuid = UUID.randomUUID();
Observable<JsonObject> consumer = (Observable<JsonObject>) globals.getGlobal("consumer");
Observable<JsonObject> ret = consumer
.buffer(1, TimeUnit.SECONDS)
.map((List<JsonObject> metrics) -> {
System.err.println("Metrics for "+uuid);
JsonObject dashboard = new JsonObject();
for (JsonObject metric : metrics) {
dashboard.mergeIn(metric);
}
return dashboard;
}).doOnUnsubscribe(() -> {
System.err.println("Unsub for "+uuid);
});
return ret;
}
示例4: subscribe
@GET
@Path("subscribe")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void subscribe(@Context SseEventSink eventSink) {
eventSink.send(sse.newEvent("You are subscribed"));
broadcaster.register(eventSink);
}
示例5: getMessageQueue
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void getMessageQueue(@Context SseEventSink eventSink) {
synchronized (outputLock) {
if (this.eventSink != null) {
throw new IllegalStateException("Server sink already served.");
}
this.eventSink = eventSink;
}
}
示例6: hello9
@Path("9")
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Observable<String> hello9(@Context io.vertx.rxjava.core.Vertx rxVertx){
System.err.println("Creating timer");
return rxVertx.periodicStream(1000).toObservable().map(r -> {
System.err.println("Tick: "+r);
return "Timer: "+System.currentTimeMillis();
});
}
示例7: subscribe
@GET
@Path("subscribe")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void subscribe(@Context SseEventSink eventSink,
@Context Sse sse){
eventSink.send(sse.newEvent("Welcome to the List!"));
eventSink.send(sse.newEvent("Message One!"));
eventSink.send(sse.newEvent("SERVER-NOTIFICATION", "Message Two!"));
eventSink.send(sse.newEventBuilder()
.comment("Nice Test")
.name("SERVER-TEST")
.data("Some data...could be an object")
.build());
eventSink.close();
}
示例8: itemEvents
@GET
@Lock(READ)
@Produces(MediaType.SERVER_SENT_EVENTS)
public void itemEvents(@HeaderParam(HttpHeaders.LAST_EVENT_ID_HEADER)
@DefaultValue("-1") int lastEventId,
@Context SseEventSink eventSink) {
if (lastEventId >= 0)
replayLastMessages(lastEventId, eventSink);
sseBroadcaster.register(eventSink);
}
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:12,代码来源:EventsResource.java