// // Copyright (c) ZeroC, Inc. All rights reserved. // #ifndef TOPIC_I_H #define TOPIC_I_H #include #include #include #include #include #include namespace IceStorm { // Forward declarations class PersistentInstance; class Subscriber; class TopicImpl { public: static std::shared_ptr create(std::shared_ptr, const std::string&, const Ice::Identity&, const SubscriberRecordSeq&); std::string getName() const; std::shared_ptr getPublisher() const; std::shared_ptr getNonReplicatedPublisher() const; std::shared_ptr subscribeAndGetPublisher(QoS, std::shared_ptr); void unsubscribe(const std::shared_ptr&); std::shared_ptr getLinkProxy(); void link(const std::shared_ptr&, int); void unlink(const std::shared_ptr&); LinkInfoSeq getLinkInfoSeq() const; Ice::IdentitySeq getSubscribers() const; void reap(const Ice::IdentitySeq&); void destroy(); IceStormElection::TopicContent getContent() const; void update(const SubscriberRecordSeq&); // Internal methods bool destroyed() const; Ice::Identity id() const; std::shared_ptr proxy() const; void shutdown(); void publish(bool, const EventDataSeq&); // Observer methods. void observerAddSubscriber(const IceStormElection::LogUpdate&, const SubscriberRecord&); void observerRemoveSubscriber(const IceStormElection::LogUpdate&, const Ice::IdentitySeq&); void observerDestroyTopic(const IceStormElection::LogUpdate&); std::shared_ptr getServant() const; void updateObserver(); void updateSubscriberObservers(); private: TopicImpl(std::shared_ptr, const std::string&, const Ice::Identity&, const SubscriberRecordSeq&); IceStormElection::LogUpdate destroyInternal(const IceStormElection::LogUpdate&, bool); void removeSubscribers(const Ice::IdentitySeq&); // // Immutable members. // const std::shared_ptr _publisherReplicaProxy; const std::shared_ptr _instance; const std::string _name; // The topic name const Ice::Identity _id; // The topic identity IceInternal::ObserverHelperT _observer; std::shared_ptr _publisherPrx; // The actual publisher proxy. std::shared_ptr _linkPrx; // The link proxy. std::shared_ptr _servant; // The topic implementation servant. // Mutex protecting the subscribers. mutable std::mutex _subscribersMutex; // // We keep a vector of subscribers since the optimized behaviour // should be publishing events, not searching through the list of // subscribers for a particular subscriber. I tested // vector/list/map and although there was little difference vector // was the fastest of the three. // std::vector> _subscribers; bool _destroyed; // Has this Topic been destroyed? LLUMap _lluMap; SubscriberMap _subscriberMap; }; } // End namespace IceStorm #endif