vooga.network.util
Class VoogaUtilsClient

java.lang.Object
  extended by vooga.network.VoogaClient
      extended by vooga.network.util.VoogaUtilsClient
All Implemented Interfaces:
java.lang.Runnable

public class VoogaUtilsClient
extends VoogaClient

VoogaUtilsClient is the data management utility for local user data. It sends requests to VoogaUtilsServerThread and can synchronize user's data with other users' data.

Author:
tanner schmidt

Method Summary
 void connect(java.net.InetAddress host)
          Connects to the server at the specified address.
 boolean containsData(java.lang.String table, java.util.List<java.lang.String> key)
          Determines whether or not there is data stored on the server associated with the given key.
 boolean containsData(java.lang.String table, java.lang.String key)
          Determines whether or not there is data stored on the server associated with the given key.
 boolean containsTable(java.lang.String table)
          Asks server whether it contains particular table.
 void createDataTable(java.lang.String tableName)
          Creates a new table on the server in which to store data.
 void eraseData(java.lang.String table, java.util.List<java.lang.String> key)
          Erases the data associated with the given key from the server
 void eraseData(java.lang.String table, java.lang.String key)
           
 java.util.Map<java.util.List<java.lang.String>,java.lang.Object> getAllData(java.lang.String table)
          Gets a list of all objects stored on the server in the given table
 java.lang.Object getData(java.lang.String table, java.util.List<java.lang.String> key)
          Gets the data stored on the server associated with the given key.
 java.lang.Object getData(java.lang.String table, java.lang.String key)
          Gets the data stored on the server associated with the given key.
 long getNextAvailableID()
          Requests the next available unique ID from the server, which is used for creating unique IDs for users, games, chat channels, etc.
static VoogaUtilsClient getUtilsClient(VoogaModule module)
          Retrieves the utilities client that has access to the given module's data on the server.
protected  void initializeConnection()
          Performs any necessary set-up for a new connection.
 void run()
          Keeps the client running as long as it is connected to the server.
 void storeData(java.lang.String table, java.util.List<java.lang.String> key, java.io.Serializable value)
          Store a key-value pair on the server, where it can be retrieved later in this session or in future sessions, unless it is overwritten or deleted.
 void storeData(java.lang.String table, java.lang.String key, java.io.Serializable value)
          Store a key-value pair on the server, where it can be retrieved later in this session or in future sessions, unless it is overwritten or deleted.
 DataObject synchronize(java.lang.String table, java.util.List<java.lang.String> key, DataObject obj)
          Used by the LocalDataManager to synchronize local storage with the server via this utilities client.
 
Methods inherited from class vooga.network.VoogaClient
allowConnection, blockConnection, connect, connect, disconnect, getMyInputStream, getMyName, getMyOutputStream, getMySocket, isConnected, setConnected, setMyName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getUtilsClient

public static VoogaUtilsClient getUtilsClient(VoogaModule module)
                                       throws java.net.UnknownHostException
Retrieves the utilities client that has access to the given module's data on the server.

Parameters:
module -
Returns:
Throws:
java.net.UnknownHostException

getNextAvailableID

public long getNextAvailableID()
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException
Requests the next available unique ID from the server, which is used for creating unique IDs for users, games, chat channels, etc. Note that the request ID is registered so it will not be given again, so this method should only be invoked when creating something new and unique.

Throws:
java.lang.ClassNotFoundException
VoogaNetworkException
java.io.IOException

createDataTable

public void createDataTable(java.lang.String tableName)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException
Creates a new table on the server in which to store data.

Parameters:
tableName -
Throws:
java.io.IOException
java.lang.ClassNotFoundException

storeData

public void storeData(java.lang.String table,
                      java.lang.String key,
                      java.io.Serializable value)
               throws java.io.IOException,
                      java.lang.ClassNotFoundException
Store a key-value pair on the server, where it can be retrieved later in this session or in future sessions, unless it is overwritten or deleted.

Parameters:
key - The key to associate the value with
value - The Object to store on the server. This object needs to be Serializable.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

storeData

public void storeData(java.lang.String table,
                      java.util.List<java.lang.String> key,
                      java.io.Serializable value)
               throws java.io.IOException,
                      java.lang.ClassNotFoundException
Store a key-value pair on the server, where it can be retrieved later in this session or in future sessions, unless it is overwritten or deleted. The key may contain a list of Strings identifying it

Parameters:
key - The key to associate the value with
value - The Object to store on the server. This object needs to be Serializable.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

eraseData

public void eraseData(java.lang.String table,
                      java.lang.String key)
               throws java.io.IOException,
                      java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

eraseData

public void eraseData(java.lang.String table,
                      java.util.List<java.lang.String> key)
               throws java.io.IOException,
                      java.lang.ClassNotFoundException
Erases the data associated with the given key from the server

Parameters:
key - The location from which to erase data.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getData

public java.lang.Object getData(java.lang.String table,
                                java.lang.String key)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Gets the data stored on the server associated with the given key.

Parameters:
key - The data location.
Returns:
The data associated with the key.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

getData

public java.lang.Object getData(java.lang.String table,
                                java.util.List<java.lang.String> key)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Gets the data stored on the server associated with the given key. The key can be a list of multiple String values.

Parameters:
key - The data location.
Returns:
The data associated with the key.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

containsData

public boolean containsData(java.lang.String table,
                            java.lang.String key)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException
Determines whether or not there is data stored on the server associated with the given key. The default is to count keys that are lists of Strings and begin with the given String.

Parameters:
key - The key or prefix to check.
Returns:
True if there is data stored with this key or with a key beginning with this key.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

containsData

public boolean containsData(java.lang.String table,
                            java.util.List<java.lang.String> key)
                     throws java.io.IOException,
                            java.lang.ClassNotFoundException
Determines whether or not there is data stored on the server associated with the given key. The default is to count keys that are lists of Strings and begin with the given list of Strings.

Parameters:
key - The key or prefix to check.
Returns:
True if there is data stored with this key or with a key beginning with this key.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

containsTable

public boolean containsTable(java.lang.String table)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException
Asks server whether it contains particular table.

Parameters:
table - table name
Returns:
true if table is already on server.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getAllData

public java.util.Map<java.util.List<java.lang.String>,java.lang.Object> getAllData(java.lang.String table)
                                                                            throws java.io.IOException,
                                                                                   java.lang.ClassNotFoundException
Gets a list of all objects stored on the server in the given table

Parameters:
key - The prefix to get data for.
Returns:
A List of all objects found.
Throws:
java.lang.ClassNotFoundException
java.io.IOException

synchronize

public DataObject synchronize(java.lang.String table,
                              java.util.List<java.lang.String> key,
                              DataObject obj)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Used by the LocalDataManager to synchronize local storage with the server via this utilities client.

Parameters:
table - table name
key - The prefix to get data for
obj - Object to be synchronized with.
Returns:
DataObject
Throws:
java.io.IOException
java.lang.ClassNotFoundException

run

public void run()
Keeps the client running as long as it is connected to the server.


initializeConnection

protected void initializeConnection()
Description copied from class: VoogaClient
Performs any necessary set-up for a new connection.

Specified by:
initializeConnection in class VoogaClient

connect

public void connect(java.net.InetAddress host)
             throws java.io.IOException
Description copied from class: VoogaClient
Connects to the server at the specified address. The implementation of this method in each of the client subclasses should call the connect method with the given host and the port number specific to that client.

Specified by:
connect in class VoogaClient
Parameters:
host - The IP of an existing VoogaChatServer.
Throws:
java.io.IOException