private boolean sessionExistsInTheCluster(String hazelcastSessionId) { try { return hazelcastSessionId != null && clusteredSessionService.containsSession(hazelcastSessionId); } catch (Exception ignored) { return false; } }
void destroy(boolean invalidate) { valid = false; webFilter.getClusteredSessionService().deleteSession(id, invalidate); }
@Override public final void destroy() { sessions.clear(); originalSessions.clear(); if (config.isShutdownOnDestroy()) { clusteredSessionService.destroy(); } }
private void ensureInstance() throws Exception { if (failedConnection && System.currentTimeMillis() > lastConnectionTry + RETRY_MILLIS) { synchronized (this) { try { if (failedConnection && System.currentTimeMillis() > lastConnectionTry + RETRY_MILLIS) { reconnectHZInstance(); clearOrphanSessionQueue(); } } catch (Exception e) { setFailedConnection(true); LOGGER.warning("Cannot connect to Hazelcast server: " + e.getMessage()); if (LOGGER.isFinestEnabled()) { LOGGER.finest("Cannot connect hazelcast server", e); } } } } }
/** * Gets attribute names. * * @param id the id * @return the attribute names * @throws Exception the exception */ public Set<String> getAttributeNames(String id) throws Exception { return (Set<String>) executeOnKey(id, new GetAttributeNamesEntryProcessor()); }
@Override public final void init(final FilterConfig filterConfig) throws ServletException { this.config = WebFilterConfig.create(filterConfig, this.properties); // Register the WebFilter with the ServletContext so SessionListener can look it up. The name // here is WebFilter.class instead of getClass() because WebFilter can have subclasses servletContext = filterConfig.getServletContext(); servletContext.setAttribute(WEB_FILTER_ATTRIBUTE_KEY, this); clusteredSessionService = new ClusteredSessionService(this.config); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest(this.config.toString()); } }
public void init() throws Exception { ensureInstance(); es.scheduleWithFixedDelay(new Runnable() { public void run() { try { ensureInstance(); } catch (Exception e) { if (LOGGER.isFinestEnabled()) { LOGGER.finest("Cannot connect hazelcast server", e); } } } }, 2 * CLUSTER_CHECK_INTERVAL, CLUSTER_CHECK_INTERVAL, TimeUnit.SECONDS); }
/** * Delete session. * * @param sessionId sessionId * @param invalidate if true remove the distributed session, otherwise just * remove the jvm reference * @return the boolean */ public boolean deleteSession(String sessionId, boolean invalidate) { try { doDeleteSession(sessionId, invalidate); return true; } catch (Exception e) { orphanSessions.add(new AbstractMap.SimpleEntry(sessionId, invalidate)); return false; } }
public void removeAttribute(final String name) { LocalCacheEntry entry = localCache.get(name); if (entry != null && entry != WebFilter.NULL_ENTRY) { entry.setValue(null); entry.setRemoved(true); entry.setDirty(true); entry.setReload(false); } if (!deferredWrite) { try { webFilter.getClusteredSessionService().deleteAttribute(id, name); entry.setDirty(false); } catch (Exception ignored) { EmptyStatement.ignore(ignored); } } }
public Object getAttribute(final String name) { LocalCacheEntry cacheEntry = localCache.get(name); Object value = null; if (cacheEntry == null || cacheEntry.isReload()) { try { value = webFilter.getClusteredSessionService().getAttribute(id, name); cacheEntry = new LocalCacheEntry(false, value); cacheEntry.setReload(false); localCache.put(name, cacheEntry); } catch (Exception e) { if (WebFilter.LOGGER.isFinestEnabled()) { WebFilter.LOGGER.finest("session could not be load so you might be dealing with stale data", e); } if (cacheEntry == null) { return null; } } } if (cacheEntry.isRemoved()) { return null; } return cacheEntry.getValue(); }
private void ensureInstance() throws Exception { if (failedConnection && System.currentTimeMillis() > lastConnectionTry + RETRY_MILLIS) { synchronized (this) { try { if (failedConnection && System.currentTimeMillis() > lastConnectionTry + RETRY_MILLIS) { reconnectHZInstance(); clearOrphanSessionQueue(); } } catch (Exception e) { setFailedConnection(true); LOGGER.warning("Cannot connect to Hazelcast server: " + e.getMessage()); if (LOGGER.isFinestEnabled()) { LOGGER.finest("Cannot connect hazelcast server", e); } } } } }
/** * Gets attribute. * * @param sessionId the session id * @param attributeName the attribute name * @return the attribute * @throws Exception the exception */ Object getAttribute(String sessionId, String attributeName) throws Exception { GetAttributeEntryProcessor entryProcessor = new GetAttributeEntryProcessor(attributeName); return executeOnKey(sessionId, entryProcessor); }
@Override public final void init(final FilterConfig filterConfig) throws ServletException { this.config = WebFilterConfig.create(filterConfig, this.properties); // Register the WebFilter with the ServletContext so SessionListener can look it up. The name // here is WebFilter.class instead of getClass() because WebFilter can have subclasses servletContext = filterConfig.getServletContext(); servletContext.setAttribute(WEB_FILTER_ATTRIBUTE_KEY, this); clusteredSessionService = new ClusteredSessionService(this.config); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest(this.config.toString()); } }
public void init() throws Exception { ensureInstance(); es.scheduleWithFixedDelay(new Runnable() { public void run() { try { ensureInstance(); } catch (Exception e) { if (LOGGER.isFinestEnabled()) { LOGGER.finest("Cannot connect hazelcast server", e); } } } }, 2 * CLUSTER_CHECK_INTERVAL, CLUSTER_CHECK_INTERVAL, TimeUnit.SECONDS); }
/** * Delete session. * * @param sessionId sessionId * @param invalidate if true remove the distributed session, otherwise just * remove the jvm reference * @return the boolean */ public boolean deleteSession(String sessionId, boolean invalidate) { try { doDeleteSession(sessionId, invalidate); return true; } catch (Exception e) { orphanSessions.add(new AbstractMap.SimpleEntry(sessionId, invalidate)); return false; } }
public void removeAttribute(final String name) { LocalCacheEntry entry = localCache.get(name); if (entry != null && entry != WebFilter.NULL_ENTRY) { entry.setValue(null); entry.setRemoved(true); entry.setDirty(true); entry.setReload(false); } if (!deferredWrite) { try { webFilter.getClusteredSessionService().deleteAttribute(id, name); if (entry != null) { entry.setDirty(false); } } catch (Exception e) { LOGGER.warning("Unexpected error occurred.", e); } } }
public Object getAttribute(final String name) { LocalCacheEntry cacheEntry = localCache.get(name); Object value = null; if (cacheEntry == null || cacheEntry.isReload()) { try { value = webFilter.getClusteredSessionService().getAttribute(id, name); cacheEntry = new LocalCacheEntry(false, value); cacheEntry.setReload(false); localCache.put(name, cacheEntry); } catch (Exception e) { if (LOGGER.isFinestEnabled()) { LOGGER.finest("session could not be load so you might be dealing with stale data", e); } if (cacheEntry == null) { return null; } } } if (cacheEntry.isRemoved()) { return null; } return cacheEntry.getValue(); }
/** * Gets attribute. * * @param sessionId the session id * @param attributeName the attribute name * @return the attribute * @throws Exception the exception */ Object getAttribute(String sessionId, String attributeName) throws Exception { GetAttributeEntryProcessor entryProcessor = new GetAttributeEntryProcessor(attributeName); return executeOnKey(sessionId, entryProcessor); }
void destroy(boolean invalidate) { valid = false; webFilter.getClusteredSessionService().deleteSession(id, invalidate); }
@Override public final void destroy() { sessions.clear(); originalSessions.clear(); if (config.isShutdownOnDestroy()) { clusteredSessionService.destroy(); } }