Sirikata
|
PersistedObjectSet tracks the set of objects which want to be restored if the object host fails and is restored. More...
#include <SQLitePersistedObjectSet.hpp>
Public Types | |
typedef std::tr1::function < void(bool success)> | RequestCallback |
RequestCallbacks are invoked when a request to change a persisted objects properties (or remove it from persistence) completes. | |
Public Member Functions | |
SQLitePersistedObjectSet (ObjectHostContext *ctx, const String &dbpath) | |
virtual | ~SQLitePersistedObjectSet () |
virtual void | start () |
virtual void | stop () |
virtual void | requestPersistedObject (const UUID &internal_id, const String &script_type, const String &script_args, const String &script_contents, RequestCallback cb, const String ×tamp="current") |
Request that an object be marked for persistence / restoration. | |
Private Types | |
enum | UpdateResult { SUCCESS, LOCK_ERROR, TRANSACTION_ERROR } |
Private Member Functions | |
bool | checkSQLiteError (int rc, const String &msg) const |
void | initDB () |
void | performUpdateWithRetry (const UUID &internal_id, const String &script_type, const String &script_args, const String &script_contents, RequestCallback cb) |
UpdateResult | performUpdate (const UUID &internal_id, const String &script_type, const String &script_args, const String &script_contents, RequestCallback cb) |
Private Attributes | |
ObjectHostContext * | mContext |
String | mDBFilename |
SQLiteDBPtr | mDB |
Network::IOService * | mIOService |
Network::IOWork * | mWork |
Thread * | mThread |
PersistedObjectSet tracks the set of objects which want to be restored if the object host fails and is restored.
It is the counterpart to an ObjectFactory which restores objects from object storage. It has a very simple interface because it assumes the object scripts (manually or via the ObjectScript implementation) tracks almost all data itself: each object can register to be restored and only the unique internal identifier (allowing access to storage), script type, and script (allowing the object to reconstruct itself) are stored.
typedef std::tr1::function<void(bool success)> Sirikata::OH::SQLitePersistedObjectSet::RequestCallback |
RequestCallbacks are invoked when a request to change a persisted objects properties (or remove it from persistence) completes.
Reimplemented from Sirikata::OH::PersistedObjectSet.
enum Sirikata::OH::SQLitePersistedObjectSet::UpdateResult [private] |
Sirikata::OH::SQLitePersistedObjectSet::SQLitePersistedObjectSet | ( | ObjectHostContext * | ctx, |
const String & | dbpath | ||
) |
Sirikata::OH::SQLitePersistedObjectSet::~SQLitePersistedObjectSet | ( | ) | [virtual] |
bool Sirikata::OH::SQLitePersistedObjectSet::checkSQLiteError | ( | int | rc, |
const String & | msg | ||
) | const [private] |
References Sirikata::SQLite::check_sql_error(), Sirikata::Logging::error, mDB, and SILOG.
Referenced by initDB(), and performUpdate().
void Sirikata::OH::SQLitePersistedObjectSet::initDB | ( | ) | [private] |
References checkSQLiteError(), Sirikata::SQLite::getSingleton(), mDB, mDBFilename, Sirikata::SQLite::open(), and TABLE_NAME.
Referenced by start().
SQLitePersistedObjectSet::UpdateResult Sirikata::OH::SQLitePersistedObjectSet::performUpdate | ( | const UUID & | internal_id, |
const String & | script_type, | ||
const String & | script_args, | ||
const String & | script_contents, | ||
RequestCallback | cb | ||
) | [private] |
References checkSQLiteError(), Sirikata::Logging::error, LOCK_ERROR, mDB, Sirikata::UUID::rawHexData(), Sirikata::SQLite::resultAsString(), SILOG, SUCCESS, TABLE_NAME, and TRANSACTION_ERROR.
Referenced by performUpdateWithRetry().
void Sirikata::OH::SQLitePersistedObjectSet::performUpdateWithRetry | ( | const UUID & | internal_id, |
const String & | script_type, | ||
const String & | script_args, | ||
const String & | script_contents, | ||
RequestCallback | cb | ||
) | [private] |
References Sirikata::Logging::error, LOCK_ERROR, Sirikata::Context::mainStrand, mContext, performUpdate(), Sirikata::Network::IOStrand::post(), SILOG, Sirikata::Timer::sleep(), and SUCCESS.
Referenced by requestPersistedObject().
void Sirikata::OH::SQLitePersistedObjectSet::requestPersistedObject | ( | const UUID & | internal_id, |
const String & | script_type, | ||
const String & | script_args, | ||
const String & | script_contents, | ||
RequestCallback | cb, | ||
const String & | timestamp = "current" |
||
) | [virtual] |
Request that an object be marked for persistence / restoration.
If script_type and script_args are left blank, the restoration of the object will be disabled (e.g. if the object is being destroyed).
internal_id | the internal identifier used by the HostedObject. This should always be read from the HostedObject as it will be used to restore access to the appropriate stored data. |
script_type | the type of script the object is running, e.g. 'js' or 'python' |
script_args | arguments to the script to ensure it is in the same state as it was originally loaded in |
script_contents | the actual script text to be executed, usually bootstrapping code which then loads data from storage |
cb | callback to invoke when the operation completes |
Implements Sirikata::OH::PersistedObjectSet.
References mIOService, performUpdateWithRetry(), and Sirikata::Network::IOService::post().
void Sirikata::OH::SQLitePersistedObjectSet::start | ( | ) | [virtual] |
Reimplemented from Sirikata::OH::PersistedObjectSet.
References initDB(), mIOService, mThread, mWork, Sirikata::Network::IOService::post(), and Sirikata::Network::IOService::runNoReturn().
void Sirikata::OH::SQLitePersistedObjectSet::stop | ( | ) | [virtual] |
Reimplemented from Sirikata::OH::PersistedObjectSet.
References Sirikata::Thread::join(), mIOService, mThread, and mWork.
Referenced by performUpdateWithRetry().
Referenced by checkSQLiteError(), initDB(), and performUpdate().
String Sirikata::OH::SQLitePersistedObjectSet::mDBFilename [private] |
Referenced by initDB().
Referenced by requestPersistedObject(), start(), and stop().