CFEngine API

org.recommender.server
Class CFEngineImpl

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--org.recommender.server.CFEngineImpl
All Implemented Interfaces:
CFEngine, java.rmi.Remote, java.io.Serializable

public class CFEngineImpl
extends java.rmi.server.UnicastRemoteObject
implements CFEngine

Implementation of the CFEngine interface.

Since:
JDK 1.2
Author:
Sameer Kadam, Irwin Yoon, Olivier Godde, Daniel Lowd, Shuzhen Nong, Matt McLaughlin
See Also:
Serialized Form

Field Summary
 java.lang.Class algorithm
           
 java.lang.Object newAlgObj
           
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
CFEngineImpl()
          Constructor, do nothing.
CFEngineImpl(java.lang.String propertiesFilename)
          Constructor, create a DataManager with a mode: experiment, autotest, or server, instantiate an algorithm and start a DBManager which is reponsible for dynamic database access.
 
Method Summary
 float getErrRating()
          Get the error rating for the current server configuration.
 ItemRating[] getItemRatingList(int itemID)
          Return an array of userIDs who have rated the given item.
 float getMaxRating()
          Get the maximum rating allowed for the current server configuration.
 float getMinRating()
          Get the minimum rating allowed for the current server configuration.
 int getNextItemId()
           
 int getNextUserId()
           
 ItemPrediction getPredictedRating(int userID, int itemID)
          Get predicted rating for user's item.
 ItemPrediction[] getPredictedRatingList(int userID, int[] itemID)
          Gets predicted ratings for a list of items.
 ItemRating getRating(int userID, int itemID)
          Retrieves a rating for user' item from cache.
 ItemRating[] getRatingList(int userID, int[] itemIDs)
          Retrieves ratings for user's items from cache.
 ItemPrediction[] getRecommendations(int userID, int number, int offset)
          Get top n recommendation for user.
 ItemPrediction[] getRecommendationsByType(int userID, int number, int offset, int type)
          Get top n recommendations for current user of specific type.
 java.lang.String getStatistics()
           
 ItemRating[] getUserRatingList(int userID)
          Return an array of itemIDs which the given user has rated.
 void removeRating(int user, int item)
          Remove the rating from both database and the cache.
 void removeRatingList(int user, int[] itemIDs)
          Removes list of ratings from users profile
 void setRating(int user, int item, float ratingValue)
          Send a new rating the CFEngine server.
 int setRatingList(ItemRating[] newRatings)
          Add a list of new ItemRatings to both database and the cache.
 void shutdown()
          Graciously shut the server down.
 java.lang.String test()
          Test wether the CFEngine is alive on the host.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

algorithm

public java.lang.Class algorithm

newAlgObj

public java.lang.Object newAlgObj
Constructor Detail

CFEngineImpl

public CFEngineImpl()
             throws java.rmi.RemoteException
Constructor, do nothing.

Throws:
java.rmi.RemoteException

CFEngineImpl

public CFEngineImpl(java.lang.String propertiesFilename)
             throws java.rmi.RemoteException,
                    CFInternalErrorException
Constructor, create a DataManager with a mode: experiment, autotest, or server, instantiate an algorithm and start a DBManager which is reponsible for dynamic database access.

Parameters:
propertiesFilename - path and filename to the properties file that defines the configuration of this server.
Throws:
java.rmi.RemoteException
CFInternalErrorException
Method Detail

test

public java.lang.String test()
                      throws java.rmi.RemoteException
Test wether the CFEngine is alive on the host.

Specified by:
test in interface CFEngine
Returns:
String
Throws:
java.rmi.RemoteException

getRating

public ItemRating getRating(int userID,
                            int itemID)
                     throws java.rmi.RemoteException,
                            CFIllegalParameterException,
                            CFInternalErrorException
Retrieves a rating for user' item from cache. If the user has not rated the item, returns an ItemRating with an ErrRating. @see getErrRating()

