Fix for errors during shutdown

This commit is contained in:
Andrew Shvayka 2017-02-03 20:07:54 +02:00
parent e0c366614e
commit 7cc3d6880d

View File

@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanCreationNotAllowedException;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -57,10 +58,12 @@ public class PluginWebSocketHandler extends TextWebSocketHandler implements Plug
private static final ConcurrentMap<String, SessionMetaData> internalSessionMap = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, SessionMetaData> internalSessionMap = new ConcurrentHashMap<>();
private static final ConcurrentMap<String, String> externalSessionMap = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, String> externalSessionMap = new ConcurrentHashMap<>();
@Autowired @Lazy @Autowired
@Lazy
private ActorService actorService; private ActorService actorService;
@Autowired @Lazy @Autowired
@Lazy
private PluginService pluginService; private PluginService pluginService;
@Override @Override
@ -105,7 +108,7 @@ public class PluginWebSocketHandler extends TextWebSocketHandler implements Plug
super.handleTransportError(session, tError); super.handleTransportError(session, tError);
SessionMetaData sessionMd = internalSessionMap.get(session.getId()); SessionMetaData sessionMd = internalSessionMap.get(session.getId());
if (sessionMd != null) { if (sessionMd != null) {
actorService.process(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onError(tError))); processInActorService(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onError(tError)));
} else { } else {
log.warn("[{}] Failed to find session", session.getId()); log.warn("[{}] Failed to find session", session.getId());
} }
@ -118,11 +121,19 @@ public class PluginWebSocketHandler extends TextWebSocketHandler implements Plug
SessionMetaData sessionMd = internalSessionMap.remove(session.getId()); SessionMetaData sessionMd = internalSessionMap.remove(session.getId());
if (sessionMd != null) { if (sessionMd != null) {
externalSessionMap.remove(sessionMd.sessionRef.getSessionId()); externalSessionMap.remove(sessionMd.sessionRef.getSessionId());
actorService.process(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onClosed())); processInActorService(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onClosed()));
} }
log.info("[{}] Session is closed", session.getId()); log.info("[{}] Session is closed", session.getId());
} }
private void processInActorService(SessionEventPluginWebSocketMsg msg) {
try {
actorService.process(msg);
} catch (BeanCreationNotAllowedException e) {
log.warn("[{}] Failed to close session due to possible shutdown state", msg.getSessionRef().getSessionId());
}
}
private PluginWebsocketSessionRef toRef(WebSocketSession session) throws IOException { private PluginWebsocketSessionRef toRef(WebSocketSession session) throws IOException {
URI sessionUri = session.getUri(); URI sessionUri = session.getUri();
String path = sessionUri.getPath(); String path = sessionUri.getPath();