@Override public Response processRemoveSession(SessionId id, long lastDeliveredSequenceId) throws Exception { SessionState session = state.getSessionState(id); if (session == null) { throw new IllegalStateException("Cannot remove session that had not been registered: " + id); } // Don't let new consumers or producers get added while we are closing // this down. session.shutdown(); // Cascade the connection stop to the consumers and producers. for (ConsumerId consumerId : session.getConsumerIds()) { try { processRemoveConsumer(consumerId, lastDeliveredSequenceId); } catch (Throwable e) { // LOG.warn("Failed to remove consumer: {}", consumerId, e); } } for (ProducerId producerId : session.getProducerIds()) { try { processRemoveProducer(producerId); } catch (Throwable e) { // LOG.warn("Failed to remove producer: {}", producerId, e); } } state.removeSession(id); protocolManager.removeSession(context, session.getInfo()); return null; }
@Override public Response processAddSession(SessionInfo info) throws Exception { // Avoid replaying dup commands if (!state.getSessionIds().contains(info.getSessionId())) { protocolManager.addSession(this, info); try { state.addSession(info); } catch (IllegalStateException e) { e.printStackTrace(); protocolManager.removeSession(context, info); } } return null; }