generationManager.append(userID, itemID, value, bulk);
} catch (IOException ioe) {
log.warn("Could not append datum; continuing", ioe);
}
Generation generation;
try {
generation = getCurrentGeneration();
} catch (NotReadyException nre) {
// Corner case -- no model ready so all we can do is record (above). Don't fail the request.
return;
}
float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock());
boolean newItem;
Lock yReadLock = generation.getYLock().readLock();
yReadLock.lock();
try {
newItem = generation.getY().get(itemID) == null;
} finally {
yReadLock.unlock();
}
if (newItem) {
generation.getCandidateFilter().addItem(itemID);
}
float[] itemFeatures = getFeatures(itemID, generation.getY(), generation.getYLock());
updateFeatures(userFeatures, itemFeatures, value, generation);
FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
if (knownItemIDs != null) {
FastIDSet userKnownItemIDs;
ReadWriteLock knownItemLock = generation.getKnownItemLock();
Lock knownItemReadLock = knownItemLock.readLock();
knownItemReadLock.lock();
try {
userKnownItemIDs = knownItemIDs.get(userID);
if (userKnownItemIDs == null) {
userKnownItemIDs = new FastIDSet();
Lock knownItemWriteLock = knownItemLock.writeLock();
knownItemReadLock.unlock();
knownItemWriteLock.lock();
try {
knownItemIDs.put(userID, userKnownItemIDs);
} finally {
knownItemReadLock.lock();
knownItemWriteLock.unlock();
}
}
} finally {
knownItemReadLock.unlock();
}
synchronized (userKnownItemIDs) {
userKnownItemIDs.add(itemID);
}
}
updateClusters(userID, userFeatures, generation.getUserClusters(), generation.getUserClustersLock().readLock());
updateClusters(itemID, itemFeatures, generation.getItemClusters(), generation.getItemClustersLock().readLock());
}