Methods Summary |
---|
public android.os.IBinder | getSessionBinder(java.lang.Class learnerClass, android.bordeaux.services.BordeauxSessionManager$SessionKey key)
if (mSessions.containsKey(key.value)) {
return mSessions.get(key.value).learner.getBinder();
}
// not in memory cache
try {
// try to find it in the database
Session stored = mSessionStorage.getSession(key.value);
if (stored != null) {
// set the callback, so that we can save the state
stored.learner.setModelChangeCallback(new LearningUpdateCallback(key.value));
// found session in the storage, put in the cache
mSessions.put(key.value, stored);
return stored.learner.getBinder();
}
// if session is not already stored, create a new one.
Log.i(TAG, "create a new learning session: " + key.value);
IBordeauxLearner learner =
(IBordeauxLearner) learnerClass.getConstructor().newInstance();
// set the callback, so that we can save the state
learner.setModelChangeCallback(new LearningUpdateCallback(key.value));
Session session = new Session();
session.learnerClass = learnerClass;
session.learner = learner;
mSessions.put(key.value, session);
return learner.getBinder();
} catch (Exception e) {
throw new RuntimeException("Can't instantiate class: " +
learnerClass.getName());
}
|
public android.bordeaux.services.BordeauxSessionManager$SessionKey | getSessionKey(java.lang.String callingUid, java.lang.Class learnerClass, java.lang.String name)
SessionKey key = new SessionKey();
key.value = callingUid + "#" + "_" + name + "_" + learnerClass.getName();
return key;
|
public void | loadSessions()
synchronized(mSessions) {
mSessionStorage.getAllSessions(mSessions);
for (Map.Entry<String, Session> session : mSessions.entrySet()) {
// set the callback, so that we can save the state
session.getValue().learner.setModelChangeCallback(
new LearningUpdateCallback(session.getKey()));
}
}
|
public void | removeAllSessionsFromCaller(java.lang.String callingUid)
// remove in the hash table
ArrayList<String> remove_keys = new ArrayList<String>();
for (Map.Entry<String, Session> session : mSessions.entrySet()) {
if (session.getKey().startsWith(callingUid + "#")) {
remove_keys.add(session.getKey());
}
}
for (String key : remove_keys) {
mSessions.remove(key);
}
// remove all session data from the callingUid in database
// % is used as wild match for the rest of the string in sql
int nDeleted = mSessionStorage.removeSessions(callingUid + "#%");
if (nDeleted > 0)
Log.i(TAG, "Successfully deleted " + nDeleted + "sessions");
|
public boolean | saveSession(android.bordeaux.services.BordeauxSessionManager$SessionKey key)
Session session = mSessions.get(key.value);
if (session != null) {
synchronized(session) {
byte[] model = session.learner.getModel();
// write to database
boolean res = mSessionStorage.saveSession(key.value, session.learnerClass, model);
if (res)
session.modified = false;
else {
Log.e(TAG, "Can't save session: " + key.value);
}
return res;
}
}
Log.e(TAG, "Session not found: " + key.value);
return false;
|
public void | saveSessions()
for (Map.Entry<String, Session> session : mSessions.entrySet()) {
synchronized(session) {
// Save the session if it's modified.
if (session.getValue().modified) {
SessionKey skey = new SessionKey();
skey.value = session.getKey();
saveSession(skey);
}
}
}
|