Specified by:
getRating in interface CFEngine
Parameters:
userID -
itemID -
Returns:
rating
Throws:
java.rmi.RemoteException - Throws exception when connection to server is lost
CFIllegalParameterException - Throws exception if userID or Item ID are out of range
CFInternalErrorException

getRatingList

public ItemRating[] getRatingList(int userID,
                                  int[] itemIDs)
                           throws java.rmi.RemoteException,
                                  CFIllegalListParameterException,
                                  CFInternalErrorException
Retrieves ratings for user's items from cache. If the user has not rated the item, returns an ItemRating with an ErrRating. @see getErrRating()

Specified by:
getRatingList in interface CFEngine
Parameters:
userID -
itemIDs -
Returns:
Throws:
java.rmi.RemoteException
CFIllegalListParameterException - Throws exception if userID or itemID[] are invalid
CFInternalErrorException

getRecommendations

public ItemPrediction[] getRecommendations(int userID,
                                           int number,
                                           int offset)
                                    throws java.rmi.RemoteException,
                                           CFIllegalParameterException,
                                           CFInternalErrorException
Get top n recommendation for user. Returns array of size equal to the number of valid predictions in the range requested. If there are no valid recommendations in the specified range, returns 0 length array.

Specified by:
getRecommendations in interface CFEngine
Parameters:
userID - User to get recommendations for.
number - Number of recommendations to be retrieved.
offset - Returns number of recommendations, starting at the offset
Returns:
ItemPrediction[]
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception for invalid curUser, number or offset
CFInternalErrorException

getRecommendationsByType

public ItemPrediction[] getRecommendationsByType(int userID,
                                                 int number,
                                                 int offset,
                                                 int type)
                                          throws java.rmi.RemoteException,
                                                 CFIllegalParameterException,
                                                 CFInternalErrorException
Get top n recommendations for current user of specific type. Returns array of size equal to the number of valid predictions in the range requested. If there are no valid recommendations in the specified range, returns 0 length array.

Specified by:
getRecommendationsByType in interface CFEngine
Parameters:
userID - User to get recommendations for.
number - Number of recommendations to be retrieved.
offset - Returns number of recommendations, starting at the offset
type - Catagory to gat recommendations from.
Returns:
ItemPrediction[]
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception if curUser,number,offset, or type are out of range
CFInternalErrorException

getPredictedRating

public ItemPrediction getPredictedRating(int userID,
                                         int itemID)
                                  throws java.rmi.RemoteException,
                                         CFIllegalParameterException,
                                         CFInternalErrorException
Get predicted rating for user's item. If there is an error predicting rating, returns an ItemPrediction with an ErrRating. @see getErrRating()

Specified by:
getPredictedRating in interface CFEngine
Parameters:
userID -
itemID -
Returns:
predictedRating
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Thrown if userID or itemID are out of range
CFInternalErrorException

getPredictedRatingList

public ItemPrediction[] getPredictedRatingList(int userID,
                                               int[] itemID)
                                        throws java.rmi.RemoteException,
                                               CFIllegalListParameterException,
                                               CFInternalErrorException
Gets predicted ratings for a list of items. For each invalid item in itemID[], returns an ItemPrediction with a predicted value of ErrRating. @see getErrRating()

Specified by:
getPredictedRatingList in interface CFEngine
Parameters:
userID -
itemID - a list of items
Returns:
predictions
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalListParameterException - Throws exception if userID or itemID[] are invalid
CFInternalErrorException

getUserRatingList

public ItemRating[] getUserRatingList(int userID)
                               throws java.rmi.RemoteException,
                                      CFIllegalParameterException
Return an array of itemIDs which the given user has rated. Note: returns 0 length array if there are no ratings.

Specified by:
getUserRatingList in interface CFEngine
Parameters:
userID -
Returns:
an array of itemIDs
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception if userID is invalid

getItemRatingList

public ItemRating[] getItemRatingList(int itemID)
                               throws java.rmi.RemoteException,
                                      CFIllegalParameterException
