diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-03 11:17:08 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-03 11:23:25 +0100 |
commit | 0f75ad4b96ec5994c022109278cad28a43255793 (patch) | |
tree | 6d7c6153025a79557dd1218d9be0a4a7cb7945c5 /common/clientapi.cpp | |
parent | 2c80424031c195333cfa6785ea7ab57dc9613fa3 (diff) | |
download | sink-0f75ad4b96ec5994c022109278cad28a43255793.tar.gz sink-0f75ad4b96ec5994c022109278cad28a43255793.zip |
Improved resource access caching
* Smarter caching. ResourceAccess instances close after a timeout, if not reused.
* Introduced a start command to avoid race condition when sending
commands to a resource that is currently shutting down.
* We resend pending commands after we lost access to the resource
* unexpectedly.
Diffstat (limited to 'common/clientapi.cpp')
-rw-r--r-- | common/clientapi.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index b732205..3dc9370 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -149,23 +149,35 @@ KAsync::Job<void> Store::remove(const DomainType &domainObject) | |||
149 | 149 | ||
150 | KAsync::Job<void> Store::shutdown(const QByteArray &identifier) | 150 | KAsync::Job<void> Store::shutdown(const QByteArray &identifier) |
151 | { | 151 | { |
152 | Trace() << "shutdown"; | 152 | Trace() << "shutdown " << identifier; |
153 | return ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) { | 153 | return ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) { |
154 | //We can't currently reuse the socket | 154 | //We can't currently reuse the socket |
155 | socket->close(); | 155 | socket->close(); |
156 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier); | 156 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier); |
157 | resourceAccess->open(); | 157 | resourceAccess->open(); |
158 | resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then<void>([&future, resourceAccess]() { | 158 | resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then<void>([&future, resourceAccess]() { |
159 | Trace() << "Shutdown complete"; | ||
159 | future.setFinished(); | 160 | future.setFinished(); |
160 | }).exec(); | 161 | }).exec(); |
161 | }, | 162 | }, |
162 | [](int, const QString &) { | 163 | [](int, const QString &) { |
164 | Trace() << "Resource is already closed."; | ||
163 | //Resource isn't started, nothing to shutdown | 165 | //Resource isn't started, nothing to shutdown |
164 | }) | 166 | }) |
165 | //FIXME JOBAPI this is only required because we don't care about the return value of connectToServer | 167 | //FIXME JOBAPI this is only required because we don't care about the return value of connectToServer |
166 | .template then<void>([](){}); | 168 | .template then<void>([](){}); |
167 | } | 169 | } |
168 | 170 | ||
171 | KAsync::Job<void> Store::start(const QByteArray &identifier) | ||
172 | { | ||
173 | Trace() << "start " << identifier; | ||
174 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier); | ||
175 | resourceAccess->open(); | ||
176 | return resourceAccess->sendCommand(Akonadi2::Commands::PingCommand).then<void>([resourceAccess]() { | ||
177 | Trace() << "Start complete"; | ||
178 | }); | ||
179 | } | ||
180 | |||
169 | KAsync::Job<void> Store::synchronize(const Akonadi2::Query &query) | 181 | KAsync::Job<void> Store::synchronize(const Akonadi2::Query &query) |
170 | { | 182 | { |
171 | Trace() << "synchronize"; | 183 | Trace() << "synchronize"; |