当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.SERVER_SENT_EVENTS属性代码示例

本文整理汇总了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();
        }
    });
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:24,代码来源:ServerSentEventsResource.java

示例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();
        }
    });
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:20,代码来源:ServerSentEventsResource.java

示例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;
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:KafkaResource.java

示例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);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:7,代码来源:SseResource.java

示例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;
    }
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:10,代码来源:ServerSentEventsResource.java

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

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

示例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


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