public final class PlusAnonymousConcurrentUserDataModel extends PlusAnonymousUserDataModel
This is a special thread-safe version of PlusAnonymousUserDataModel
which allow multiple concurrent anonymous requests.
To use it, you have to estimate the number of concurrent anonymous users of your application. The pool of users with the given size will be created. For each anonymous recommendations request, a user has to be taken from the pool and returned back immediately afterwards.
If no more users are available in the pool, anonymous recommendations cannot be produced.
Setup:int concurrentUsers = 100; DataModel realModel = .. PlusAnonymousConcurrentUserDataModel plusModel = new PlusAnonymousConcurrentUserDataModel(realModel, concurrentUsers); Recommender recommender = ...;Real-time recommendation:
PlusAnonymousConcurrentUserDataModel plusModel = (PlusAnonymousConcurrentUserDataModel) recommender.getDataModel(); // Take the next available anonymous user from the pool Long anonymousUserID = plusModel.takeAvailableUser(); PreferenceArray tempPrefs = .. tempPrefs.setUserID(0, anonymousUserID); tempPrefs.setItemID(0, itemID); plusModel.setTempPrefs(tempPrefs, anonymousUserID); // Produce recommendations recommender.recommend(anonymousUserID, howMany); // It is very IMPORTANT to release user back to the pool plusModel.releaseUser(anonymousUserID);
TEMP_USER_ID| Constructor and Description |
|---|
PlusAnonymousConcurrentUserDataModel(DataModel delegate,
int maxConcurrentUsers) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearTempPrefs(long anonymousUserID)
Clears temporary preferences for a given anonymous user.
|
FastIDSet |
getItemIDsFromUser(long userID) |
int |
getNumUsers() |
int |
getNumUsersWithPreferenceFor(long itemID) |
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2) |
PreferenceArray |
getPreferencesForItem(long itemID) |
PreferenceArray |
getPreferencesFromUser(long userID) |
Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known.
|
Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item.
|
LongPrimitiveIterator |
getUserIDs() |
boolean |
releaseUser(Long userID)
Release previously taken anonymous user and return it to the pool.
|
void |
removePreference(long userID,
long itemID)
Removes a particular preference for a user.
|
void |
setPreference(long userID,
long itemID,
float value)
Sets a particular preference (item plus rating) for a user.
|
void |
setTempPrefs(PreferenceArray prefs,
long anonymousUserID)
Sets temporary preferences for a given anonymous user.
|
Long |
takeAvailableUser()
Take the next available concurrent anonymous users from the pool.
|
clearTempPrefs, getDelegate, getItemIDs, getMaxPreference, getMinPreference, getNumItems, hasPreferenceValues, refresh, setTempPrefspublic PlusAnonymousConcurrentUserDataModel(DataModel delegate, int maxConcurrentUsers)
delegate - Real model where anonymous users will be added tomaxConcurrentUsers - Maximum allowed number of concurrent anonymous userspublic Long takeAvailableUser()
public boolean releaseUser(Long userID)
userID - ID of a previously taken anonymous userpublic void setTempPrefs(PreferenceArray prefs, long anonymousUserID)
public void clearTempPrefs(long anonymousUserID)
public LongPrimitiveIterator getUserIDs() throws TasteException
getUserIDs in interface DataModelgetUserIDs in class PlusAnonymousUserDataModelTasteException - if an error occurs while accessing the datapublic PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser in interface DataModelgetPreferencesFromUser in class PlusAnonymousUserDataModeluserID - ID of user to get prefs forNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the datapublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser in interface DataModelgetItemIDsFromUser in class PlusAnonymousUserDataModeluserID - ID of user to get prefs forNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the datapublic PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem in interface DataModelgetPreferencesForItem in class PlusAnonymousUserDataModelitemID - item IDPreferences expressed for that item, ordered by user ID, as an arrayNoSuchItemException - if the item does not existTasteException - if an error occurs while accessing the datapublic Float getPreferenceValue(long userID, long itemID) throws TasteException
DataModelgetPreferenceValue in interface DataModelgetPreferenceValue in class PlusAnonymousUserDataModeluserID - user ID to get pref value fromitemID - item ID to get pref value forNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the datapublic Long getPreferenceTime(long userID, long itemID) throws TasteException
DataModelgetPreferenceTime in interface DataModelgetPreferenceTime in class PlusAnonymousUserDataModeluserID - user ID for preference in questionitemID - item ID for preference in questionNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the datapublic int getNumUsers()
throws TasteException
getNumUsers in interface DataModelgetNumUsers in class PlusAnonymousUserDataModelTasteException - if an error occurs while accessing the datapublic int getNumUsersWithPreferenceFor(long itemID)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelgetNumUsersWithPreferenceFor in class PlusAnonymousUserDataModelitemID - item ID to check forTasteException - if an error occurs while accessing the datapublic int getNumUsersWithPreferenceFor(long itemID1,
long itemID2)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelgetNumUsersWithPreferenceFor in class PlusAnonymousUserDataModelitemID1 - first item ID to check foritemID2 - second item ID to check forTasteException - if an error occurs while accessing the datapublic void setPreference(long userID,
long itemID,
float value)
throws TasteException
DataModelSets a particular preference (item plus rating) for a user.
setPreference in interface DataModelsetPreference in class PlusAnonymousUserDataModeluserID - user to set preference foritemID - item to set preference forvalue - preference valueNoSuchItemException - if the item does not existNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the datapublic void removePreference(long userID,
long itemID)
throws TasteException
DataModelRemoves a particular preference for a user.
removePreference in interface DataModelremovePreference in class PlusAnonymousUserDataModeluserID - user from which to remove preferenceitemID - item to remove preference forNoSuchItemException - if the item does not existNoSuchUserException - if the user does not existTasteException - if an error occurs while accessing the dataCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.