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


Java SseEmitter.onCompletion方法代码示例

本文整理汇总了Java中org.springframework.web.servlet.mvc.method.annotation.SseEmitter.onCompletion方法的典型用法代码示例。如果您正苦于以下问题:Java SseEmitter.onCompletion方法的具体用法?Java SseEmitter.onCompletion怎么用?Java SseEmitter.onCompletion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.servlet.mvc.method.annotation.SseEmitter的用法示例。


在下文中一共展示了SseEmitter.onCompletion方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResults

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@GetMapping("/api/notification/feed")
public ResponseEntity<SseEmitter> getResults() {

	if(sseEngine==null){
		LOGGER.warn(()->"No SSE Engine available");
		return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
	}

	final Long fLoggedInUserId = getLoggedInUserId();
	SseEmitter emitter = sseEngine.getEmitters().get(fLoggedInUserId);
	if (emitter == null) {
		LOGGER.debug(() -> "Creating new emitter");
		SseEmitter fEmitter = emitter = new SseEmitter();

		emitter.onCompletion(() -> {
			LOGGER.debug(() -> "Emitter completed");
			sseEngine.getEmitters().remove(fLoggedInUserId);
		});
		emitter.onTimeout(() -> {
			fEmitter.complete();
		});

		sseEngine.getEmitters().put(fLoggedInUserId, emitter);
	}
	return new ResponseEntity<>(emitter, HttpStatus.OK);
}
 
开发者ID:howma03,项目名称:sporticus,代码行数:27,代码来源:RestControllerPushImplSse.java

