AMF48

AMF Encode/Decode Library for Java

Browsing Posts published by wacky

I need to get all active sessions from servlet.
But I believe this API is obsolated…

That is why, I tried to implement using existing API.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package jp.develop.tool.servlet;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
 
/**
 * Session list providing Listener.
 */
public class SessionListListener implements HttpSessionListener, HttpSessionActivationListener, Serializable {
 
    private static final boolean DEBUG = true;
    private static final long serialVersionUID = 7490899888824580726L;
    private static final String SESSION_LISTENER_KEY = "_sessionListListener";
 
    private static Object lock = new Object();
    private static List<httpsession> sessions = new ArrayList<httpsession>();
    private static List<httpsession> sessionsForOutput = Collections.unmodifiableList(sessions);
 
    /**
     * Get all sessions.
     * @return All sessions list.
     */
    public static List<httpsession> getSessions() {
        return sessionsForOutput;
    }
 
    /**
     * Default Constructor.
     */
    public SessionListListener() {
        log(String.format("Session List Listener is initialized."));
    }
 
    /**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent event) {
        synchronized (lock) {
            HttpSession session = event.getSession();
            session.setAttribute(SESSION_LISTENER_KEY, this);
            sessions.add(session);
            log(String.format("Session Added: %s", session.getId()));
        }
    }
 
    /**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent event) {
        synchronized (lock) {
            HttpSession session = event.getSession();
            session.removeAttribute(SESSION_LISTENER_KEY);
            sessions.remove(session);       // XXX May not good implementation for performance.
            log(String.format("Session Removed: %s", session.getId()));
        }
    }
 
    /**
     * @see HttpSessionActivationListener#sessionDidActivate(HttpSessionEvent)
     */
    public void sessionDidActivate(HttpSessionEvent event) {
        synchronized (lock) {
            HttpSession session = event.getSession();
            sessions.add(session);
            log(String.format("Session Activate: %s", session.getId()));
        }
    }
 
    /**
     * @see HttpSessionActivationListener#sessionWillPassivate(HttpSessionEvent)
     */
    public void sessionWillPassivate(HttpSessionEvent event) {
        synchronized (lock) {
            HttpSession session = event.getSession();
            sessions.remove(session);       // XXX May not good implementation for performance.
            log(String.format("Session Passivate: %s", session.getId()));
        }
    }
 
    private static void log(String message) {
        if (DEBUG) {
            System.out.println(message);
        }
    }
}
</httpsession></httpsession></httpsession></httpsession>

If anybody find a problem, please let me know…

Sorry, this entry is only available in 日本語.

I got full marks for DevQuiz, which is required to join Google Developer Day 2011.
Today I just upload the image…(Because, DevQuiz is still open.)

FullMarks

GAE’s channel API provide client library only for JavaScript.
That is why, I thought that it is difficult to use channel API
from Adobe AIR.

But it looks possible…At least, my test code is working…
Anyway, I need rewrite my code for better structure.

This release includes the bug fix for decoding Vector.<Object>.