mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
refine code.
This commit is contained in:
parent
d2ca51ac50
commit
cbe4252b4d
2 changed files with 35 additions and 35 deletions
|
@ -381,6 +381,36 @@ void SrsKafkaProducer::stop()
|
|||
worker->stop();
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::send(int key, SrsJsonObject* obj)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// cache the json object.
|
||||
cache->append(key, obj);
|
||||
|
||||
// too few messages, ignore.
|
||||
if (cache->size() < SRS_KAFKA_PRODUCER_AGGREGATE_SIZE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// too many messages, warn user.
|
||||
if (cache->size() > SRS_KAFKA_PRODUCER_AGGREGATE_SIZE * 10) {
|
||||
srs_warn("kafka cache too many messages: %d", cache->size());
|
||||
}
|
||||
|
||||
// sync with backgound metadata worker.
|
||||
st_mutex_lock(lock);
|
||||
|
||||
// flush message when metadata is ok.
|
||||
if (metadata_ok) {
|
||||
ret = flush();
|
||||
}
|
||||
|
||||
st_mutex_unlock(lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::on_client(int key, SrsListenerType type, string ip)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -415,36 +445,6 @@ int SrsKafkaProducer::on_close(int key)
|
|||
return worker->execute(new SrsKafkaMessage(this, key, obj));
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::send(int key, SrsJsonObject* obj)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// cache the json object.
|
||||
cache->append(key, obj);
|
||||
|
||||
// too few messages, ignore.
|
||||
if (cache->size() < SRS_KAFKA_PRODUCER_AGGREGATE_SIZE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// too many messages, warn user.
|
||||
if (cache->size() > SRS_KAFKA_PRODUCER_AGGREGATE_SIZE * 10) {
|
||||
srs_warn("kafka cache too many messages: %d", cache->size());
|
||||
}
|
||||
|
||||
// sync with backgound metadata worker.
|
||||
st_mutex_lock(lock);
|
||||
|
||||
// flush message when metadata is ok.
|
||||
if (metadata_ok) {
|
||||
ret = flush();
|
||||
}
|
||||
|
||||
st_mutex_unlock(lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
|
@ -173,11 +173,7 @@ public:
|
|||
virtual int initialize();
|
||||
virtual int start();
|
||||
virtual void stop();
|
||||
// interface ISrsKafkaCluster
|
||||
public:
|
||||
virtual int on_client(int key, SrsListenerType type, std::string ip);
|
||||
virtual int on_close(int key);
|
||||
// for worker to call task to send object.
|
||||
// internal: for worker to call task to send object.
|
||||
public:
|
||||
/**
|
||||
* send json object to kafka cluster.
|
||||
|
@ -186,6 +182,10 @@ public:
|
|||
* @param obj the json object; user must never free it again.
|
||||
*/
|
||||
virtual int send(int key, SrsJsonObject* obj);
|
||||
// interface ISrsKafkaCluster
|
||||
public:
|
||||
virtual int on_client(int key, SrsListenerType type, std::string ip);
|
||||
virtual int on_close(int key);
|
||||
// interface ISrsReusableThreadHandler
|
||||
public:
|
||||
virtual int cycle();
|
||||
|
|
Loading…
Reference in a new issue