// ********************************************************************** // // Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #ifndef SUBSCRIBER_H #define SUBSCRIBER_H #include #include #include namespace IceStorm { class Instance; typedef IceUtil::Handle InstancePtr; class Subscriber; typedef IceUtil::Handle SubscriberPtr; class Subscriber : public IceUtil::Shared { public: static SubscriberPtr create(const InstancePtr&, const IceStorm::SubscriberRecord&); ~Subscriber(); Ice::ObjectPrx proxy() const; // Get the per subscriber object. Ice::Identity id() const; // Return the id of the subscriber. IceStorm::SubscriberRecord record() const; // Get the subscriber record. // Returns false if the subscriber should be reaped. bool queue(bool, const EventDataSeq&); bool reap(); void resetIfReaped(); bool errored() const; void destroy(); // To be called by the AMI callbacks only. void error(bool, const Ice::Exception&); void response(); void shutdown(); enum SubscriberState { SubscriberStateOnline, // Online waiting to send events. SubscriberStateOffline, // Offline, retrying. SubscriberStateError, // Error state, awaiting reaping. SubscriberStateReaped // Reaped. }; virtual void flush() = 0; protected: void setState(SubscriberState); Subscriber(const InstancePtr&, const IceStorm::SubscriberRecord&, const Ice::ObjectPrx&, int, int); // Immutable const InstancePtr _instance; const IceStorm::SubscriberRecord _rec; // The subscriber record. const int _retryCount; // The retryCount. const int _maxOutstanding; // The maximum number of oustanding events. const Ice::ObjectPrx _proxy; // The per subscriber object proxy, if any. const Ice::ObjectPrx _proxyReplica; // The replicated per subscriber object proxy, if any. IceUtil::Monitor _lock; bool _shutdown; SubscriberState _state; // The subscriber state. int _outstanding; // The current number of outstanding responses. EventDataSeq _events; // The queue of events to send. // The next to try sending a new event if we're offline. IceUtil::Time _next; int _currentRetry; }; bool operator==(const IceStorm::SubscriberPtr&, const Ice::Identity&); bool operator==(const IceStorm::Subscriber&, const IceStorm::Subscriber&); bool operator!=(const IceStorm::Subscriber&, const IceStorm::Subscriber&); bool operator<(const IceStorm::Subscriber&, const IceStorm::Subscriber&); } #endif // SUBSCRIBER_H