• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SseEventSink类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.ws.rs.sse.SseEventSink的典型用法代码示例。如果您正苦于以下问题:Java SseEventSink类的具体用法?Java SseEventSink怎么用?Java SseEventSink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SseEventSink类属于javax.ws.rs.sse包,在下文中一共展示了SseEventSink类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: startDomain

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@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();
        }
    });
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:25,代码来源:ServerSentEventsResource.java


示例2: eventStream

import javax.ws.rs.sse.SseEventSink; //导入依赖的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();
        }
    });
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:21,代码来源:ServerSentEventsResource.java


示例3: eventStream

import javax.ws.rs.sse.SseEventSink; //导入依赖的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"));
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:13,代码来源:SseResource.java


示例4: subscribe

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@GET
@Path("subscribe")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void subscribe(@Context SseEventSink eventSink) {
    eventSink.send(sse.newEvent("You are subscribed"));
    broadcaster.register(eventSink);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:8,代码来源:SseResource.java


示例5: getMessageQueue

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:11,代码来源:ServerSentEventsResource.java


示例6: 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();
}
 
开发者ID:javaee-samples,项目名称:javaee8-applications,代码行数:16,代码来源:SSEResource.java


示例7: 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");
}
 
开发者ID:abhirockzz,项目名称:jaxrs-sse-mbw,代码行数:38,代码来源:EventsResource.java


示例8: itemEvents

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@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,代码行数:13,代码来源:EventsResource.java


示例9: replayLastMessages

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
private void replayLastMessages(int lastEventId, SseEventSink eventSink) {
    try {
        for (int i = lastEventId; i < messages.size(); i++) {
            eventSink.send(createEvent(messages.get(i), i + 1));
        }
    } catch (Exception e) {
        throw new InternalServerErrorException("Could not replay messages ", e);
    }
}
 
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:10,代码来源:EventsResource.java


示例10: deregister

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public void deregister(String uuid) {
    LOG.log(Level.INFO, "deregister request:{0}", uuid);
    SseRequest req = requests.remove(uuid);
    try (SseEventSink eventSink = req.getEventSink()) {
        eventSink.close();
    }
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:8,代码来源:MessageHandler.java


示例11: register

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@GET
//@Path("register")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void register(@Context SseEventSink eventSink) {
    eventSink.send(sse.newEvent("welcome!"));
    sseBroadcaster.register(eventSink);
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:8,代码来源:BroadcastResource.java


示例12: 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();
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:12,代码来源:SseEndpoint.java


示例13: subscribe

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
@Path("subscribe")
@GET
@Produces("text/event-stream")
public void subscribe(@Context SseEventSink eSink) {
    broadcaster.register(eSink);
}
 
开发者ID:abhirockzz,项目名称:accs-javaee8,代码行数:7,代码来源:EventsResource.java


示例14: register

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public void register(SseEventSink eventSink){
    broadcaster.register(eventSink);
    System.out.println("Registered Event sink");
}
 
开发者ID:abhirockzz,项目名称:accs-javaee8,代码行数:5,代码来源:Broadcaster.java


示例15: SseRequest

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public SseRequest(Sse sse, SseEventSink eventSink) {
    this.sse = sse;
    this.eventSink = eventSink;
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:5,代码来源:SseRequest.java


示例16: getEventSink

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public SseEventSink getEventSink() {
    return eventSink;
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:4,代码来源:SseRequest.java


示例17: setEventSink

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public void setEventSink(SseEventSink eventSink) {
    this.eventSink = eventSink;
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:4,代码来源:SseRequest.java


示例18: eventStreamCdi

import javax.ws.rs.sse.SseEventSink; //导入依赖的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));
}
 
开发者ID:hantsy,项目名称:ee8-sandbox,代码行数:6,代码来源:SseCdiResource.java


示例19: SseEvent

import javax.ws.rs.sse.SseEventSink; //导入依赖的package包/类
public SseEvent(SseEventSink sink, Sse sse, String id) {
    this.sink = sink;
    this.sse = sse;
    this.id = id;
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:6,代码来源:SseEvent.java


示例20: onEvent

import javax.ws.rs.sse.SseEventSink; //导入依赖的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));
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:7,代码来源:SseEventEndpoint.java



注:本文中的javax.ws.rs.sse.SseEventSink类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Configurable类代码示例发布时间:2022-05-23
下一篇:
Java Function类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap