soc.server
Class SOCChannelList

java.lang.Object
  extended by soc.server.SOCChannelList

public class SOCChannelList
extends java.lang.Object

A class for tracking the chat channels. The list itself, and each channel, has a monitor for synchronization.

Author:
Robert S. Thomas

Field Summary
protected  java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> channelMembers
          key = string, value = Vector of StringConnections
protected  java.util.Hashtable<java.lang.String,MutexFlag> channelMutexes
          key = string, value = Vector of MutexFlags
protected  java.util.Hashtable<java.lang.String,java.lang.String> channelOwners
          Each channel's creator/owner name.
protected  boolean inUse
          track the monitor for this channel list
 
Constructor Summary
SOCChannelList()
          constructor
 
Method Summary
 void addMember(StringConnection conn, java.lang.String chName)
          add a member to the chat channel
 void createChannel(java.lang.String chName, java.lang.String chOwner)
          create a new channel.
 void deleteChannel(java.lang.String chName)
          remove the channel from the list
 java.util.Enumeration<java.lang.String> getChannels()
           
 java.util.Vector<StringConnection> getMembers(java.lang.String chName)
           
 java.lang.String getOwner(java.lang.String chName)
          Get a channel's owner name
 boolean isChannel(java.lang.String chName)
           
 boolean isChannelEmpty(java.lang.String chName)
           
 boolean isMember(StringConnection conn, java.lang.String chName)
           
 void releaseMonitor()
          release the monitor for this channel list
 boolean releaseMonitorForChannel(java.lang.String channel)
          release the monitor for this channel
 void removeMember(StringConnection conn, java.lang.String chName)
          remove member from the chat channel
 void replaceMemberAllChannels(StringConnection oldConn, StringConnection newConn)
          Replace member from all chat channels, with a new connection (after a network problem).
 void takeMonitor()
          take the monitor for this channel list
 boolean takeMonitorForChannel(java.lang.String channel)
          take the monitor for this channel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channelMutexes

protected java.util.Hashtable<java.lang.String,MutexFlag> channelMutexes
key = string, value = Vector of MutexFlags


channelMembers

protected java.util.Hashtable<java.lang.String,java.util.Vector<StringConnection>> channelMembers
key = string, value = Vector of StringConnections


channelOwners

protected java.util.Hashtable<java.lang.String,java.lang.String> channelOwners
Each channel's creator/owner name. key = string, value = Vector of Strings.

Since:
1.1.10

inUse

protected boolean inUse
track the monitor for this channel list

Constructor Detail

SOCChannelList

public SOCChannelList()
constructor

Method Detail

takeMonitor

public void takeMonitor()
take the monitor for this channel list


releaseMonitor

public void releaseMonitor()
release the monitor for this channel list


takeMonitorForChannel

public boolean takeMonitorForChannel(java.lang.String channel)
take the monitor for this channel

Parameters:
channel - the name of the channel
Returns:
false if the channel has no mutex

releaseMonitorForChannel

public boolean releaseMonitorForChannel(java.lang.String channel)
release the monitor for this channel

Parameters:
channel - the name of the channel
Returns:
false if the channel has no mutex

getChannels

public java.util.Enumeration<java.lang.String> getChannels()
Returns:
an enumeration of channel names (Strings)

getOwner

public java.lang.String getOwner(java.lang.String chName)
Get a channel's owner name

Parameters:
chName - channel name
Returns:
owner's name, or null if chName isn't a channel
Since:
1.1.10

getMembers

public java.util.Vector<StringConnection> getMembers(java.lang.String chName)
Parameters:
chName - channel name
Returns:
list of members

isMember

public boolean isMember(StringConnection conn,
                        java.lang.String chName)
Parameters:
chName - the name of the channel
conn - the member's connection
Returns:
true if memName is a member of the channel

addMember

public void addMember(StringConnection conn,
                      java.lang.String chName)
add a member to the chat channel

Parameters:
chName - the name of the channel
conn - the member's connection

removeMember

public void removeMember(StringConnection conn,
                         java.lang.String chName)
remove member from the chat channel

Parameters:
chName - the name of the channel
conn - the member's connection

replaceMemberAllChannels

public void replaceMemberAllChannels(StringConnection oldConn,
                                     StringConnection newConn)
Replace member from all chat channels, with a new connection (after a network problem).

Parameters:
oldConn - the member's old connection
newConn - the member's new connection
Since:
1.1.08

isChannel

public boolean isChannel(java.lang.String chName)
Parameters:
chName - the name of the channel
Returns:
true if the channel exists

isChannelEmpty

public boolean isChannelEmpty(java.lang.String chName)
Parameters:
chName - the name of the channel
Returns:
true if the channel exists and has an empty member list

createChannel

public void createChannel(java.lang.String chName,
                          java.lang.String chOwner)
                   throws java.lang.NullPointerException
create a new channel. If channel already exists, do nothing.

Parameters:
chName - the name of the channel
chOwner - the game owner/creator's player name (added in 1.1.10)
Throws:
java.lang.NullPointerException - if chOwner null

deleteChannel

public void deleteChannel(java.lang.String chName)
remove the channel from the list

Parameters:
chName - the name of the channel