Context context = getTheContext(); if (context == null) { return; File store = sessionStore(context.getPath()); if (store == null) { getLogger().debug("No session store file found"); return; if (getLogger().isDebugEnabled()) { getLogger().debug("Loading sessions from " + store.getAbsolutePath()); fis = new FileInputStream(store.getAbsolutePath()); bis = new BufferedInputStream(fis); if (getTheContext() != null) { loader = getTheContext().getLoader(); if (getLogger().isDebugEnabled()) { getLogger().debug("Creating custom object input stream for class loader"); if (getLogger().isDebugEnabled()) { getLogger().debug("Creating standard object input stream"); if (getLogger().isDebugEnabled()) { getLogger().debug("No persisted data file found"); getLogger().error("Exception loading sessions", e); try { fis.close();
int interval = ((Integer) event.getNewValue()).intValue(); if (interval < RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) { getLogger().warn("The configured session timeout of " + interval + " minutes is invalid. Using the original value of " + event.getOldValue() + " minutes."); setMaxInactiveInterval(interval == RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL ? RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL : interval * 60); } catch (NumberFormatException e) { getLogger() .error(sm.getString("standardManager.sessionTimeout", event.getNewValue().toString()));
@Override public Object getAttribute(String name) { checkBackingCacheAvailable(); Object value = super.getAttribute(name); // If the attribute is a byte[] (meaning it came from the server), // deserialize it and add it to attributes map before returning it. if (value instanceof byte[]) { try { value = BlobHelper.deserializeBlob((byte[]) value); } catch (Exception e) { StringBuilder builder = new StringBuilder(); builder.append(this).append(": Attribute named ").append(name).append( " contains a byte[] that cannot be deserialized due to the following exception"); ((DeltaSessionManager) getManager()).getLogger().warn(builder.toString(), e); } if (this.preferDeserializedForm) { localUpdateAttribute(name, value); } } // Touch the session region if necessary. This is an asynchronous operation // that prevents the session region from prematurely expiring a session that // is only getting attributes. ((DeltaSessionManager) getManager()).addSessionToTouch(getId()); return value; }
@Override public void load() throws ClassNotFoundException, IOException { doLoad(); ContextMapper.addContext(getContextName(), this); }
@Override public void unload() throws IOException { doUnload(); ContextMapper.removeContext(getContextName()); }
@Override public void run() { int currentActiveSessions = getSessionCache().size(); if (currentActiveSessions > getMaxActive()) { setMaxActive(currentActiveSessions); if (getLogger().isDebugEnabled()) { getLogger().debug( DeltaSessionManager.this + ": Set max active sessions: " + currentActiveSessions); } } } };
Context context = getTheContext(); if (context == null) { return; if (getRegionName().startsWith("/")) { regionName = getRegionName(); } else { regionName = "/" + getRegionName(); getLogger().debug("Query: " + query.getQueryString()); results = (SelectResults) query.execute(); } catch (Exception ex) { getLogger().error("Unable to perform query during doUnload", ex); return; getLogger().debug("No sessions to unload for context " + context.getPath()); return; // nothing to do File store = sessionStore(context.getPath()); if (store == null) { return; if (getLogger().isDebugEnabled()) { getLogger().debug("Unloading sessions to " + store.getAbsolutePath()); } catch (IOException e) { error = true; getLogger().error("Exception unloading sessions", e);
/** * Returns the number of active sessions * * @return number of sessions active */ @Override public int getActiveSessions() { return getSessionCache().size(); }
super.stopInternal(); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Stopping"); super.destroyInternal();
private void initializeRegion(DeltaSessionManager sessionManager) { // Get the session region name this.sessionRegionName = sessionManager.getRegionName(); // Get the operating region. // If a P2P manager is used, then this will be a local region fronting the // session region if local cache is enabled; otherwise, it will be the // session region itself. // If a CS manager is used, it will be the session proxy region. this.operatingRegion = sessionManager.getSessionCache().getOperatingRegion(); if (sessionManager.getLogger().isDebugEnabled()) { sessionManager.getLogger().debug(this + ": Set operating region: " + this.operatingRegion); } }
@Override public void run() { // Get the sessionIds to touch and clear the set inside synchronization Set<String> sessionIds = null; sessionIds = new HashSet<String>(getSessionsToTouch()); getSessionsToTouch().clear(); // Touch the sessions we currently have if (!sessionIds.isEmpty()) { getSessionCache().touchSessions(sessionIds); if (getLogger().isDebugEnabled()) { getLogger().debug(DeltaSessionManager.this + ": Touched sessions: " + sessionIds); } } } };
public void remove(Session session, boolean update) { // super.remove(session); // Remove the session from the region if necessary. // It will have already been removed if it expired implicitly. DeltaSessionInterface ds = (DeltaSessionInterface) session; if (ds.getExpired()) { if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Expired session " + session.getId() + " from " + getSessionCache().getOperatingRegionName()); } } else { if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Destroying session " + session.getId() + " from " + getSessionCache().getOperatingRegionName()); } getSessionCache().destroySession(session.getId()); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Destroyed session " + session.getId() + " from " + getSessionCache().getOperatingRegionName()); } } }
return null; if (getLogger().isDebugEnabled()) { getLogger().debug( this + ": Finding session " + id + " in " + getSessionCache().getOperatingRegionName()); DeltaSessionInterface session = (DeltaSessionInterface) getSessionCache().getSession(id); && !getContextName().equals(session.getContextName())) { getLogger() .info(this + ": Session " + id + " rejected as container name and context do not match: " + getContextName() + " != " + session.getContextName()); session = null; if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Did not find session " + id + " in " + getSessionCache().getOperatingRegionName()); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Found session " + id + " in " + getSessionCache().getOperatingRegionName() + ": " + session);
@Override public void add(Session session) { // super.add(session); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Storing session " + session.getId() + " into " + getSessionCache().getOperatingRegionName()); } getSessionCache().putSession(session); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Stored session " + session.getId() + " into " + getSessionCache().getOperatingRegionName()); } getSessionCache().getStatistics().incSessionsCreated(); }
/** * Reset some data */ @Before public void setup() throws Exception { sessionManager.setMaxInactiveInterval(30); region.clear(); }
if (manager.getLogger().isDebugEnabled()) { StringBuilder builder = new StringBuilder(); builder.append(this).append(": Handling failover of session ").append(sessionId) .append(" from ").append(requestJvmRoute).append(" to ").append(localJvmRoute); manager.getLogger().debug(builder.toString()); session = manager.findSession(sessionId); } catch (IOException e) { StringBuilder builder = new StringBuilder(); builder.append(this).append(": Caught exception attempting to find session ") .append(sessionId).append(" in ").append(manager); manager.getLogger().warn(builder.toString(), e); builder.append(this).append(": Did not find session ").append(sessionId) .append(" to failover in ").append(manager); manager.getLogger().warn(builder.toString()); } else {
public static void setupServer(DeltaSessionManager manager) throws Exception { FileUtils.copyDirectory(Paths.get("..", "resources", "integrationTest", "tomcat").toFile(), new File("./tomcat")); port = AvailablePortHelper.getRandomAvailableTCPPort(); server = new EmbeddedTomcat("/test", port, "JVM-1"); PeerToPeerCacheLifecycleListener p2pListener = new PeerToPeerCacheLifecycleListener(); p2pListener.setProperty(MCAST_PORT, "0"); p2pListener.setProperty(LOG_LEVEL, "config"); server.getEmbedded().addLifecycleListener(p2pListener); sessionManager = manager; sessionManager.setEnableCommitValve(true); server.getRootContext().setManager(sessionManager); servlet = server.addServlet("/test/*", "default", CommandServlet.class.getName()); server.startContainer(); /* * Can only retrieve the region once the container has started up (and the cache has started * too). */ region = sessionManager.getSessionCache().getSessionRegion(); }
super.startInternal(); if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Starting");
Context context = getTheContext(); if (context == null) { return; if (getRegionName().startsWith("/")) { regionName = getRegionName(); } else { regionName = "/" + getRegionName(); getLogger().debug("Query: " + query.getQueryString()); results = (SelectResults) query.execute(); } catch (Exception ex) { getLogger().error("Unable to perform query during doUnload", ex); return; getLogger().debug("No sessions to unload for context " + context.getPath()); return; // nothing to do File store = sessionStore(context.getPath()); if (store == null) { return; if (getLogger().isDebugEnabled()) { getLogger().debug("Unloading sessions to " + store.getAbsolutePath()); } catch (IOException e) { error = true; getLogger().error("Exception unloading sessions", e);
@Override public void run() { int currentActiveSessions = getSessionCache().size(); if (currentActiveSessions > getMaxActive()) { setMaxActive(currentActiveSessions); if (getLogger().isDebugEnabled()) { getLogger().debug( DeltaSessionManager.this + ": Set max active sessions: " + currentActiveSessions); } } } };