FileDocCategorySizeDatePackage
ChatSessionManager.javaAPI DocAndroid 1.5 API3223Wed May 06 22:42:46 BST 2009com.android.im.engine

ChatSessionManager

public abstract class ChatSessionManager extends Object
The ChatSessionManager keeps track of all current chat sessions and is also responsible to dispatch the new incoming message to the right session.

Fields Summary
private CopyOnWriteArrayList
mListeners
protected Vector
mSessions
Map session to the participant communicate with.
Constructors Summary
protected ChatSessionManager()

        mListeners = new CopyOnWriteArrayList<ChatSessionListener>();
        mSessions = new Vector<ChatSession>();
    
Methods Summary
public synchronized voidaddChatSessionListener(ChatSessionListener listener)
Registers a ChatSessionListener with the ChatSessionManager to receive events related to ChatSession.

param
listener the listener

        if ((listener != null) && !mListeners.contains(listener)) {
            mListeners.add(listener);
        }
    
public voidcloseChatSession(ChatSession session)
Closes a ChatSession. This only removes the session from the list; the protocol implementation should override this if it has special work to do.

param
session the ChatSession to close.

        mSessions.remove(session);
    
public synchronized ChatSessioncreateChatSession(ImEntity participant)
Creates a new ChatSession with specified participant.

param
participant the participant.
return
the created ChatSession.

        for(ChatSession session : mSessions) {
            if(session.getParticipant().equals(participant)) {
                return session;
            }
        }

        ChatSession session = new ChatSession(participant, this);
        for (ChatSessionListener listener : mListeners) {
            listener.onChatSessionCreated(session);
        }

        mSessions.add(session);

        return session;
    
public synchronized voidremoveChatSessionListener(ChatSessionListener listener)
Removes a ChatSessionListener so that it will no longer be notified.

param
listener the listener to remove.

        mListeners.remove(listener);
    
protected abstract voidsendMessageAsync(ChatSession session, Message message)
Sends a message to specified participant(s) asynchronously. TODO: more docs on async callbacks.

param
message the message to send.