Created
May 21, 2013 14:28
-
-
Save jfuerth/5620208 to your computer and use it in GitHub Desktop.
Enhanced traceability for things that go into SessionsContainer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static class TraceableMap<K,V> implements Map<K,V> { | |
| private final Map<K, V> backingMap; | |
| private final String name; | |
| TraceableMap(String name, Map<K,V> backingMap) { | |
| this.backingMap = Assert.notNull(backingMap); | |
| this.name = Assert.notNull(name); | |
| } | |
| public void clear() { | |
| backingMap.clear(); | |
| } | |
| public boolean containsKey(Object key) { | |
| return backingMap.containsKey(key); | |
| } | |
| public boolean containsValue(Object value) { | |
| return backingMap.containsValue(value); | |
| } | |
| public Set<java.util.Map.Entry<K, V>> entrySet() { | |
| return backingMap.entrySet(); | |
| } | |
| public boolean equals(Object o) { | |
| return backingMap.equals(o); | |
| } | |
| public V get(Object key) { | |
| return backingMap.get(key); | |
| } | |
| public int hashCode() { | |
| return backingMap.hashCode(); | |
| } | |
| public boolean isEmpty() { | |
| return backingMap.isEmpty(); | |
| } | |
| public Set<K> keySet() { | |
| return backingMap.keySet(); | |
| } | |
| public V put(K key, V value) { | |
| System.out.println("Put into TraceableMap " + name + ": " + value); | |
| new Exception("Just a stack trace").printStackTrace(System.out); | |
| return backingMap.put(key, value); | |
| } | |
| public void putAll(Map<? extends K, ? extends V> m) { | |
| System.out.println("Put entire map into TraceableMap " + name + ": " + m.entrySet()); | |
| new Exception("Just a stack trace").printStackTrace(System.out); | |
| backingMap.putAll(m); | |
| } | |
| public V remove(Object key) { | |
| return backingMap.remove(key); | |
| } | |
| public int size() { | |
| return backingMap.size(); | |
| } | |
| public Collection<V> values() { | |
| return backingMap.values(); | |
| } | |
| } | |
| public static class SessionsContainer implements Serializable { | |
| private final Map<String, Object> sharedAttributes = | |
| new TraceableMap<String, Object>("sharedAttributes of " + System.identityHashCode(this), new HashMap<String, Object>()); | |
| private final Map<String, QueueSession> queueSessions = | |
| new TraceableMap<String, QueueSession>("queueSessions of " + System.identityHashCode(this), new HashMap<String, QueueSession>()); | |
| public SessionsContainer() { | |
| System.out.println("Creating new SessionsContainer@" + System.identityHashCode(this)); | |
| } | |
| public QueueSession createSession(final String httpSessionId, final String remoteQueueId) { | |
| final QueueSession qs = new HttpSessionWrapper(this, httpSessionId, remoteQueueId); | |
| queueSessions.put(remoteQueueId, qs); | |
| return qs; | |
| } | |
| public QueueSession getSession(final String remoteQueueId) { | |
| return queueSessions.get(remoteQueueId); | |
| } | |
| public void removeSession(final String remoteQueueId) { | |
| queueSessions.remove(remoteQueueId); | |
| } | |
| private void writeObject(ObjectOutputStream out) throws IOException { | |
| System.out.println("SessionsContainer@" + System.identityHashCode(this) + " is about to get serialized. Contents:"); | |
| System.out.println("sharedAttributes: " + sharedAttributes); | |
| System.out.println("queueSessions: " + queueSessions); | |
| out.defaultWriteObject(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment