// ---------------------------------------------------------------------- // File: Publisher.hh // Author: Georgios Bitzes - CERN // ---------------------------------------------------------------------- /************************************************************************ * quarkdb - a redis-like highly available key-value store * * Copyright (C) 2016 CERN/Switzerland * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* ************************************************************************/ #ifndef QUARKDB_PUBLISHER_HH #define QUARKDB_PUBLISHER_HH #include "pubsub/SimplePatternMatcher.hh" #include "Connection.hh" #include "Dispatcher.hh" #include "storage/VersionedHashRevisionTracker.hh" #include "utils/AssistedThread.hh" #include #include #include #include #include namespace quarkdb { class PendingQueue; class RedisRequest; class Publisher : public Dispatcher { public: // Constructor Publisher(); // Destructor ~Publisher(); // Subscribe connection to given channel or pattern. Return whether the subscription // existed already, or not. int subscribe(std::shared_ptr connection, std::string_view channel); int psubscribe(std::shared_ptr connection, std::string_view pattern); int publish(const std::string& channel, std::string_view payload); void purgeListeners(RedisEncodedResponse resp); virtual LinkStatus dispatch(Connection *conn, RedisRequest &req) override final; virtual LinkStatus dispatch(Connection *conn, Transaction &tx) override final; virtual void notifyDisconnect(Connection *conn) override final {} void schedulePublishing(VersionedHashRevisionTracker &&revisionTracker); private: int publishChannels(const std::string &channel, std::string_view payload); int publishPatterns(const std::string &channel, std::string_view payload); bool unsubscribe(std::shared_ptr connection, std::string_view channel); bool punsubscribe(std::shared_ptr connection, std::string_view pattern); void asyncPublisher(ThreadAssistant &assistant); // Queue to publish vhash updates qclient::WaitableQueue revisionQueue; AssistedThread asyncPublishingThread; // Map of subscribed-to channels ThreadSafeMultiMap> channelSubscriptions; // Pattern matcher SimplePatternMatcher> patternMatcher; }; } #endif