本文整理汇总了Java中javax.ws.rs.sse.Sse类的典型用法代码示例。如果您正苦于以下问题:Java Sse类的具体用法?Java Sse怎么用?Java Sse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sse类属于javax.ws.rs.sse包,在下文中一共展示了Sse类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eventStream
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@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();
}
});
}
示例2: eventStream
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void eventStream(@Context Sse sse, @Context SseEventSink eventSink) {
// Resource method is invoked when a client subscribes to an event stream.
// That implies that sending events will most likely happen from different
// context - thread / event handler / etc, so common implementation of the
// resource method will store the eventSink instance and the application
// logic will retrieve it when an event should be emitted to the client.
// sending events:
eventSink.send(sse.newEvent("event1"));
}
示例3: subscribe
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@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();
}
示例4: fetch
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@GET
@Produces("text/event-stream")
public void fetch(@Context Sse sse, @Context SseEventSink eSink) {
OutboundSseEvent stringEvent = sse.newEventBuilder()
.name("stringEvent")
.data(new Date().toString()).build();
eSink.send(stringEvent);
OutboundSseEvent primitiveTypeEvent = sse.newEventBuilder()
.name("primitiveTypeEvent")
.data(System.currentTimeMillis()).build();
eSink.send(primitiveTypeEvent);
OutboundSseEvent jsonbType = sse.newEventBuilder()
.name("jsonbType")
.data(new Employee("[email protected]", "test", 42))
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.build();
eSink.send(jsonbType);
OutboundSseEvent jaxbType = sse.newEventBuilder()
.name("jaxbType")
.data(new Customer("[email protected]", "king"))
.mediaType(MediaType.APPLICATION_XML_TYPE)
.build();
eSink.send(jaxbType);
OutboundSseEvent customObjWithMBW = sse.newEventBuilder()
.name("customObjWithMBW")
.data(new Student("[email protected]", "stud-007")).build();
eSink.send(customObjWithMBW);
System.out.println("events sent");
eSink.close();
System.out.println("sink closed");
}
示例5: doSseCall
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@GET
@Path("/{uuid}")
@Produces(SERVER_SENT_EVENTS)
public void doSseCall(@PathParam("uuid") String uuid, @Context SseEventSink sink, @Context Sse sse) {
final OutboundSseEvent.Builder builder = sse.newEventBuilder();
OutboundSseEvent event = builder.id(uuid)
.data(SseModel.class, new SseModel("some model "+uuid))
.build();
sink.send(event);
sink.close();
}
示例6: SseRequest
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
public SseRequest(Sse sse, SseEventSink eventSink) {
this.sse = sse;
this.eventSink = eventSink;
}
示例7: getSse
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
public Sse getSse() {
return sse;
}
示例8: setSse
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
public void setSse(Sse sse) {
this.sse = sse;
}
示例9: eventStreamCdi
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void eventStreamCdi(@Context Sse sse, @Context SseEventSink eventSink) {
handler.register(UUID.randomUUID().toString(), new SseRequest(sse, eventSink));
}
示例10: SseEvent
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
public SseEvent(SseEventSink sink, Sse sse, String id) {
this.sink = sink;
this.sse = sse;
this.id = id;
}
示例11: onEvent
import javax.ws.rs.sse.Sse; //导入依赖的package包/类
@GET
@Path("{connectionId}")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void onEvent(@Context SseEventSink sink, @PathParam("connectionId") final String id, @Context Sse sse) {
event.fire(new SseEvent(sink, sse, id));
}