Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.undertow.servlet.util;
 
 
Session persistence implementation that simply stores session information in memory.

Author(s):
Stuart Douglas
    private static final Map<StringMap<StringSessionEntry>> data = new ConcurrentHashMap<StringMap<StringSessionEntry>>();
    @Override
    public void persistSessions(String deploymentNameMap<StringPersistentSessionsessionData) {
        try {
            final Map<StringSessionEntryserializedData = new HashMap<StringSessionEntry>();
            for (Map.Entry<StringPersistentSessionsessionEntry : sessionData.entrySet()) {
                Map<Stringbyte[]> data = new HashMap<Stringbyte[]>();
                for (Map.Entry<StringObjectsessionAttribute : sessionEntry.getValue().getSessionData().entrySet()) {
                    try {
                        final ByteArrayOutputStream out = new ByteArrayOutputStream();
                        final ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
                        objectOutputStream.writeObject(sessionAttribute.getValue());
                        objectOutputStream.close();
                        data.put(sessionAttribute.getKey(), out.toByteArray());
                    } catch (Exception e) {
                        ..failedToPersistSessionAttribute(sessionAttribute.getKey(), sessionAttribute.getValue(), sessionEntry.getKey(), e);
                    }
                }
                serializedData.put(sessionEntry.getKey(), new SessionEntry(sessionEntry.getValue().getExpiration(), data));
            }
            .put(deploymentNameserializedData);
        } catch (Exception e) {
        }
    }
    @Override
    public Map<StringPersistentSessionloadSessionAttributes(String deploymentNamefinal ClassLoader classLoader) {
        try {
            long time = System.currentTimeMillis();
            Map<StringSessionEntrydata = this..remove(deploymentName);
            if (data != null) {
                Map<StringPersistentSessionret = new HashMap<StringPersistentSession>();
                for (Map.Entry<StringSessionEntrysessionEntry : data.entrySet()) {
                    if (sessionEntry.getValue()..getTime() > time) {
                        Map<StringObjectsession = new HashMap<StringObject>();
                        for (Map.Entry<Stringbyte[]> sessionAttribute : sessionEntry.getValue()..entrySet()) {
                            final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(sessionAttribute.getValue()));
                            session.put(sessionAttribute.getKey(), in.readObject());
                        }
                        ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().session));
                    }
                }
                return ret;
            }
        } catch (Exception e) {
        }
        return null;
    }
    @Override
    public void clear(String deploymentName) {
    }
    static final class SessionEntry {
        private final Date expiry;
        private final Map<Stringbyte[]> data;
        private SessionEntry(Date expiryMap<Stringbyte[]> data) {
            this. = expiry;
            this. = data;
        }
    }
New to GrepCode? Check out our FAQ X