示例2: progress

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@GetMapping("/progress/{name}")
SseEmitter progress(@PathVariable String name) {
    UUID key = UUID.fromString(name);
    SseEmitter emitter = new SseEmitter();
    progress.addListener(key, a -> {
        try {
            emitter.send(a);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        if (a >= 1) {
            emitter.complete();
        }
    });
    emitter.onCompletion(() -> progress.removeListener(key));
    return emitter;
}
 
开发者ID:backpaper0,项目名称:spring-boot-sandbox,代码行数:18,代码来源:ProgressSampleApplication.java

示例3: updateHTML

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@RequestMapping("/userPriv/updates")
SseEmitter updateHTML() {
	SseEmitter sseEmitter = new SseEmitter();
	synchronized (this.sseEmitters) {
		this.sseEmitters.add(sseEmitter);
		sseEmitter.onCompletion(() -> {
			synchronized (this.sseEmitters) {
				this.sseEmitters.remove(sseEmitter);
			}
		});
	}
	return sseEmitter;
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:14,代码来源:ControladorHTML.java

示例4: streamTweets

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@RequestMapping("/tweetLocation")
public SseEmitter streamTweets() throws InterruptedException{
	
	SseEmitter sseEmitter = new SseEmitter();
	emitters.add(sseEmitter);
	sseEmitter.onCompletion(() -> emitters.remove(sseEmitter));
	
	streamTweetEventService.streamTweetEvent(emitters);
	
	return sseEmitter;
}
 
开发者ID:RawSanj,项目名称:spring-twitter-stream,代码行数:12,代码来源:WebSocketEventController.java

示例5: emit

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
private SseEmitter emit(Route route, Message<Collection<Object>> message)
		throws IOException {
	SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
	String path = route.getPath();
	if (!emitters.containsKey(path)) {
		emitters.putIfAbsent(path, new HashSet<>());
	}
	emitters.get(path).add(emitter);
	emitter.onCompletion(() -> emitters.get(path).remove(emitter));
	emitter.onTimeout(() -> emitters.get(path).remove(emitter));
	for (Object body : message.getPayload()) {
		emitter.send(body);
	}
	return emitter;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-function,代码行数:16,代码来源:MessageController.java

示例6: subscribeUpdates

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@RequestMapping("/sse/updates")
SseEmitter subscribeUpdates() {
	SseEmitter sseEmitter = new SseEmitter();
	synchronized (this.sseEmitters) {
		this.sseEmitters.add(sseEmitter);
		sseEmitter.onCompletion(() -> {
			synchronized (this.sseEmitters) {
				this.sseEmitters.remove(sseEmitter);
			}
		});
	}
	return sseEmitter;
}
 
开发者ID:sdeleuze,项目名称:spring-react-isomorphic,代码行数:14,代码来源:CommentController.java

示例7: serverSideEmitter

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@GetMapping(value = "/emitter/{dashboardId}")
public SseEmitter serverSideEmitter(@PathVariable String dashboardId) throws IOException {

    LOGGER.info("Creating SseEmitter for dashboard {}", dashboardId);

    SseEmitter sseEmitter = new NotCachedSseEmitter();

    sseEmitter.onCompletion(() -> {
        handler.removeFromSessionsMap(sseEmitter, dashboardId);
        sseEmitter.complete();
    });

    sseEmitter.onTimeout(() -> {
        handler.removeFromSessionsMap(sseEmitter, dashboardId);
        sseEmitter.complete();
    });

    handler.addToSessionsMap(sseEmitter, dashboardId);

    sseEmitter.send(SseEmitter.event().reconnectTime(0L));

    return sseEmitter;

}
 
开发者ID:BBVA,项目名称:mirrorgate,代码行数:25,代码来源:ServerSentEventsController.java

示例8: event

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
@RequestMapping(value="/v1/events", method=RequestMethod.GET)
public SseEmitter event( 
    @RequestHeader(value="Last-Event-ID", required=false) String lastEventIdHeader,
    @RequestParam(required=true, value="topic") String topic,
    @RequestParam(required=false, value="rewind") Integer rewind,
    @RequestParam(required=false, value="lastEventId") Long lastEventIdOverride
    ) throws IOException
{
    final SseEmitter sseEmitter = new SseEmitter();
    final Emitter emitter = new Emitter(sseEmitter);
    
    logger.debug("Opening emitter {}", emitter.hashCode());
    this.emitters.add(emitter);
    
    final Long lastEventId = lastEventIdOverride != null ? lastEventIdOverride : (lastEventIdHeader != null ? Long.parseLong(lastEventIdHeader) : null);
    
    final KfkaPredicate p = new KfkaPredicate().topic(topic);
    if (lastEventId != null)
    {
        p.messageId(lastEventId + 1);
        p.relativeOffset(Integer.MIN_VALUE + 10);
    }
    else
    {
        final int offset = rewind != null ? Math.abs(rewind) * -1 : -20;
        p.relativeOffset(offset);
    }
    
    final KfkaMessageListener l = kfkaManager.addListener((msg)->
    {
        try
        {
            emitter.emit(msg);
        }
        catch (IOException exc)
        {
            throw Throwables.propagate(exc);
        }
    }, p);
    
    emitter.setListener(l);
    
    // Remove on completion
    sseEmitter.onCompletion(new Runnable()
    {
        @Override
        public void run()
        {
            logger.debug("Emitter {} closed", emitter.hashCode());
            emitters.remove(emitter);
            kfkaManager.removeListener(emitter.getListener());
        }
    });

    
    return sseEmitter;
}
 
开发者ID:ethlo,项目名称:kfka,代码行数:58,代码来源:EventController.java

示例9: subscribe

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
public SseEmitter subscribe(String username) {
    SseEmitter sseEmitter = new SseEmitter(0l);
    sseEmitter.onCompletion(new DeleteTask(this, username, sseEmitter));
    this.subscriptions.put(username, sseEmitter);
    return sseEmitter;
}
 
开发者ID:ProxyPrint,项目名称:proxyprint-kitchen,代码行数:7,代码来源:NotificationManager.java

示例10: bindUnsubscribe

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
/**
 * Unsubscribes the subscription when the emitter completes or times out
 * @param emitter
 * @param subscription
 */
public static void bindUnsubscribe(SseEmitter emitter, Subscription subscription) {
    emitter.onCompletion(subscription::unsubscribe);
    emitter.onTimeout(subscription::unsubscribe);
}
 
开发者ID:bbcom,项目名称:argos-dashboard,代码行数:10,代码来源:SseEmitterUtil.java


注:本文中的org.springframework.web.servlet.mvc.method.annotation.SseEmitter.onCompletion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。