Client
Class ClientModel

java.lang.Object
  extended by Client.ClientModel

public class ClientModel
extends java.lang.Object

The ClientModel does not have any race conditions because any method that changes the model state is synchronized. The methods that request information from the server mostly call the sendMessage method which is synchronized. The methods that do not call that method or makes additional changes to the state is synchronized as a method. All instance variables are private and can only be accessed through synchronized methods.


Nested Class Summary
 class ClientModel.ClientRunnable
          Class for creating the background thread.
 class ClientModel.ServerOutputThread
          This class is used to get the outputs from the server when given certain inputs.
 
Constructor Summary
ClientModel()
          Constructor used when the default localhost and port is used
ClientModel(boolean isTesting)
          Constructor only used in testing Not calling the view at all at this stage The only difference is that the testing constructor does not call the background thread responsible for calling the ClientView.
ClientModel(java.lang.String server, int port)
           
ClientModel(java.lang.String server, int port, boolean isTesting)
          For testing whether the server is connected to a correct connection.
 
Method Summary
 void addme(java.lang.String convId)
          Adds the current user to a conversation
 void logout()
          Closes all connections upon logging out
 void removeme(java.lang.String convId)
          Removes the user from the conversation
 void requestUsername(java.lang.String username)
          Requests the username that you want when you first log in to the client.
 void sendConvoInvite(java.lang.String convId, java.lang.String otheruser)
          Invites a user into a conversation that has already been initiated
 void sendText(java.lang.String message, java.lang.String convId)
          Sends a message in a conversation
 void startConversation(java.lang.String[] users)
          Starts a conversation with a list of users you pass in to the conversation Need to synchronize because uses users which could be used elsewhere
 void usersOnline()
          Asks who is in the conversation
 void whoInConv(java.lang.String convId)
          Asks server who is in the conversation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientModel

public ClientModel(java.lang.String server,
                   int port)
            throws java.net.UnknownHostException,
                   java.io.IOException
Throws:
java.net.UnknownHostException
java.io.IOException

ClientModel

public ClientModel()
            throws java.net.UnknownHostException,
                   java.io.IOException
Constructor used when the default localhost and port is used

Throws:
java.io.IOException
java.net.UnknownHostException

ClientModel

public ClientModel(boolean isTesting)
Constructor only used in testing Not calling the view at all at this stage The only difference is that the testing constructor does not call the background thread responsible for calling the ClientView. Also does not construct a ClientView object.

Parameters:
isTesting - whether the testing constructor is called

ClientModel

public ClientModel(java.lang.String server,
                   int port,
                   boolean isTesting)
            throws java.net.UnknownHostException,
                   java.io.IOException
For testing whether the server is connected to a correct connection.

Parameters:
isTesting -
Throws:
java.net.UnknownHostException
java.io.IOException
Method Detail

requestUsername

public void requestUsername(java.lang.String username)
Requests the username that you want when you first log in to the client. Need to synchronize because does not call sendMessage method

Parameters:
username - the username you want to be sent to the server

startConversation

public void startConversation(java.lang.String[] users)
Starts a conversation with a list of users you pass in to the conversation Need to synchronize because uses users which could be used elsewhere

Parameters:
users - the array of users to start a conversation with

sendConvoInvite

public void sendConvoInvite(java.lang.String convId,
                            java.lang.String otheruser)
Invites a user into a conversation that has already been initiated

Parameters:
convId - the ID of the conversation you want to invite the user into
otheruser - the username of the other user you want to invite

addme

public void addme(java.lang.String convId)
Adds the current user to a conversation

Parameters:
convId - the conversation ID of the conversation to be invited to

removeme

public void removeme(java.lang.String convId)
Removes the user from the conversation

Parameters:
convId - the conversation id of the conversation that the user wants to be removed from

usersOnline

public void usersOnline()
Asks who is in the conversation


whoInConv

public void whoInConv(java.lang.String convId)
Asks server who is in the conversation

Parameters:
convId - the id of the conversation that you want to find out

sendText

public void sendText(java.lang.String message,
                     java.lang.String convId)
Sends a message in a conversation

Parameters:
message - the message to be sent in the conversation
convId - the conservation where the text will be sent

logout

public void logout()
Closes all connections upon logging out