com.cutunes.server
Class RequestHandler

java.lang.Object
  extended bycom.cutunes.server.RequestHandler

public class RequestHandler
extends java.lang.Object

RequestHandler specifies the format of the incoming XML-RPC messages. All messages requires some sort of access to the database, but all database logic has been separated into the DatabaseController class. The four methods below define the API used to communicate between the client and server, making for a very simple and easy to understand API.

Author:
blake, hal2001

Constructor Summary
RequestHandler()
          Constructor gets an instance of the DatabaseController.
 
Method Summary
 boolean bulkLoadSongs(int userID, boolean sendAllSongs, java.util.Date lastSync, java.lang.String version, java.util.Vector songGroup)
          This method received the user's song information over XML-RPC and adds it to the database.
 java.sql.Timestamp getLastSync(int userID, java.lang.String version)
          Queries database to get the time of the user's last sync.
 java.lang.Integer getUserID(java.lang.String username, java.lang.String password, java.lang.String version)
          getUserID() performs basic login checks and returns the given user's unique ID number.
 boolean setLastSync(int userID, java.lang.String version)
          Sets the user's last sync time to the current time.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestHandler

public RequestHandler()
Constructor gets an instance of the DatabaseController.

Method Detail

getUserID

public java.lang.Integer getUserID(java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String version)
getUserID() performs basic login checks and returns the given user's unique ID number. Checks to see if user is running an acceptable version of the client program, and queries the database to get the user ID.

Parameters:
username - String username
password - String password
version - String identifying version of client software
Returns:
Returns userID if user/password match database, returns -1 if user/password pair not in DB, and returns -10 if wrong version of client software is being used.

getLastSync

public java.sql.Timestamp getLastSync(int userID,
                                      java.lang.String version)
Queries database to get the time of the user's last sync.

Parameters:
userID - Unique ID of user
version - String identifying version of client software
Returns:
Timestamp of user's last sync

setLastSync

public boolean setLastSync(int userID,
                           java.lang.String version)
Sets the user's last sync time to the current time.

Parameters:
userID - Unique ID of user
version - String identifying version of client software
Returns:
True if successfully updated

bulkLoadSongs

public boolean bulkLoadSongs(int userID,
                             boolean sendAllSongs,
                             java.util.Date lastSync,
                             java.lang.String version,
                             java.util.Vector songGroup)
This method received the user's song information over XML-RPC and adds it to the database. Many things have been done to improve performance, specifically the user's track information is written to two files in the server's /tmp space so that MySQL load data function can be used.

The songsFile contains all the track information to put in the songs table of the database (this includes track name, album, artist, etc). This information is always loaded into the database using MySQLs bulk load function, even if it already exists in the table (in which case it is ignored).

The hasSongsFile contains all the information about the playcount and last play date of a specified song for a given user. It is written and bulk loaded only if the sendAllSongs boolean is true (which indicates this is a user's first sync). Otherwise this information is loaded using the DatabaseController's updateHasSong function (which updates weekly playcounts according to a specified algorithm).

Parameters:
userID - Unique ID identifying user
sendAllSongs - Boolean variable is true if this is a user's first sync, in which case the has_song table data is bulk loaded
lastSync - The time of the user's last sync
version - String identifying version of client software
songGroup - Vector of SongData objects
Returns:
True if successfully loads data