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


Java SseEmitter.onTimeout方法代码示例

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


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

示例1: createSseEmitter

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //导入方法依赖的package包/类
/**
 * Creates a {@link SseEmitter} and registers the client in the internal database.
 * Client will be subscribed to the provided events if specified.
 *
 * @param clientId unique client identifier
 * @param timeout timeout value in milliseconds
 * @param unsubscribe if true unsubscribes from all events that are not provided with
 * the next parameter
 * @param events events the client wants to subscribe
 * @return a new SseEmitter instance
 */
public SseEmitter createSseEmitter(String clientId, Long timeout, boolean unsubscribe,
		boolean completeAfterMessage, String... events) {
	SseEmitter emitter = new SseEmitter(timeout);
	emitter.onTimeout(emitter::complete);
	registerClient(clientId, emitter, completeAfterMessage);

	if (events != null && events.length > 0) {
		if (unsubscribe) {
			unsubscribeFromAllEvents(clientId, events);
		}
		for (String event : events) {
			subscribe(clientId, event);
		}
	}

	return emitter;
}
 
开发者ID:ralscha,项目名称:sse-eventbus,代码行数:29,代码来源:SseEventBus.java

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

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

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

示例5: 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.onTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。