/**
  * Register all cross context sessions inside endAccess. Use a list with contains check, that the
  * Portlet API can include a lot of fragments from same or different applications with session
  * changes.
  *
  * @param session cross context session
  */
 public void registerReplicationSession(DeltaSession session) {
   List<DeltaSession> sessions = crossContextSessions.get();
   if (sessions != null) {
     if (!sessions.contains(session)) {
       if (log.isDebugEnabled())
         log.debug(
             sm.getString(
                 "ReplicationValve.crossContext.registerSession",
                 session.getIdInternal(),
                 session.getManager().getContainer().getName()));
       sessions.add(session);
     }
   }
 }
 /**
  * Reset DeltaRequest from session
  *
  * @param session HttpSession from current request or cross context session
  */
 protected void resetDeltaRequest(Session session) {
   if (log.isDebugEnabled()) {
     log.debug(
         sm.getString(
             "ReplicationValve.resetDeltaRequest", session.getManager().getContainer().getName()));
   }
   ((DeltaSession) session).resetDeltaRequest();
 }
 /**
  * Fix memory leak for long sessions with many changes, when no backup member exists!
  *
  * @param request current request after response is generated
  * @param isCrossContext check crosscontext threadlocal
  */
 protected void resetReplicationRequest(Request request, boolean isCrossContext) {
   Session contextSession = request.getSessionInternal(false);
   if (contextSession instanceof DeltaSession) {
     resetDeltaRequest(contextSession);
     ((DeltaSession) contextSession).setPrimarySession(true);
   }
   if (isCrossContext) {
     List<DeltaSession> sessions = crossContextSessions.get();
     if (sessions != null && sessions.size() > 0) {
       Iterator<DeltaSession> iter = sessions.iterator();
       for (; iter.hasNext(); ) {
         Session session = iter.next();
         resetDeltaRequest(session);
         if (session instanceof DeltaSession)
           ((DeltaSession) contextSession).setPrimarySession(true);
       }
     }
   }
 }