Subscriber.h
Go to the documentation of this file.
1// **********************************************************************
2//
3// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
4//
5// This copy of Ice is licensed to you under the terms described in the
6// ICE_LICENSE file included in this distribution.
7//
8// **********************************************************************
9
10#ifndef SUBSCRIBER_H
11#define SUBSCRIBER_H
12
13#include <Ice/ObserverHelper.h>
17#include <IceUtil/RecMutex.h>
18
19namespace IceStorm
20{
21
22 class Instance;
23 typedef IceUtil::Handle<Instance> InstancePtr;
24
25 class Subscriber;
27
28 class Subscriber : public IceUtil::Shared
29 {
30 public:
32
33 Ice::ObjectPrx proxy() const; // Get the per subscriber object.
34 Ice::Identity id() const; // Return the id of the subscriber.
35 IceStorm::SubscriberRecord record() const; // Get the subscriber record.
36
37 // Returns false if the subscriber should be reaped.
38 bool queue(bool, const EventDataSeq&);
39 bool reap();
40 void resetIfReaped();
41 bool errored() const;
42
43 void destroy();
44
45 // To be called by the AMI callbacks only.
46 void completed(const Ice::AsyncResultPtr&);
47 void error(bool, const Ice::Exception&);
48
49 void shutdown();
50
51 void updateObserver();
52
54 {
55 SubscriberStateOnline, // Online waiting to send events.
56 SubscriberStateOffline, // Offline, retrying.
57 SubscriberStateError, // Error state, awaiting reaping.
59 };
60
61 virtual void flush() = 0;
62
63 protected:
65
68 const Ice::ObjectPrx&,
69 int,
70 int);
71
72 // Immutable
74 const IceStorm::SubscriberRecord _rec; // The subscriber record.
75 const int _retryCount; // The retryCount.
76 const int _maxOutstanding; // The maximum number of oustanding events.
77 const Ice::ObjectPrx _proxy; // The per subscriber object proxy, if any.
78 const Ice::ObjectPrx _proxyReplica; // The replicated per subscriber object proxy, if any.
79
80 IceUtil::Monitor<IceUtil::RecMutex> _lock;
81
83
84 SubscriberState _state; // The subscriber state.
85
86 int _outstanding; // The current number of outstanding responses.
87 int _outstandingCount; // The current number of outstanding events when batching events (only used for metrics).
88 EventDataSeq _events; // The queue of events to send.
89
90 // The next time to try sending a new event if we're offline.
91 IceUtil::Time _next;
93
94 IceInternal::ObserverHelperT<IceStorm::Instrumentation::SubscriberObserver> _observer;
95 };
96
97 bool operator==(const IceStorm::SubscriberPtr&, const Ice::Identity&);
101
102} // namespace IceStorm
103
104#endif // SUBSCRIBER_H
bool queue(bool, const EventDataSeq &)
Subscriber(const InstancePtr &, const IceStorm::SubscriberRecord &, const Ice::ObjectPrx &, int, int)
const IceStorm::SubscriberRecord _rec
Definition Subscriber.h:74
IceUtil::Time _next
Definition Subscriber.h:91
const Ice::ObjectPrx _proxyReplica
Definition Subscriber.h:78
IceInternal::ObserverHelperT< IceStorm::Instrumentation::SubscriberObserver > _observer
Definition Subscriber.h:94
virtual void flush()=0
Ice::ObjectPrx proxy() const
IceStorm::SubscriberRecord record() const
SubscriberState _state
Definition Subscriber.h:84
const Ice::ObjectPrx _proxy
Definition Subscriber.h:77
void completed(const Ice::AsyncResultPtr &)
const int _maxOutstanding
Definition Subscriber.h:76
void error(bool, const Ice::Exception &)
const InstancePtr _instance
Definition Subscriber.h:73
EventDataSeq _events
Definition Subscriber.h:88
static SubscriberPtr create(const InstancePtr &, const IceStorm::SubscriberRecord &)
const int _retryCount
Definition Subscriber.h:75
Ice::Identity id() const
void setState(SubscriberState)
IceUtil::Monitor< IceUtil::RecMutex > _lock
Definition Subscriber.h:80
IceUtil::Handle< Subscriber > SubscriberPtr
Definition Subscriber.h:26
std::deque<::IceStorm::EventDataPtr > EventDataSeq
A sequence of EventData.
bool operator!=(const IceStorm::Subscriber &, const IceStorm::Subscriber &)
bool operator<(const TopicLink &lhs, const TopicLink &rhs)
IceUtil::Handle< Instance > InstancePtr
Definition Instance.h:128
bool operator==(const TopicLink &lhs, const TopicLink &rhs)
Used to store persistent information for persistent subscribers.