public boolean idInUse(String id) { if (id == null) return false; String clusterId = getClusterId(id); boolean inUse = false; synchronized (_sessionIds) { inUse = _sessionIds.contains(clusterId); } if (inUse) return true; //optimisation - if this session is one we've been managing, we can check locally //otherwise, we need to go to the database to check try { return exists(clusterId); } catch (Exception e) { LOG.warn("Problem checking inUse for id="+clusterId, e); return false; } }
/** * Get a connection from the driver. * @return * @throws SQLException */ private Connection getConnection () throws SQLException { return ((JDBCSessionIdManager)getSessionIdManager()).getConnection(); }
/** * Start up the id manager. * * Makes necessary database tables and starts a Session * scavenger thread. */ @Override public void doStart() throws Exception { initializeDatabase(); prepareTables(); cleanExpiredSessions(); super.doStart(); if (LOG.isDebugEnabled()) LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec"); _timer=new Timer("JDBCSessionScavenger", true); setScavengeInterval(getScavengeInterval()); }
public void renewSessionId (String oldClusterId, String oldNodeId, HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); synchronized (_sessionIds) { removeSession(oldClusterId);//remove the old one from the list (and database) addSession(newClusterId); //add in the new session id to the list (and database) //tell all contexts to update the id Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class); for (int i=0; contexts!=null && i<contexts.length; i++) { SessionHandler sessionHandler = (SessionHandler)((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof JDBCSessionManager) { ((JDBCSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }
if (_lastScavengeTime > 0) connection = getConnection(); connection.setAutoCommit(true); if (isRunning()) LOG.warn("Problem selecting expired sessions", e); else
public void removeSession(HttpSession session) { if (session == null) return; removeSession(((JDBCSessionManager.Session)session).getClusterId()); }
Set<String> candidateIds = getAllCandidateExpiredSessionIds(); LOG.debug(getWorkerName()+"- Scavenge sweep started at "+System.currentTimeMillis()); if (_lastScavengeTime > 0) connection = getConnection(); connection.setAutoCommit(true); Set<String> expiredSessionIds = new HashSet<String>(); long upperBound = _lastScavengeTime; if (LOG.isDebugEnabled()) LOG.debug (getWorkerName()+"- Pass 1: Searching for sessions expired between "+lowerBound + " and "+upperBound); statement.setString(1, getWorkerName()); statement.setLong(2, lowerBound); statement.setLong(3, upperBound); scavengeSessions(candidateIds, expiredSessionIds, false); if (LOG.isDebugEnabled()) LOG.debug(getWorkerName()+"- Pass 2: Searching for sessions expired before "+upperBound); selectExpiredSessions.setLong(1, upperBound); try (ResultSet result = selectExpiredSessions.executeQuery()) if ((getWorkerName() == null && lastNode == null) || (getWorkerName() != null && getWorkerName().equals(lastNode))) expiredSessionIds.add(sessionId); if (LOG.isDebugEnabled()) LOG.debug ("Found expired sessionId="+sessionId+" last managed by "+getWorkerName()); scavengeSessions(candidateIds, expiredSessionIds, false);
public void addSession(String id) { if (id == null) return; synchronized (_sessionIds) { try { insert(id); _sessionIds.add(id); } catch (Exception e) { LOG.warn("Problem storing session id="+id, e); } } }
public void removeSession (String id) { if (id == null) return; synchronized (_sessionIds) { if (LOG.isDebugEnabled()) LOG.debug("Removing session id="+id); try { _sessionIds.remove(id); delete(id); } catch (Exception e) { LOG.warn("Problem removing session id="+id, e); } } }
if (_lastScavengeTime > 0) connection = getConnection(); connection.setAutoCommit(true); if (isRunning()) LOG.warn("Problem selecting expired sessions", e); else
public void renewSessionId (String oldClusterId, String oldNodeId, HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); synchronized (_sessionIds) { removeSession(oldClusterId);//remove the old one from the list (and database) addSession(newClusterId); //add in the new session id to the list (and database) //tell all contexts to update the id Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class); for (int i=0; contexts!=null && i<contexts.length; i++) { SessionHandler sessionHandler = (SessionHandler)((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof JDBCSessionManager) { ((JDBCSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }
public void removeSession(HttpSession session) { if (session == null) return; removeSession(((JDBCSessionManager.Session)session).getClusterId()); }
LOG.debug(getWorkerName()+"- Scavenge sweep started at "+System.currentTimeMillis()); if (_lastScavengeTime > 0) connection = getConnection(); connection.setAutoCommit(true); Set<String> expiredSessionIds = new HashSet<String>(); long upperBound = _lastScavengeTime; if (LOG.isDebugEnabled()) LOG.debug (getWorkerName()+"- Pass 1: Searching for sessions expired between "+lowerBound + " and "+upperBound); statement.setString(1, getWorkerName()); statement.setLong(2, lowerBound); statement.setLong(3, upperBound); scavengeSessions(expiredSessionIds, false); if (LOG.isDebugEnabled()) LOG.debug(getWorkerName()+"- Pass 2: Searching for sessions expired before "+upperBound); selectExpiredSessions.setLong(1, upperBound); try (ResultSet result = selectExpiredSessions.executeQuery()) if ((getWorkerName() == null && lastNode == null) || (getWorkerName() != null && getWorkerName().equals(lastNode))) expiredSessionIds.add(sessionId); if (LOG.isDebugEnabled()) LOG.debug ("Found expired sessionId="+sessionId+" last managed by "+getWorkerName()); scavengeSessions(expiredSessionIds, false); if (LOG.isDebugEnabled()) LOG.debug(getWorkerName()+"- Pass 3: searching for sessions expired before "+upperBound); selectExpiredSessions.setLong(1, upperBound);
public void addSession(String id) { if (id == null) return; synchronized (_sessionIds) { try { insert(id); _sessionIds.add(id); } catch (Exception e) { LOG.warn("Problem storing session id="+id, e); } } }
public void removeSession (String id) { if (id == null) return; synchronized (_sessionIds) { if (LOG.isDebugEnabled()) LOG.debug("Removing session id="+id); try { _sessionIds.remove(id); delete(id); } catch (Exception e) { LOG.warn("Problem removing session id="+id, e); } } }
/** * Start up the id manager. * * Makes necessary database tables and starts a Session * scavenger thread. */ @Override public void doStart() throws Exception { initializeDatabase(); prepareTables(); cleanExpiredSessions(); super.doStart(); if (LOG.isDebugEnabled()) LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec"); _timer=new Timer("JDBCSessionScavenger", true); setScavengeInterval(getScavengeInterval()); }
public boolean idInUse(String id) { if (id == null) return false; String clusterId = getClusterId(id); boolean inUse = false; synchronized (_sessionIds) { inUse = _sessionIds.contains(clusterId); } if (inUse) return true; //optimisation - if this session is one we've been managing, we can check locally //otherwise, we need to go to the database to check try { return exists(clusterId); } catch (Exception e) { LOG.warn("Problem checking inUse for id="+clusterId, e); return false; } }
if (_lastScavengeTime > 0) connection = getConnection(); connection.setAutoCommit(true); if (isRunning()) LOG.warn("Problem selecting expired sessions", e); else
/** * Remove a session id from the table. * * @param id * @throws SQLException */ private void delete (String id) throws SQLException { try (Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement(_deleteId)) { connection.setAutoCommit(true); statement.setString(1, id); statement.executeUpdate(); } }
@Override public void renewSessionId (String oldClusterId, String oldNodeId, HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); synchronized (_sessionIds) { removeSession(oldClusterId);//remove the old one from the list (and database) addSession(newClusterId); //add in the new session id to the list (and database) //tell all contexts to update the id Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class); for (int i=0; contexts!=null && i<contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof JDBCSessionManager) { ((JDBCSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }