mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 22:56:19 +01:00
Renamed AsyncClient into AsyncReader
This commit is contained in:
parent
93a2cced8d
commit
cb8b6cfe8d
@ -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)
|
||||
|
@ -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<RedisType::Ptr> 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<AsyncClient> _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
|
92
Redis/include/Poco/Redis/AsyncReader.h
Normal file
92
Redis/include/Poco/Redis/AsyncReader.h
Normal file
@ -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<void>, because this class is responsible for
|
||||
/// reading all replies.
|
||||
{
|
||||
public:
|
||||
|
||||
BasicEvent<RedisType::Ptr> 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<AsyncReader> _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
|
@ -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
|
57
Redis/src/AsyncReader.cpp
Normal file
57
Redis/src/AsyncReader.cpp
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user