-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stephen Belanger <[email protected]>
- Loading branch information
Showing
26 changed files
with
833 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
|
||
#include <nan.h> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* node-rdkafka - Node.js wrapper for RdKafka C/C++ library | ||
* | ||
* Copyright (c) 2016 Blizzard Entertainment | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE.txt file for details. | ||
*/ | ||
|
||
#include <mutex> | ||
#include <unordered_map> | ||
#include <utility> | ||
|
||
#include "per-isolate-data.h" | ||
|
||
namespace NodeKafka { | ||
|
||
static std::unordered_map<v8::Isolate*, PerIsolateData> per_isolate_data_; | ||
static std::mutex mutex; | ||
|
||
PerIsolateData* PerIsolateData::For(v8::Isolate* isolate) { | ||
const std::lock_guard<std::mutex> lock(mutex); | ||
auto maybe = per_isolate_data_.find(isolate); | ||
if (maybe != per_isolate_data_.end()) { | ||
return &maybe->second; | ||
} | ||
|
||
per_isolate_data_.emplace(std::make_pair(isolate, PerIsolateData())); | ||
|
||
auto pair = per_isolate_data_.find(isolate); | ||
auto perIsolateData = &pair->second; | ||
|
||
node::AddEnvironmentCleanupHook(isolate, [](void* data) { | ||
const std::lock_guard<std::mutex> lock(mutex); | ||
per_isolate_data_.erase(static_cast<v8::Isolate*>(data)); | ||
}, isolate); | ||
|
||
return perIsolateData; | ||
} | ||
|
||
Nan::Global<v8::Function>& PerIsolateData::AdminClientConstructor() { | ||
return admin_client_constructor; | ||
} | ||
|
||
Nan::Global<v8::Function>& PerIsolateData::KafkaConsumerConstructor() { | ||
return kafka_consumer_constructor; | ||
} | ||
|
||
Nan::Global<v8::Function>& PerIsolateData::KafkaProducerConstructor() { | ||
return kafka_producer_constructor; | ||
} | ||
|
||
Nan::Global<v8::Function>& PerIsolateData::TopicConstructor() { | ||
return topic_constructor; | ||
} | ||
|
||
} // namespace dd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* node-rdkafka - Node.js wrapper for RdKafka C/C++ library | ||
* | ||
* Copyright (c) 2016 Blizzard Entertainment | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE.txt file for details. | ||
*/ | ||
|
||
#ifndef SRC_PER_ISOLATE_DATA_H_ | ||
#define SRC_PER_ISOLATE_DATA_H_ | ||
|
||
#include <node.h> | ||
#include <nan.h> | ||
#include <v8.h> | ||
|
||
namespace NodeKafka { | ||
|
||
class PerIsolateData { | ||
private: | ||
Nan::Global<v8::Function> admin_client_constructor; | ||
Nan::Global<v8::Function> kafka_consumer_constructor; | ||
Nan::Global<v8::Function> kafka_producer_constructor; | ||
Nan::Global<v8::Function> topic_constructor; | ||
|
||
PerIsolateData() {} | ||
|
||
public: | ||
static PerIsolateData* For(v8::Isolate* isolate); | ||
|
||
Nan::Global<v8::Function>& AdminClientConstructor(); | ||
Nan::Global<v8::Function>& KafkaConsumerConstructor(); | ||
Nan::Global<v8::Function>& KafkaProducerConstructor(); | ||
Nan::Global<v8::Function>& TopicConstructor(); | ||
}; | ||
|
||
} // namespace NodeKafka | ||
|
||
#endif // SRC_PER_ISOLATE_DATA_H_ |
Oops, something went wrong.