-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async call for broker stats #305
Changes from 12 commits
2618954
a86eb25
3480d8b
fdfa653
0196f39
9dde11c
f852087
cfe19e9
e89ec7b
6abbd02
e42d2db
b748c69
6083ad9
2cfd147
c5a2404
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright 2016 Yahoo Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PULSAR_CPP_BROKERCONSUMERSTATS_H | ||
#define PULSAR_CPP_BROKERCONSUMERSTATS_H | ||
|
||
#include <boost/date_time/posix_time/ptime.hpp> | ||
#include <string.h> | ||
#include <iostream> | ||
#include <pulsar/Result.h> | ||
#include <boost/function.hpp> | ||
#include <pulsar/ConsumerType.h> | ||
|
||
namespace pulsar { | ||
class BrokerConsumerStatsImplBase; | ||
class BrokerConsumerStats { | ||
private: | ||
boost::shared_ptr<BrokerConsumerStatsImplBase> impl_; | ||
public: | ||
BrokerConsumerStats(boost::shared_ptr<BrokerConsumerStatsImplBase> impl); | ||
|
||
BrokerConsumerStats(); | ||
|
||
/** Returns true if the Stats are still valid **/ | ||
virtual bool isValid() const; | ||
|
||
/** Returns the rate of messages delivered to the consumer. msg/s */ | ||
virtual double getMsgRateOut() const; | ||
|
||
/** Returns the throughput delivered to the consumer. bytes/s */ | ||
virtual double getMsgThroughputOut() const; | ||
|
||
/** Returns the rate of messages redelivered by this consumer. msg/s */ | ||
virtual double getMsgRateRedeliver() const; | ||
|
||
/** Returns the Name of the consumer */ | ||
virtual const std::string getConsumerName() const; | ||
|
||
/** Returns the Number of available message permits for the consumer */ | ||
virtual uint64_t getAvailablePermits() const; | ||
|
||
/** Returns the Number of unacknowledged messages for the consumer */ | ||
virtual uint64_t getUnackedMessages() const; | ||
|
||
/** Returns true if the consumer is blocked due to unacked messages. */ | ||
virtual bool isBlockedConsumerOnUnackedMsgs() const; | ||
|
||
/** Returns the Address of this consumer */ | ||
virtual const std::string getAddress() const; | ||
|
||
/** Returns the Timestamp of connection */ | ||
virtual const std::string getConnectedSince() const; | ||
|
||
/** Returns Whether this subscription is Exclusive or Shared or Failover */ | ||
virtual const ConsumerType getType() const; | ||
|
||
/** Returns the rate of messages expired on this subscription. msg/s */ | ||
virtual double getMsgRateExpired() const; | ||
|
||
/** Returns the Number of messages in the subscription backlog */ | ||
virtual uint64_t getMsgBacklog() const; | ||
|
||
/** @deprecated */ | ||
boost::shared_ptr<BrokerConsumerStatsImplBase> getImpl() const; | ||
|
||
friend std::ostream& operator<<(std::ostream &os, const BrokerConsumerStats &obj); | ||
}; | ||
typedef boost::shared_ptr<BrokerConsumerStats> BrokerConsumerStatsPtr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need a shared_ptr here if BrokerConsumerStats is already basically a shared_ptr and is allowed to be invalid? |
||
typedef boost::function<void(Result result, BrokerConsumerStats brokerConsumerStats)> BrokerConsumerStatsCallback; | ||
|
||
} | ||
#endif //PULSAR_CPP_BROKERCONSUMERSTATS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2016 Yahoo Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PULSAR_CPP_CONSUMERTYPE_H | ||
#define PULSAR_CPP_CONSUMERTYPE_H | ||
|
||
namespace pulsar { | ||
enum ConsumerType { | ||
/** | ||
* There can be only 1 consumer on the same topic with the same consumerName | ||
*/ | ||
ConsumerExclusive, | ||
|
||
/** | ||
* Multiple consumers will be able to use the same consumerName and the messages | ||
* will be dispatched according to a round-robin rotation between the connected consumers | ||
*/ | ||
ConsumerShared, | ||
|
||
/** Only one consumer is active on the subscription; Subscription can have N consumers | ||
* connected one of which will get promoted to master if the current master becomes inactive | ||
*/ | ||
ConsumerFailover | ||
}; | ||
} | ||
|
||
#endif //PULSAR_CPP_CONSUMERTYPE_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* Copyright 2016 Yahoo Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <pulsar/BrokerConsumerStats.h> | ||
#include <lib/BrokerConsumerStatsImplBase.h> | ||
|
||
namespace pulsar { | ||
BrokerConsumerStats::BrokerConsumerStats(boost::shared_ptr<BrokerConsumerStatsImplBase> impl) : impl_(impl) {} | ||
|
||
BrokerConsumerStats::BrokerConsumerStats() {} | ||
|
||
boost::shared_ptr<BrokerConsumerStatsImplBase> BrokerConsumerStats::getImpl() const { | ||
return impl_; | ||
} | ||
|
||
bool BrokerConsumerStats::isValid() const { | ||
if (impl_) { | ||
return impl_->isValid(); | ||
} | ||
return false; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream &os, const BrokerConsumerStats& obj) { | ||
os << "\nBrokerConsumerStats [" | ||
<< "validTill_ = " << obj.isValid() | ||
<< ", msgRateOut_ = " << obj.getMsgRateOut() | ||
<< ", msgThroughputOut_ = " << obj.getMsgThroughputOut() | ||
<< ", msgRateRedeliver_ = " << obj.getMsgRateRedeliver() | ||
<< ", consumerName_ = " << obj.getConsumerName() | ||
<< ", availablePermits_ = " << obj.getAvailablePermits() | ||
<< ", unackedMessages_ = " << obj.getUnackedMessages() | ||
<< ", blockedConsumerOnUnackedMsgs_ = " << obj.isBlockedConsumerOnUnackedMsgs() | ||
<< ", address_ = " << obj.getAddress() | ||
<< ", connectedSince_ = " << obj.getConnectedSince() | ||
<< ", type_ = " << obj.getType() | ||
<< ", msgRateExpired_ = " << obj.getMsgRateExpired() | ||
<< ", msgBacklog_ = " << obj.getMsgBacklog() | ||
<< "]"; | ||
return os; | ||
} | ||
|
||
double BrokerConsumerStats::getMsgRateOut() const { | ||
if (impl_) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be more idiomatic to just document that no getXXX is allowed on an invalid BrokerConsumerStats object and get rid of the check. that avoids hiding bugs. |
||
return impl_->getMsgRateOut(); | ||
} | ||
return 0; | ||
} | ||
|
||
double BrokerConsumerStats::getMsgThroughputOut() const { | ||
if (impl_) { | ||
return impl_->getMsgThroughputOut(); | ||
} | ||
return 0; | ||
} | ||
|
||
double BrokerConsumerStats::getMsgRateRedeliver() const { | ||
if (impl_) { | ||
return impl_->getMsgRateRedeliver(); | ||
} | ||
return 0; | ||
} | ||
|
||
const std::string BrokerConsumerStats::getConsumerName() const { | ||
if (impl_) { | ||
return impl_->getConsumerName(); | ||
} | ||
return ""; | ||
} | ||
|
||
uint64_t BrokerConsumerStats::getAvailablePermits() const { | ||
if (impl_) { | ||
return impl_->getAvailablePermits(); | ||
} | ||
return 0; | ||
} | ||
|
||
uint64_t BrokerConsumerStats::getUnackedMessages() const { | ||
if (impl_) { | ||
return impl_->getUnackedMessages(); | ||
} | ||
return 0; | ||
} | ||
|
||
bool BrokerConsumerStats::isBlockedConsumerOnUnackedMsgs() const { | ||
if (impl_) { | ||
return impl_->isBlockedConsumerOnUnackedMsgs(); | ||
} | ||
return false; | ||
} | ||
|
||
const std::string BrokerConsumerStats::getAddress() const { | ||
if (impl_) { | ||
return impl_->getAddress(); | ||
} | ||
return ""; | ||
} | ||
|
||
const std::string BrokerConsumerStats::getConnectedSince() const { | ||
if (impl_) { | ||
return impl_->getConnectedSince(); | ||
} | ||
return ""; | ||
} | ||
|
||
const ConsumerType BrokerConsumerStats::getType() const { | ||
if (impl_) { | ||
return impl_->getType(); | ||
} | ||
return ConsumerExclusive; | ||
} | ||
|
||
double BrokerConsumerStats::getMsgRateExpired() const { | ||
if (impl_) { | ||
return impl_->getMsgRateExpired(); | ||
} | ||
return 0; | ||
} | ||
|
||
uint64_t BrokerConsumerStats::getMsgBacklog() const { | ||
if (impl_) { | ||
return impl_->getMsgBacklog(); | ||
} | ||
return 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this constructor should be
explicit