Return an array of userIDs who have rated the given item. Note: returns 0 length array if there are no ratings.

Specified by:
getItemRatingList in interface CFEngine
Parameters:
itemID -
Returns:
an array of userID
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception if itemID is out of range

setRating

public void setRating(int user,
                      int item,
                      float ratingValue)
               throws java.rmi.RemoteException,
                      CFIllegalParameterException,
                      CFInternalErrorException
Send a new rating the CFEngine server. Note: If rating already exists, it replaces it.

Specified by:
setRating in interface CFEngine
Parameters:
user -
item -
ratingValue -
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception for out of range user,item, or rating
CFInternalErrorException

setRatingList

public int setRatingList(ItemRating[] newRatings)
                  throws java.rmi.RemoteException,
                         CFIllegalListParameterException,
                         CFInternalErrorException
Add a list of new ItemRatings to both database and the cache. If a rating already exists for a (user, item), then the old rating will be overwritten.

Specified by:
setRatingList in interface CFEngine
Parameters:
newRatings - a list of new ratings wanted to add
Returns:
numSuccess Returns the number of new ratings that were successfully added to the database
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalListParameterException - Throws exception if ItemRating[] has invalid contents
CFInternalErrorException

removeRating

public void removeRating(int user,
                         int item)
                  throws java.rmi.RemoteException,
                         CFIllegalParameterException,
                         CFInternalErrorException
Remove the rating from both database and the cache. Removes rating from both database and cache. If rating doesn't exist, it just returns.

Specified by:
removeRating in interface CFEngine
Parameters:
user -
item -
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalParameterException - Throws exception for out of range user or item
CFInternalErrorException

removeRatingList

public void removeRatingList(int user,
                             int[] itemIDs)
                      throws java.rmi.RemoteException,
                             CFIllegalListParameterException,
                             CFInternalErrorException
Removes list of ratings from users profile

Specified by:
removeRatingList in interface CFEngine
Parameters:
user -
itemIDs -
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error
CFIllegalListParameterException - Throws exception if userID or itemID[] are invalid
CFInternalErrorException

getMaxRating

public float getMaxRating()
                   throws java.rmi.RemoteException
Get the maximum rating allowed for the current server configuration.

Specified by:
getMaxRating in interface CFEngine
Returns:
max
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error

getMinRating

public float getMinRating()
                   throws java.rmi.RemoteException
Get the minimum rating allowed for the current server configuration.

Specified by:
getMinRating in interface CFEngine
Returns:
min
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error

getErrRating

public float getErrRating()
                   throws java.rmi.RemoteException
Get the error rating for the current server configuration.

Specified by:
getErrRating in interface CFEngine
Returns:
error rating
Throws:
java.rmi.RemoteException - Thrown upon client/server connection error

getNextUserId

public int getNextUserId()
                  throws java.rmi.RemoteException,
                         CFInternalErrorException
Specified by:
getNextUserId in interface CFEngine
Returns:
An unused integer userid that is guaranteed to be unique
java.rmi.RemoteException
CFInternalErrorException

getNextItemId

public int getNextItemId()
                  throws java.rmi.RemoteException,
                         CFInternalErrorException
Specified by:
getNextItemId in interface CFEngine
Returns:
An unused integer itemid that is guaranteed to be unique
java.rmi.RemoteException
CFInternalErrorException

getStatistics

public java.lang.String getStatistics()
                               throws java.rmi.RemoteException
Specified by:
getStatistics in interface CFEngine
Returns:
A string describing key runtime statistics of the CFEngine server, such as cache hit rate
Throws:
java.rmi.RemoteException

shutdown

public void shutdown()
              throws java.rmi.RemoteException
Graciously shut the server down. Execute all pending DB requests before exiting.

Specified by:
shutdown in interface CFEngine
Throws:
java.rmi.RemoteException

CFEngine API

Copyright © 2003 - Oregon State University www.orst.edu