/**
  * 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();
 }
 /**
  * Send all changed cross context sessions to backups
  *
  * @param containerCluster
  */
 protected void sendCrossContextSession(CatalinaCluster containerCluster) {
   List<DeltaSession> sessions = crossContextSessions.get();
   if (sessions != null && sessions.size() > 0) {
     for (Iterator<DeltaSession> iter = sessions.iterator(); iter.hasNext(); ) {
       Session session = iter.next();
       if (log.isDebugEnabled())
         log.debug(
             sm.getString(
                 "ReplicationValve.crossContext.sendDelta",
                 session.getManager().getContainer().getName()));
       sendMessage(session, (ClusterManager) session.getManager(), containerCluster);
       if (doStatistics()) {
         nrOfCrossContextSendRequests++;
       }
     }
   }
 }
예제 #3
0
  public static ApplicationSession getApplicationSession(
      Session session, boolean calcSize, boolean addAttributes) {

    ApplicationSession sbean = null;
    if (session != null && session.isValid()) {
      sbean = new ApplicationSession();

      sbean.setId(session.getId());
      sbean.setCreationTime(new Date(session.getCreationTime()));
      sbean.setLastAccessTime(new Date(session.getLastAccessedTime()));
      sbean.setMaxIdleTime(session.getMaxInactiveInterval() * 1000);
      sbean.setManagerType(session.getManager().getClass().getName());
      // sbean.setInfo(session.getInfo());
      // TODO:fixmee

      boolean sessionSerializable = true;
      int attributeCount = 0;
      long size = 0;

      HttpSession httpSession = session.getSession();
      Set processedObjects = new HashSet(1000);

      // Exclude references back to the session itself
      processedObjects.add(httpSession);
      try {
        for (Enumeration e = httpSession.getAttributeNames(); e.hasMoreElements(); ) {
          String name = (String) e.nextElement();
          Object obj = httpSession.getAttribute(name);
          sessionSerializable = sessionSerializable && obj instanceof Serializable;

          long objSize = 0;
          if (calcSize) {
            try {
              objSize += Instruments.sizeOf(name, processedObjects);
              objSize += Instruments.sizeOf(obj, processedObjects);
            } catch (Throwable th) {
              logger.error("Cannot estimate size of attribute \"" + name + "\"", th);
              //
              // make sure we always re-throw ThreadDeath
              //
              if (e instanceof ThreadDeath) {
                throw (ThreadDeath) e;
              }
            }
          }

          if (addAttributes) {
            Attribute saBean = new Attribute();
            saBean.setName(name);
            saBean.setType(ClassUtils.getQualifiedName(obj.getClass()));
            saBean.setValue(obj);
            saBean.setSize(objSize);
            saBean.setSerializable(obj instanceof Serializable);
            sbean.addAttribute(saBean);
          }
          attributeCount++;
          size += objSize;
        }
        String lastAccessedIp =
            (String) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_BY_IP);
        if (lastAccessedIp != null) {
          sbean.setLastAccessedIp(lastAccessedIp);
        }
        try {
          sbean.setLastAccessedIpLocale(
              InetAddressLocator.getLocale(InetAddress.getByName(lastAccessedIp).getAddress()));
        } catch (Throwable e) {
          logger.error("Cannot determine Locale of " + lastAccessedIp);
          //
          // make sure we always re-throw ThreadDeath
          //
          if (e instanceof ThreadDeath) {
            throw (ThreadDeath) e;
          }
        }

      } catch (IllegalStateException e) {
        logger.info("Session appears to be invalidated, ignore");
      }

      sbean.setObjectCount(attributeCount);
      sbean.setSize(size);
      sbean.setSerializable(sessionSerializable);
    }

    return sbean;
  }