From cb8b6cfe8d448176a53ed42a2a36bee6d3853319 Mon Sep 17 00:00:00 2001 From: fbraem Date: Mon, 2 Nov 2015 22:08:27 +0100 Subject: [PATCH] Renamed AsyncClient into AsyncReader --- Redis/Makefile | 2 +- Redis/include/Poco/Redis/AsyncClient.h | 98 -------------------------- Redis/include/Poco/Redis/AsyncReader.h | 92 ++++++++++++++++++++++++ Redis/src/AsyncClient.cpp | 75 -------------------- Redis/src/AsyncReader.cpp | 57 +++++++++++++++ 5 files changed, 150 insertions(+), 174 deletions(-) delete mode 100644 Redis/include/Poco/Redis/AsyncClient.h create mode 100644 Redis/include/Poco/Redis/AsyncReader.h delete mode 100644 Redis/src/AsyncClient.cpp create mode 100644 Redis/src/AsyncReader.cpp diff --git a/Redis/Makefile b/Redis/Makefile index 4443b01c6..b110ce63e 100644 --- a/Redis/Makefile +++ b/Redis/Makefile @@ -10,7 +10,7 @@ include $(POCO_BASE)/build/rules/global INCLUDE += -I $(POCO_BASE)/Redis/include/Poco/Redis -objects = AsyncClient Array Client Error Exception RedisSocket Type +objects = AsyncReader Array Client Error Exception RedisSocket Type target = PocoRedis target_version = $(LIBVERSION) diff --git a/Redis/include/Poco/Redis/AsyncClient.h b/Redis/include/Poco/Redis/AsyncClient.h deleted file mode 100644 index 6541bab23..000000000 --- a/Redis/include/Poco/Redis/AsyncClient.h +++ /dev/null @@ -1,98 +0,0 @@ -// -// AsyncClient.h -// -// $Id$ -// -// Library: Redis -// Package: Redis -// Module: AsyncClient -// -// Definition of the AsyncClient class. -// -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Redis_AsyncClient_INCLUDED -#define Redis_AsyncClient_INCLUDED - - -#include "Poco/Redis/Redis.h" -#include "Poco/Redis/Client.h" -#include "Poco/Activity.h" - -namespace Poco { -namespace Redis { - - -class Redis_API AsyncClient : public Client -{ -public: - - - BasicEvent redisResponse; - - - AsyncClient(); - /// Default constructor. Use this when you want to - /// connect later on. - - AsyncClient(const std::string& hostAndPort); - /// Constructor which connects to the given Redis host/port. - /// The host and port must be separated with a colon. - - AsyncClient(const std::string& host, int port); - /// Constructor which connects to the given Redis host/port. - - AsyncClient(const Net::SocketAddress& addrs); - /// Constructor which connects to the given Redis host/port. - - virtual ~AsyncClient(); - /// Destructor - - bool isStopped(); - /// Returns true if the activity is not running, false when it is. - - void start(); - /// Starts the activity to read replies from the Redis server. - - void stop(); - /// Stops the read activity. - -protected: - - void runActivity(); - -private: - - AsyncClient(const AsyncClient&); - AsyncClient& operator = (const AsyncClient&); - - - Activity _activity; - -}; - - -inline bool AsyncClient::isStopped() -{ - return _activity.isStopped(); -} - -inline void AsyncClient::start() -{ - _activity.start(); -} - -inline void AsyncClient::stop() -{ - _activity.stop(); -} - - -} } // namespace Poco::Redis - -#endif //Redis_Client_INCLUDED diff --git a/Redis/include/Poco/Redis/AsyncReader.h b/Redis/include/Poco/Redis/AsyncReader.h new file mode 100644 index 000000000..79ce85b37 --- /dev/null +++ b/Redis/include/Poco/Redis/AsyncReader.h @@ -0,0 +1,92 @@ +// +// AsyncReader.h +// +// $Id$ +// +// Library: Redis +// Package: Redis +// Module: AsyncReader +// +// Definition of the AsyncReader class. +// +// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Redis_AsyncReader_INCLUDED +#define Redis_AsyncReader_INCLUDED + + +#include "Poco/Redis/Redis.h" +#include "Poco/Redis/Client.h" +#include "Poco/Activity.h" + +namespace Poco { +namespace Redis { + + +class Redis_API AsyncReader + /// Wrapper around a Redis client to read messages asynchronously. Use this + /// for publish/subscribe. The redisResponse event is used to notify that + /// a message is received. When a reader is started for a Redis server, + /// you should use execute, because this class is responsible for + /// reading all replies. +{ +public: + + BasicEvent redisResponse; + /// Event that is called when a message is received + + AsyncReader(Client& client); + /// Constructor. + + virtual ~AsyncReader(); + /// Destructor + + bool isStopped(); + /// Returns true if the activity is not running, false when it is. + + void start(); + /// Starts the activity to read replies from the Redis server. + + void stop(); + /// Stops the read activity. + +protected: + + void runActivity(); + +private: + + AsyncReader(const AsyncReader&); + AsyncReader& operator = (const AsyncReader&); + + + Activity _activity; + + Client& _client; +}; + + +inline bool AsyncReader::isStopped() +{ + return _activity.isStopped(); +} + +inline void AsyncReader::start() +{ + _activity.start(); +} + +inline void AsyncReader::stop() +{ + _activity.stop(); +} + + +} } // namespace Poco::Redis + +#endif //Redis_AsyncReader_INCLUDED diff --git a/Redis/src/AsyncClient.cpp b/Redis/src/AsyncClient.cpp deleted file mode 100644 index 691bf4a99..000000000 --- a/Redis/src/AsyncClient.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// AsyncClient.cpp -// -// $Id$ -// -// Library: Redis -// Package: Redis -// Module: AsyncClient -// -// Implementation of the AsyncClient class. -// -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - -#include "Poco/Redis/AsyncClient.h" - -namespace Poco { -namespace Redis { - - -AsyncClient::AsyncClient() : Client(), - _activity(this, &AsyncClient::runActivity) -{ -} - - -AsyncClient::AsyncClient(const std::string& hostAndPort) : Client(hostAndPort), - _activity(this, &AsyncClient::runActivity) -{ -} - - -AsyncClient::AsyncClient(const std::string& host, int port) : Client(host, port), - _activity(this, &AsyncClient::runActivity) -{ -} - - -AsyncClient::AsyncClient(const Net::SocketAddress& addrs) : Client(addrs), - _activity(this, &AsyncClient::runActivity) -{ -} - - -AsyncClient::~AsyncClient() -{ - stop(); -} - - -void AsyncClient::runActivity() -{ - while(!_activity.isStopped()) - { - try - { - RedisType::Ptr reply = readReply(); - redisResponse.notify(this, reply); - } - catch(TimeoutException&) - { - continue; - } - catch(Exception &) - { - stop(); - } - } -} - - -} } // Poco::Redis diff --git a/Redis/src/AsyncReader.cpp b/Redis/src/AsyncReader.cpp new file mode 100644 index 000000000..2a9663629 --- /dev/null +++ b/Redis/src/AsyncReader.cpp @@ -0,0 +1,57 @@ +// +// AsyncReader.cpp +// +// $Id$ +// +// Library: Redis +// Package: Redis +// Module: AsyncReader +// +// Implementation of the AsyncReader class. +// +// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + +#include "Poco/Redis/AsyncReader.h" + +namespace Poco { +namespace Redis { + + +AsyncReader::AsyncReader(Client& client) : _client(client), + _activity(this, &AsyncReader::runActivity) +{ +} + + +AsyncReader::~AsyncReader() +{ + stop(); +} + + +void AsyncReader::runActivity() +{ + while(!_activity.isStopped()) + { + try + { + RedisType::Ptr reply = _client.readReply(); + redisResponse.notify(this, reply); + } + catch(TimeoutException&) + { + continue; + } + catch(Exception &) + { + stop(); + } + } +} + + +} } // Poco::Redis