CADI.Server.Session
Class ClientSessions

java.lang.Object
  extended by CADI.Server.Session.ClientSessions

public class ClientSessions
extends java.lang.Object

This class is used to save the sessions of the clients. This object will be shared among the Worker threads, therefore methods must garantee the access to the list.

Version:
1.0 2007/10/26
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
(package private)  java.util.ArrayList<Session> sessionsList
          Contains a list where the client sessions are saved.
 
Constructor Summary
ClientSessions()
          Constructor.
 
Method Summary
 boolean add(Session session)
          Adds the specified element to the end of the list.
 boolean belongs(java.lang.String cid1, java.lang.String cid2)
          Checks whether the cid1 and cid2 channel identifiers belongs to the same session.
 void clear()
          Remove all elements from the clients list
 void closeSession(java.lang.String cid)
          Closes all channels that belongs to the same sessions, so the session is closed and removed from the sessions list.
 boolean contains(java.lang.String cid)
          Returns true if the clients list contains the specified element.
 Session get(java.lang.String cid)
          Returns the first element of the queue if it isn't empty, otherwise null.
private  int indexOf(java.lang.String cid)
          Returns the index of the session which the channel cid belongs to.
 boolean isEmpty()
          Checks if there is a empty list of sessions.
 void list(java.io.PrintStream out)
          Prints this ClientSessions out to the specified output stream.
 void remove(java.lang.String cid)
          Removes the element that it is identifier by its session identifier.
 int size()
          Returns the number of sessions.
 java.lang.String toString()
          For debugging purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sessionsList

java.util.ArrayList<Session> sessionsList
Contains a list where the client sessions are saved.

Constructor Detail

ClientSessions

public ClientSessions()
Constructor.

Method Detail

add

public boolean add(Session session)
Adds the specified element to the end of the list.

Parameters:
session - element to be appended to this list.
Returns:
true (as specified by Collection.add(E))

remove

public void remove(java.lang.String cid)
Removes the element that it is identifier by its session identifier. Shifts any subsequent elements to the left (subtracts one from their indices).

Parameters:
cid - the channel identifier.

get

public Session get(java.lang.String cid)
Returns the first element of the queue if it isn't empty, otherwise null.

Returns:
the session.

contains

public boolean contains(java.lang.String cid)
Returns true if the clients list contains the specified element.

Parameters:
cid -
Returns:
true if the list contains the specified element.

belongs

public boolean belongs(java.lang.String cid1,
                       java.lang.String cid2)
Checks whether the cid1 and cid2 channel identifiers belongs to the same session.

Parameters:
cid1 - a channel identifier.
cid2 - a channel identifier.
Returns:
true if both channel identifiers belong to the same session. Otherwise, returns false.

closeSession

public void closeSession(java.lang.String cid)
Closes all channels that belongs to the same sessions, so the session is closed and removed from the sessions list.

Parameters:
cid - the unique channel identifier.

size

public int size()
Returns the number of sessions.

Returns:
the number of sessions.

isEmpty

public boolean isEmpty()
Checks if there is a empty list of sessions.

Returns:
true if there is not any sessions. Otherwise, returns false.

clear

public void clear()
Remove all elements from the clients list


toString

public java.lang.String toString()
For debugging purpose.

Overrides:
toString in class java.lang.Object

list

public void list(java.io.PrintStream out)
Prints this ClientSessions out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

indexOf

private int indexOf(java.lang.String cid)
Returns the index of the session which the channel cid belongs to. If the channel is not in the sessions, returns -1 .

Parameters:
cid - the channel identifier.
Returns:
the index of the session in the sessionsList, or -1 if the channel is not the list.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)