I would like to know how I could map the users that connect based on their unique id's and id session so that when there are more than 3 sessions for that id, the users who connected first are removed from the hashmap and so on.
Example:
UserID:3 Session:1980002
UserID:3 Session:2841111
UserID:3 Session:84848
The UserID already contains 3 active sessions, the oldest one is removed and the KillSession invoked, giving way to new.
UserID:3 Session:2841111
UserID:3 Session:84848
UserID:3 Session:4848880
Code:
public void onHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertino httpSession) {
String User_Session = httpSession.getSessionId();
String Client_ID = httpSession.getProperties().getPropertyStr("sql_client_id");
/* Verifies that there are already 3 active sessions and removes the oldest,
since the limit of simultaneous sessions is 3 for each user,
and add to hashmap, Client_ID and User_Session */
}
public void onHTTPCupertinoStreamingSessionDestroy(IHTTPStreamerSession httpSession) {
String User_Session = httpSession.getSessionId();
//remove from hashmap, Client_ID based on session User_Session
}
public void KillSession(int SessionId){
IApplicationInstance Instance = applicationInstance;
IHTTPStreamerSession sessions = Instance.getHTTPStreamerSessions().get(SessionId);
sessions.rejectSession();
//remove from hashmap, Client_ID based on session User_Session
}
The Client_ID is the id of the user in the database, the User_Session is the unique session in the wowza generated for each connection, this session does not have equal values, that is, if the same Client_ID connects more than once, that value will be different For each of your sessions.
That is, basically my difficulty is to mount the hashmap, how could I do this?
If I have understood correctly that you want to store up to three session IDs per user/client ID, I don’t really think that a
LinkedHashMap
will help you. It is correct that aLinkedHashMap
maintains insertion order, as opposed to aHashMap
.I have a different suggestion for you. To keep things separate, I suggest this little auxiliary class to hold the map:
Now the map is what keeps the correspondenace between client ID and session ID, while the
Queue
is keeping the insertion order.With this you may solve your task in the following way. I have taken the removal from the map out of
killSession()
and have given that responibility to the caller,onHTTPCupertinoStreamingSessionCreate()
.I am storing the client ID as string and the session ID as integer. You may want to use the same type for both. Since you had declared
KillSession()
with anint
parameter, I thought I’d useint
for the session.