diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-16 14:55:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-21 09:02:21 +0200 |
commit | 237b9ae4113e7a9f489632296941becb71afdb45 (patch) | |
tree | 01cde58f495944f01cad9d282391d4efd2897141 /common/synchronizer.h | |
parent | 95d11bf0be98a4e3c08502fe23417b800233ce14 (diff) | |
download | sink-237b9ae4113e7a9f489632296941becb71afdb45.tar.gz sink-237b9ae4113e7a9f489632296941becb71afdb45.zip |
Refactor how the storage is used.
This is the initial refactoring to improve how we deal with the storage.
It does a couple of things:
* Rename Sink::Storage to Sink::Storage::DataStore to free up the
Sink::Storage namespace
* Introduce a Sink::ResourceContext to have a single object that can be
passed around containing everything that is necessary to operate on a
resource. This is a lot better than the multiple separate parameters
that we used to pass around all over the place, while still allowing
for dependency injection for tests.
* Tie storage access together using the new EntityStore that directly
works with ApplicationDomainTypes. This gives us a central place where
main storage, indexes and buffer adaptors are tied together, which
will also give us a place to implement external indexes, such as a
fulltextindex using xapian.
* Use ApplicationDomainTypes as the default way to pass around entities.
Instead of using various ways to pass around entities (buffers,
buffer adaptors, ApplicationDomainTypes), only use a single way.
The old approach was confusing, and was only done as:
* optimization; really shouldn't be necessary and otherwise I'm sure
we can find better ways to optimize ApplicationDomainType itself.
* a way to account for entities that have multiple buffers, a concept
that I no longer deem relevant.
While this commit does the bulk of the work to get there, the following
commits will refactor more stuff to get things back to normal.
Diffstat (limited to 'common/synchronizer.h')
-rw-r--r-- | common/synchronizer.h | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/common/synchronizer.h b/common/synchronizer.h index 5f60128..f3319f6 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -37,31 +37,28 @@ class RemoteIdMap; | |||
37 | class SINK_EXPORT Synchronizer | 37 | class SINK_EXPORT Synchronizer |
38 | { | 38 | { |
39 | public: | 39 | public: |
40 | Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); | 40 | Synchronizer(const Sink::ResourceContext &resourceContext); |
41 | virtual ~Synchronizer(); | 41 | virtual ~Synchronizer(); |
42 | 42 | ||
43 | void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &messageQueue); | 43 | void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &messageQueue); |
44 | KAsync::Job<void> synchronize(); | 44 | KAsync::Job<void> synchronize(); |
45 | 45 | ||
46 | //Read only access to main storage | 46 | //Read only access to main storage |
47 | EntityStore &store(); | 47 | Storage::EntityStore &store(); |
48 | 48 | ||
49 | //Read/Write access to sync storage | 49 | //Read/Write access to sync storage |
50 | RemoteIdMap &syncStore(); | 50 | RemoteIdMap &syncStore(); |
51 | 51 | ||
52 | void commit(); | 52 | void commit(); |
53 | Sink::Storage::Transaction &transaction(); | 53 | Sink::Storage::DataStore::Transaction &syncTransaction(); |
54 | Sink::Storage::Transaction &syncTransaction(); | ||
55 | 54 | ||
56 | protected: | 55 | protected: |
57 | ///Calls the callback to enqueue the command | 56 | ///Calls the callback to enqueue the command |
58 | void enqueueCommand(int commandId, const QByteArray &data); | 57 | void enqueueCommand(int commandId, const QByteArray &data); |
59 | 58 | ||
60 | static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, | 59 | void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject); |
61 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback); | 60 | void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject); |
62 | static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, | 61 | void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType); |
63 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback); | ||
64 | static void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, std::function<void(const QByteArray &)> callback); | ||
65 | 62 | ||
66 | /** | 63 | /** |
67 | * A synchronous algorithm to remove entities that are no longer existing. | 64 | * A synchronous algorithm to remove entities that are no longer existing. |
@@ -74,7 +71,8 @@ protected: | |||
74 | * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. | 71 | * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. |
75 | */ | 72 | */ |
76 | void scanForRemovals(const QByteArray &bufferType, | 73 | void scanForRemovals(const QByteArray &bufferType, |
77 | const std::function<void(const std::function<void(const QByteArray &key)> &callback)> &entryGenerator, std::function<bool(const QByteArray &remoteId)> exists); | 74 | const std::function<void(const std::function<void(const QByteArray &sinkId)> &callback)> &entryGenerator, std::function<bool(const QByteArray &remoteId)> exists); |
75 | void scanForRemovals(const QByteArray &bufferType, std::function<bool(const QByteArray &remoteId)> exists); | ||
78 | 76 | ||
79 | /** | 77 | /** |
80 | * An algorithm to create or modify the entity. | 78 | * An algorithm to create or modify the entity. |
@@ -96,14 +94,13 @@ protected: | |||
96 | virtual KAsync::Job<void> synchronizeWithSource() = 0; | 94 | virtual KAsync::Job<void> synchronizeWithSource() = 0; |
97 | 95 | ||
98 | private: | 96 | private: |
97 | void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity); | ||
98 | |||
99 | Sink::ResourceContext mResourceContext; | ||
100 | Sink::Storage::EntityStore::Ptr mEntityStore; | ||
99 | QSharedPointer<RemoteIdMap> mSyncStore; | 101 | QSharedPointer<RemoteIdMap> mSyncStore; |
100 | QSharedPointer<EntityStore> mEntityStore; | 102 | Sink::Storage::DataStore mSyncStorage; |
101 | Sink::Storage mStorage; | 103 | Sink::Storage::DataStore::Transaction mSyncTransaction; |
102 | Sink::Storage mSyncStorage; | ||
103 | QByteArray mResourceType; | ||
104 | QByteArray mResourceInstanceIdentifier; | ||
105 | Sink::Storage::Transaction mTransaction; | ||
106 | Sink::Storage::Transaction mSyncTransaction; | ||
107 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; | 104 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; |
108 | MessageQueue *mMessageQueue; | 105 | MessageQueue *mMessageQueue; |
109 | bool mSyncInProgress; | 106 | bool mSyncInProgress; |