本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}