本文整理汇总了Java中javax.ws.rs.sse.SseEventSink.close方法的典型用法代码示例。如果您正苦于以下问题:Java SseEventSink.close方法的具体用法?Java SseEventSink.close怎么用?Java SseEventSink.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.sse.SseEventSink
的用法示例。
在下文中一共展示了SseEventSink.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribe
import javax.ws.rs.sse.SseEventSink; //导入方法依赖的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();
}
示例2: fetch
import javax.ws.rs.sse.SseEventSink; //导入方法依赖的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");
}
示例3: doSseCall
import javax.ws.rs.sse.SseEventSink; //导入方法依赖的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();
}