@Override public void persistSessions(String deploymentName, Map<String, PersistentSession> sessionData) { try { final Marshaller marshaller = createMarshaller(); try { final Map<String, SessionEntry> serializedData = new HashMap<String, SessionEntry>(); for (Map.Entry<String, PersistentSession> sessionEntry : sessionData.entrySet()) { Map<String, byte[]> data = new HashMap<String, byte[]>(); for (Map.Entry<String, Object> sessionAttribute : sessionEntry.getValue().getSessionData().entrySet()) { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.start(new OutputStreamByteOutput(out)); marshaller.writeObject(sessionAttribute.getValue()); marshaller.finish(); data.put(sessionAttribute.getKey(), out.toByteArray()); } catch (Exception e) { UndertowLogger.ROOT_LOGGER.failedToPersistSessionAttribute(sessionAttribute.getKey(), sessionAttribute.getValue(), sessionEntry.getKey(), e); } } serializedData.put(sessionEntry.getKey(), new SessionEntry(sessionEntry.getValue().getExpiration(), data)); } persistSerializedSessions(deploymentName, serializedData); } finally { marshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedToPersistSessions(e); } }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override public synchronized void start(StartContext startContext) throws StartException { super.start(startContext); if (pathRelativeTo != null) { callbackHandle = pathManager.getValue().registerCallback(pathRelativeTo, PathManager.ReloadServerCallback.create(), PathManager.Event.UPDATED, PathManager.Event.REMOVED); } baseDir = new File(pathManager.getValue().resolveRelativePathEntry(path, pathRelativeTo)); if (!baseDir.exists()) { if (!baseDir.mkdirs()) { throw UndertowLogger.ROOT_LOGGER.failedToCreatePersistentSessionDir(baseDir); } } if (!baseDir.isDirectory()) { throw UndertowLogger.ROOT_LOGGER.invalidPersistentSessionDir(baseDir); } }
@Override public synchronized void stop(StopContext stopContext) { super.stop(stopContext); if (callbackHandle != null) { callbackHandle.remove(); } }
@Override public synchronized void stop(StopContext stopContext) { super.stop(stopContext); if (callbackHandle != null) { callbackHandle.remove(); } }
@Override public void persistSessions(String deploymentName, Map<String, PersistentSession> sessionData) { try { final Marshaller marshaller = createMarshaller(); try { final Map<String, SessionEntry> serializedData = new HashMap<String, SessionEntry>(); for (Map.Entry<String, PersistentSession> sessionEntry : sessionData.entrySet()) { Map<String, byte[]> data = new HashMap<String, byte[]>(); for (Map.Entry<String, Object> sessionAttribute : sessionEntry.getValue().getSessionData().entrySet()) { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.start(new OutputStreamByteOutput(out)); marshaller.writeObject(sessionAttribute.getValue()); marshaller.finish(); data.put(sessionAttribute.getKey(), out.toByteArray()); } catch (Exception e) { UndertowLogger.ROOT_LOGGER.failedToPersistSessionAttribute(sessionAttribute.getKey(), sessionAttribute.getValue(), sessionEntry.getKey(), e); } } serializedData.put(sessionEntry.getKey(), new SessionEntry(sessionEntry.getValue().getExpiration(), data)); } persistSerializedSessions(deploymentName, serializedData); } finally { marshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedToPersistSessions(e); } }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override public synchronized void stop(StopContext stopContext) { super.stop(stopContext); if (callbackHandle != null) { callbackHandle.remove(); } }
@Override public synchronized void start(StartContext startContext) throws StartException { super.start(startContext); if (pathRelativeTo != null) { callbackHandle = pathManager.getValue().registerCallback(pathRelativeTo, PathManager.ReloadServerCallback.create(), PathManager.Event.UPDATED, PathManager.Event.REMOVED); } baseDir = new File(pathManager.getValue().resolveRelativePathEntry(path, pathRelativeTo)); if (!baseDir.exists()) { if (!baseDir.mkdirs()) { throw UndertowLogger.ROOT_LOGGER.failedToCreatePersistentSessionDir(baseDir); } } if (!baseDir.isDirectory()) { throw UndertowLogger.ROOT_LOGGER.invalidPersistentSessionDir(baseDir); } }
@Override public void persistSessions(String deploymentName, Map<String, PersistentSession> sessionData) { try { final Marshaller marshaller = createMarshaller(); try { final Map<String, SessionEntry> serializedData = new HashMap<String, SessionEntry>(); for (Map.Entry<String, PersistentSession> sessionEntry : sessionData.entrySet()) { Map<String, byte[]> data = new HashMap<String, byte[]>(); for (Map.Entry<String, Object> sessionAttribute : sessionEntry.getValue().getSessionData().entrySet()) { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.start(new OutputStreamByteOutput(out)); marshaller.writeObject(sessionAttribute.getValue()); marshaller.finish(); data.put(sessionAttribute.getKey(), out.toByteArray()); } catch (Exception e) { UndertowLogger.ROOT_LOGGER.failedToPersistSessionAttribute(sessionAttribute.getKey(), sessionAttribute.getValue(), sessionEntry.getKey(), e); } } serializedData.put(sessionEntry.getKey(), new SessionEntry(sessionEntry.getValue().getExpiration(), data)); } persistSerializedSessions(deploymentName, serializedData); } finally { marshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedToPersistSessions(e); } }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override public synchronized void start(StartContext startContext) throws StartException { super.start(startContext); if (pathRelativeTo != null) { callbackHandle = pathManager.getValue().registerCallback(pathRelativeTo, PathManager.ReloadServerCallback.create(), PathManager.Event.UPDATED, PathManager.Event.REMOVED); } baseDir = new File(pathManager.getValue().resolveRelativePathEntry(path, pathRelativeTo)); if (!baseDir.exists()) { if (!baseDir.mkdirs()) { throw UndertowLogger.ROOT_LOGGER.failedToCreatePersistentSessionDir(baseDir); } } if (!baseDir.isDirectory()) { throw UndertowLogger.ROOT_LOGGER.invalidPersistentSessionDir(baseDir); } }