summaryrefslogtreecommitdiffstats
path: root/examples/mailtransportresource
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-16 14:55:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:02:21 +0200
commit237b9ae4113e7a9f489632296941becb71afdb45 (patch)
tree01cde58f495944f01cad9d282391d4efd2897141 /examples/mailtransportresource
parent95d11bf0be98a4e3c08502fe23417b800233ce14 (diff)
downloadsink-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 'examples/mailtransportresource')
-rw-r--r--examples/mailtransportresource/mailtransportresource.cpp32
-rw-r--r--examples/mailtransportresource/mailtransportresource.h4
2 files changed, 18 insertions, 18 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp
index 3ce9476..9a22c41 100644
--- a/examples/mailtransportresource/mailtransportresource.cpp
+++ b/examples/mailtransportresource/mailtransportresource.cpp
@@ -41,6 +41,7 @@
41#include <pipeline.h> 41#include <pipeline.h>
42#include <mailpreprocessor.h> 42#include <mailpreprocessor.h>
43#include <indexupdater.h> 43#include <indexupdater.h>
44#include <adaptorfactoryregistry.h>
44 45
45#define ENTITY_TYPE_MAIL "mail" 46#define ENTITY_TYPE_MAIL "mail"
46 47
@@ -52,7 +53,7 @@ using namespace Sink;
52class MailtransportWriteback : public Sink::SourceWriteBack 53class MailtransportWriteback : public Sink::SourceWriteBack
53{ 54{
54public: 55public:
55 MailtransportWriteback(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) : Sink::SourceWriteBack(resourceType, resourceInstanceIdentifier) 56 MailtransportWriteback(const Sink::ResourceContext &resourceContext) : Sink::SourceWriteBack(resourceContext)
56 { 57 {
57 58
58 } 59 }
@@ -74,9 +75,9 @@ public:
74 75
75class MailtransportSynchronizer : public Sink::Synchronizer { 76class MailtransportSynchronizer : public Sink::Synchronizer {
76public: 77public:
77 MailtransportSynchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) 78 MailtransportSynchronizer(const Sink::ResourceContext &resourceContext)
78 : Sink::Synchronizer(resourceType, resourceInstanceIdentifier), 79 : Sink::Synchronizer(resourceContext),
79 mResourceInstanceIdentifier(resourceInstanceIdentifier) 80 mResourceInstanceIdentifier(resourceContext.instanceId())
80 { 81 {
81 82
82 } 83 }
@@ -112,10 +113,9 @@ public:
112 { 113 {
113 SinkLog() << " Synchronizing"; 114 SinkLog() << " Synchronizing";
114 return KAsync::start<void>([this](KAsync::Future<void> future) { 115 return KAsync::start<void>([this](KAsync::Future<void> future) {
115 Sink::Query query;
116 QList<ApplicationDomain::Mail> toSend; 116 QList<ApplicationDomain::Mail> toSend;
117 SinkLog() << " Looking for mail"; 117 SinkLog() << " Looking for mail";
118 store().reader<ApplicationDomain::Mail>().query(query, [&](const ApplicationDomain::Mail &mail) -> bool { 118 store().readAll<ApplicationDomain::Mail>([&](const ApplicationDomain::Mail &mail) -> bool {
119 SinkTrace() << "Found mail: " << mail.identifier(); 119 SinkTrace() << "Found mail: " << mail.identifier();
120 if (!mail.getSent()) { 120 if (!mail.getSent()) {
121 toSend << mail; 121 toSend << mail;
@@ -143,10 +143,10 @@ public:
143 MailtransportResource::Settings mSettings; 143 MailtransportResource::Settings mSettings;
144}; 144};
145 145
146MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline) 146MailtransportResource::MailtransportResource(const Sink::ResourceContext &resourceContext, const QSharedPointer<Sink::Pipeline> &pipeline)
147 : Sink::GenericResource(PLUGIN_NAME, instanceIdentifier, pipeline) 147 : Sink::GenericResource(resourceContext, pipeline)
148{ 148{
149 auto config = ResourceConfig::getConfiguration(instanceIdentifier); 149 auto config = ResourceConfig::getConfiguration(resourceContext.instanceId());
150 mSettings = {config.value("server").toString(), 150 mSettings = {config.value("server").toString(),
151 config.value("username").toString(), 151 config.value("username").toString(),
152 config.value("cacert").toString(), 152 config.value("cacert").toString(),
@@ -154,11 +154,11 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie
154 config.value("testmode").toBool() 154 config.value("testmode").toBool()
155 }; 155 };
156 156
157 auto synchronizer = QSharedPointer<MailtransportSynchronizer>::create(PLUGIN_NAME, instanceIdentifier); 157 auto synchronizer = QSharedPointer<MailtransportSynchronizer>::create(resourceContext);
158 synchronizer->mSettings = mSettings; 158 synchronizer->mSettings = mSettings;
159 setupSynchronizer(synchronizer); 159 setupSynchronizer(synchronizer);
160 160
161 auto changereplay = QSharedPointer<MailtransportWriteback>::create(PLUGIN_NAME, instanceIdentifier); 161 auto changereplay = QSharedPointer<MailtransportWriteback>::create(resourceContext);
162 changereplay->mSettings = mSettings; 162 changereplay->mSettings = mSettings;
163 setupChangereplay(changereplay); 163 setupChangereplay(changereplay);
164 164
@@ -168,14 +168,14 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie
168void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) 168void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier)
169{ 169{
170 GenericResource::removeFromDisk(instanceIdentifier); 170 GenericResource::removeFromDisk(instanceIdentifier);
171 Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::ReadWrite).removeFromDisk(); 171 Sink::Storage::DataStore(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::DataStore::ReadWrite).removeFromDisk();
172} 172}
173 173
174KAsync::Job<void> MailtransportResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) 174KAsync::Job<void> MailtransportResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue)
175{ 175{
176 if (domainType == ENTITY_TYPE_MAIL) { 176 if (domainType == ENTITY_TYPE_MAIL) {
177 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { 177 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) {
178 auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/" + entityId; 178 auto path = resourceStorageLocation(mResourceContext.instanceId()) + "/test/" + entityId;
179 if (QFileInfo::exists(path)) { 179 if (QFileInfo::exists(path)) {
180 return KAsync::null<void>(); 180 return KAsync::null<void>();
181 } 181 }
@@ -191,14 +191,14 @@ MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent)
191 191
192} 192}
193 193
194Sink::Resource *MailtransportResourceFactory::createResource(const QByteArray &instanceIdentifier) 194Sink::Resource *MailtransportResourceFactory::createResource(const Sink::ResourceContext &context)
195{ 195{
196 return new MailtransportResource(instanceIdentifier); 196 return new MailtransportResource(context);
197} 197}
198 198
199void MailtransportResourceFactory::registerFacades(Sink::FacadeFactory &factory) 199void MailtransportResourceFactory::registerFacades(Sink::FacadeFactory &factory)
200{ 200{
201 factory.registerFacade<ApplicationDomain::Mail, DefaultFacade<ApplicationDomain::Mail, DomainTypeAdaptorFactory<ApplicationDomain::Mail>>>(PLUGIN_NAME); 201 factory.registerFacade<ApplicationDomain::Mail, DefaultFacade<ApplicationDomain::Mail>>(PLUGIN_NAME);
202} 202}
203 203
204void MailtransportResourceFactory::registerAdaptorFactories(Sink::AdaptorFactoryRegistry &registry) 204void MailtransportResourceFactory::registerAdaptorFactories(Sink::AdaptorFactoryRegistry &registry)
diff --git a/examples/mailtransportresource/mailtransportresource.h b/examples/mailtransportresource/mailtransportresource.h
index dcc33df..212880c 100644
--- a/examples/mailtransportresource/mailtransportresource.h
+++ b/examples/mailtransportresource/mailtransportresource.h
@@ -28,7 +28,7 @@
28class MailtransportResource : public Sink::GenericResource 28class MailtransportResource : public Sink::GenericResource
29{ 29{
30public: 30public:
31 MailtransportResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>()); 31 MailtransportResource(const Sink::ResourceContext &resourceContext, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>());
32 KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; 32 KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE;
33 static void removeFromDisk(const QByteArray &instanceIdentifier); 33 static void removeFromDisk(const QByteArray &instanceIdentifier);
34 34
@@ -52,7 +52,7 @@ class MailtransportResourceFactory : public Sink::ResourceFactory
52public: 52public:
53 MailtransportResourceFactory(QObject *parent = 0); 53 MailtransportResourceFactory(QObject *parent = 0);
54 54
55 Sink::Resource *createResource(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; 55 Sink::Resource *createResource(const Sink::ResourceContext &resourceContext) Q_DECL_OVERRIDE;
56 void registerFacades(Sink::FacadeFactory &factory) Q_DECL_OVERRIDE; 56 void registerFacades(Sink::FacadeFactory &factory) Q_DECL_OVERRIDE;
57 void registerAdaptorFactories(Sink::AdaptorFactoryRegistry &registry) Q_DECL_OVERRIDE; 57 void registerAdaptorFactories(Sink::AdaptorFactoryRegistry &registry) Q_DECL_OVERRIDE;
58 void removeDataFromDisk(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; 58 void removeDataFromDisk(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE;