de.kosi.chat
Class ChatChannelImpl

java.lang.Object
  |
  +--de.kosi.chat.ChatChannelImpl
All Implemented Interfaces:
ChatChannel, java.rmi.Remote, UserListener

public class ChatChannelImpl
extends java.lang.Object
implements ChatChannel, UserListener

This class implements a chat channel.

ChangeLog:

 $Log: ChatChannelImpl.java,v $
 Revision 1.4  2001/08/30 12:03:04  jiriki
 Fixed Bug 440380

 Revision 1.3  2001/06/04 14:21:10  jiriki
 Made source more comliant to coding guidelines.

 Revision 1.2  2001/05/22 10:16:02  jiriki
 - Removed old unused Client class
 - Removed unused import statements.

 Revision 1.1.1.1  2001/04/29 18:05:16  jiriki
 Imported sources from zola.

 Revision 1.19  2001/04/11 18:08:14  wombat
 Client can now write into the table chat.

 Revision 1.18  2001/04/11 16:54:04  wombat
 Removed some bugs when joining table and immidiatly leaving again.

 Revision 1.17  2001/04/09 13:03:10  wombat
 Removed timeout from threadpool (did not work)

 Revision 1.16  2001/03/20 18:17:31  wombat
 Added logging support

 Revision 1.15  2001/02/25 23:16:05  wombat
 - deadlock vermeidung umgestellt.
 - ListenerList erstellt

 Revision 1.14  2001/02/09 21:21:18  login
 completed docs for de.kosi.chat

 Revision 1.13  2001/02/09 19:23:20  login
 Updated the javadocs.

 Revision 1.12  2001/02/06 15:04:36  wombat
 Updated documentation

 

Version:
$Revision: 1.4 $ ($Date: 2001/08/30 12:03:04 $)
Author:
Niklas, Timo, Jan-Ole

Field Summary
static java.lang.Boolean DEFAULT
          Constant indicating default access to the chat channel.
static java.lang.Boolean READ_ONLY
          Constant indicating read only access to the chat channel.
static java.lang.Boolean READ_WRITE
          Constant indicating read/write access to the chat channel.
 
Fields inherited from interface de.kosi.chat.ChatChannel
ACTION, SAY
 
Constructor Summary
ChatChannelImpl(java.lang.Boolean defaultPermission)
          Creates a new ChatChannelImpl instance with the given default read/write permissions.
 
Method Summary
 void addChatListener(ChatListener listener)
          Implements the methode inherited from ChatChannel.
 void close()
          Closes this chat channel instance.
 void destroyed(UserImpl user)
          Called when a UserImpl Object is about to be destroyed.
protected  void fireChatEvent(ChatEvent event)
          Sends a chat event to all registered listeners.
 java.lang.String[] getUserNames()
          Returns an array that contains the login names of all users that are currently on this chat channel.
 void onlineChange(UserImpl user, boolean isOnline)
          This method is called when the online status of the user changes.
 void removeChatListener(ChatListener listener, java.lang.String reason)
          Removes the given ChatListener off the listener list.
 void removeUser(UserImpl user, java.lang.String reason)
          Remove a user from the chat.
 void sendMessage(java.lang.String msg, int type)
          Sends a message to the chat channel.
 void setUserPermission(UserImpl user, java.lang.Boolean permission)
          Sets the permission of the given user to read only respectively read/write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_ONLY

public static final java.lang.Boolean READ_ONLY
Constant indicating read only access to the chat channel.

READ_WRITE

public static final java.lang.Boolean READ_WRITE
Constant indicating read/write access to the chat channel.

DEFAULT

public static final java.lang.Boolean DEFAULT
Constant indicating default access to the chat channel.
Constructor Detail

ChatChannelImpl

public ChatChannelImpl(java.lang.Boolean defaultPermission)
                throws java.rmi.RemoteException
Creates a new ChatChannelImpl instance with the given default read/write permissions.
Parameters:
defaultPermission - The default permission. If a user joins this channel, his read/write permission will be set to the value of this argument.
Throws:
java.rmi.RemoteException - If RMI detects an error.
Method Detail

setUserPermission

public void setUserPermission(UserImpl user,
                              java.lang.Boolean permission)
Sets the permission of the given user to read only respectively read/write.
Parameters:
user - The user whos permission is to be changed.
permission - The new permission. Must be one of the values of the constants READ_ONLY or READ_WRITE.

close

public void close()
           throws java.rmi.RemoteException
Closes this chat channel instance. You should always call this method to let RMI unexport this instance.
Throws:
java.rmi.RemoteException - If RMI runs into trouble.

getUserNames

public java.lang.String[] getUserNames()
Returns an array that contains the login names of all users that are currently on this chat channel. The value null will never be returned, but the length of the returned array may be zero. All array fields will refer to a String instance, none will contain null.
Specified by:
getUserNames in interface ChatChannel
Returns:
An array that contains the login names of all users that are currently on this chat channel.

addChatListener

public void addChatListener(ChatListener listener)
                     throws java.rmi.RemoteException,
                            InvalidSessionException
Implements the methode inherited from ChatChannel. Adds a ChatListener to the listener list.
Specified by:
addChatListener in interface ChatChannel
Parameters:
listener - The ChatListener that is to be added.
Throws:
java.rmi.RemoteException - If there was something amiss about RMI.
InvalidSessionException - ???

removeChatListener

public void removeChatListener(ChatListener listener,
                               java.lang.String reason)
Removes the given ChatListener off the listener list. The other users on the channel get the reason for leaving sent to them.
Specified by:
removeChatListener in interface ChatChannel
Parameters:
listener - The listener that is to be removed.
reason - The reason for leaving the channel.

removeUser

public void removeUser(UserImpl user,
                       java.lang.String reason)
Remove a user from the chat.
Parameters:
user - User to remove.
reason - Reason for the removal.

sendMessage

public void sendMessage(java.lang.String msg,
                        int type)
                 throws java.rmi.RemoteException,
                        ChatException,
                        InvalidSessionException
Sends a message to the chat channel. This method will be called by a client who wants to tell the other users anything.
Specified by:
sendMessage in interface ChatChannel
Parameters:
msg - The message that is sent by the client.
type - The message type. This should be one of the constants ChatChannel.ACTION and ChatChannel.SAY. If an ACTION message is sent the client should display it in a way that indicates that the user who sent the message "did" it. If a SAY message is sent the client should display it in a way that indicates that the user "said" it.
Throws:
java.rmi.RemoteException - If RMI doesn't get along.
ChatException - If the user either didn't join the channel before sending a message or isn't permitted to send anything.
InvalidSessionException - If the session was invalid?!?

fireChatEvent

protected void fireChatEvent(ChatEvent event)
Sends a chat event to all registered listeners.
Parameters:
event - The chat event that is to be sent.

onlineChange

public void onlineChange(UserImpl user,
                         boolean isOnline)
This method is called when the online status of the user changes.
Specified by:
onlineChange in interface UserListener
Parameters:
user - user whose state changed.
isOnline - wether the user is online.

destroyed

public void destroyed(UserImpl user)
Called when a UserImpl Object is about to be destroyed.
Specified by:
destroyed in interface UserListener
Parameters:
user - UserImpl object to be destroyed.