net.sourceforge.obby4j
Class Client

java.lang.Object
  extended by net.sourceforge.obby4j.Client
All Implemented Interfaces:
ProtocolListener

public class Client
extends java.lang.Object
implements ProtocolListener

The main application entry point for communicating with a obby-compatible server in an OOP fashion.


Constructor Summary
Client()
          Creates an unconnected client.
 
Method Summary
 void addChatListener(ChatListener listener)
          Register a listener to receive chat messages.
 void addUserListener(UserListener listener)
          Register a listener to receive user join/part notifications.
 void commandReceived(Command command)
          Handles protocol commands to sychronize the client's internal state with one on the server.
 void connect(java.net.InetAddress host, int port, java.lang.String username, java.awt.Color color)
          Logs into the server as the given user.
 Document getDocumentById(java.lang.String documentId)
          Searches for a document by its document ID.
 java.util.List<Document> getDocuments()
           
 Protocol getProtocol()
           
 User getSelf()
           
 ServerMetaData getServerMetaData()
           
 User getUserByNet6Id(int net6Id)
          Searches for a user by his net6 user ID.
 User getUserByObbyId(int obbyId)
          Searches for a user by his obby user ID.
 java.util.List<User> getUsers()
           
 void removeChatListener(ChatListener listener)
          Unregister a listener from receiving chat messages.
 void removeUserListener(UserListener listener)
          Unregister a listener from receiving user join/part notifications.
 void sendMessage(java.lang.String message)
          Sends a chat message to other users.
 void subscribe(Document document)
          Subscribes this client to a document.
 void unsubscribe(Document document)
          Unsubscribes this client from a document.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client()
Creates an unconnected client.

Method Detail

addChatListener

public void addChatListener(ChatListener listener)
Register a listener to receive chat messages.

Parameters:
listener - the listener to register

addUserListener

public void addUserListener(UserListener listener)
Register a listener to receive user join/part notifications.

Parameters:
listener - the listener to register

commandReceived

public void commandReceived(Command command)
Handles protocol commands to sychronize the client's internal state with one on the server.

Specified by:
commandReceived in interface ProtocolListener
Parameters:
command - the command to handle

connect

public void connect(java.net.InetAddress host,
                    int port,
                    java.lang.String username,
                    java.awt.Color color)
             throws java.io.IOException,
                    Net6LoginException
Logs into the server as the given user.

Parameters:
host -
port -
username -
color -
Throws:
java.io.IOException
Net6LoginException

getDocumentById

public Document getDocumentById(java.lang.String documentId)
Searches for a document by its document ID. Returns the document if found, throws a NoSuchElementException otherwise.

Parameters:
documentId -
Returns:
a document
Throws:
java.util.NoSuchElementException - if no document could be found with the given ID

getDocuments

public java.util.List<Document> getDocuments()
Returns:
all documents available in the session

getProtocol

public Protocol getProtocol()
Returns:
the protocol used by this client

getSelf

public User getSelf()
Returns:
the user represented by this client

getServerMetaData

public ServerMetaData getServerMetaData()
Returns:
Returns the server meta-data.

getUserByNet6Id

public User getUserByNet6Id(int net6Id)
Searches for a user by his net6 user ID. Returns the user if found, throws a NoSuchElementException otherwise.

Parameters:
net6Id -
Returns:
a valid obby User
Throws:
java.util.NoSuchElementException - if no user could be found with the given ID

getUserByObbyId

public User getUserByObbyId(int obbyId)
Searches for a user by his obby user ID. Returns the user if found, throws a NoSuchElementException otherwise.

Parameters:
obbyId -
Returns:
a valid obby User
Throws:
java.util.NoSuchElementException - if no user could be found with the given ID

getUsers

public java.util.List<User> getUsers()
Returns:
a list of all users

removeChatListener

public void removeChatListener(ChatListener listener)
Unregister a listener from receiving chat messages.

Parameters:
listener - the listener to unregister

removeUserListener

public void removeUserListener(UserListener listener)
Unregister a listener from receiving user join/part notifications.

Parameters:
listener - the listener to unregister

sendMessage

public void sendMessage(java.lang.String message)
                 throws java.io.IOException
Sends a chat message to other users.

Parameters:
message - the message to send
Throws:
java.io.IOException

subscribe

public void subscribe(Document document)
               throws java.io.IOException
Subscribes this client to a document.

Parameters:
document - the document to subscribe to
Throws:
java.io.IOException

unsubscribe

public void unsubscribe(Document document)
                 throws java.io.IOException
Unsubscribes this client from a document.

Parameters:
document - the document to unsubscribe from
Throws:
java.io.IOException