From 0f75ad4b96ec5994c022109278cad28a43255793 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 3 Dec 2015 11:17:08 +0100 Subject: 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. --- common/clientapi.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'common/clientapi.cpp') 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 Store::remove(const DomainType &domainObject) KAsync::Job Store::shutdown(const QByteArray &identifier) { - Trace() << "shutdown"; + Trace() << "shutdown " << identifier; return ResourceAccess::connectToServer(identifier).then>([identifier](QSharedPointer socket, KAsync::Future &future) { //We can't currently reuse the socket socket->close(); auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then([&future, resourceAccess]() { + Trace() << "Shutdown complete"; future.setFinished(); }).exec(); }, [](int, const QString &) { + Trace() << "Resource is already closed."; //Resource isn't started, nothing to shutdown }) //FIXME JOBAPI this is only required because we don't care about the return value of connectToServer .template then([](){}); } +KAsync::Job Store::start(const QByteArray &identifier) +{ + Trace() << "start " << identifier; + auto resourceAccess = QSharedPointer::create(identifier); + resourceAccess->open(); + return resourceAccess->sendCommand(Akonadi2::Commands::PingCommand).then([resourceAccess]() { + Trace() << "Start complete"; + }); +} + KAsync::Job Store::synchronize(const Akonadi2::Query &query) { Trace() << "synchronize"; -- cgit v1.2.3