22 #ifndef __M2ETIS_PUBSUB_PARTITION_BRUTEFORCEPARTITION_H__
23 #define __M2ETIS_PUBSUB_PARTITION_BRUTEFORCEPARTITION_H__
35 template<
typename NetworkType,
typename EventType>
56 if (partition_filter_vector_.empty()) {
60 for (std::vector<int>::size_type i = 0; i != partition_filter_vector_.size(); ++i) {
61 ret.push_back(
int(i));
67 std::vector<int>::size_type
getPublishTree(
const PayloadPtr message,
const typename NetworkType::Key &) {
68 if (partition_filter_vector_.empty()) {
72 std::vector<int>::size_type i = 0;
73 for (
auto current_filter : partition_filter_vector_) {
76 current_filter->Accept(match_filter_visitor);
78 M2ETIS_LOG_INFO(
"BruteForcePartition",
"publishing message on tree number " << i);
83 M2ETIS_THROW_API(
"BruteForcePartition",
"No matching tree for publish message found.");
88 std::vector<unsigned int> overlapping_trees;
89 if (partition_filter_vector_.empty()) {
90 overlapping_trees.push_back(0);
91 return overlapping_trees;
93 unsigned int tree_index = 0;
95 for (
auto partition_filter : partition_filter_vector_) {
96 if (isOverlap(partition_filter, dynamic_filter)) {
97 overlapping_trees.push_back(tree_index);
101 return overlapping_trees;
104 boost::shared_ptr<filter::FilterExp<EventType>>
getPredicate(
size_t id) {
105 assert(
id < partition_filter_vector_.size());
106 return partition_filter_vector_[id];
128 auto intersection_filter = std::make_shared<filter::AndExp<EventType>>(static_filter, dynamic_filter);
131 intersection_filter->Accept(variable_assignment_filter_visitor);
133 unsigned long number_of_assignment_possibilities =
static_cast<unsigned long>(pow(2.0, variable_assignment_filter_visitor.get_predicate_number()));
134 std::vector<unsigned long> fulfilling_predicate_assignments;
136 for (
unsigned long predicate_assignment = 0; predicate_assignment != number_of_assignment_possibilities; ++predicate_assignment) {
137 variable_assignment_filter_visitor.
reset();
138 variable_assignment_filter_visitor.set_predicate_assignment(predicate_assignment);
139 intersection_filter->Accept(variable_assignment_filter_visitor);
140 if (variable_assignment_filter_visitor.get_result()) {
141 fulfilling_predicate_assignments.push_back(predicate_assignment);
146 for (
auto fulfilling_predicate_assignment_iterator = fulfilling_predicate_assignments.begin(); fulfilling_predicate_assignment_iterator != fulfilling_predicate_assignments.end(); ++fulfilling_predicate_assignment_iterator) {
147 bool disjoint_predicates_found =
false;
148 auto fulfilling_predicate_assignment = *fulfilling_predicate_assignment_iterator;
152 for (
int current_predicate_number = 0; current_predicate_number != variable_assignment_filter_visitor.get_predicate_number() && !disjoint_predicates_found; ++current_predicate_number) {
153 if ((fulfilling_predicate_assignment & (1UL << current_predicate_number)) != 0) {
155 for (
int other_predicate_number = current_predicate_number + 1; other_predicate_number != variable_assignment_filter_visitor.get_predicate_number() && !disjoint_predicates_found; ++other_predicate_number) {
156 if ((fulfilling_predicate_assignment & (1UL << other_predicate_number)) != 0) {
158 if (!((variable_assignment_filter_visitor.get_predicate_index())[current_predicate_number])->overlaps((variable_assignment_filter_visitor.get_predicate_index())[other_predicate_number])) {
159 disjoint_predicates_found =
true;
165 if (!disjoint_predicates_found) {
173 std::vector<boost::shared_ptr<filter::FilterExp<EventType>> > partition_filter_vector_;
std::vector< unsigned int > getSubscribeTrees(boost::shared_ptr< filter::FilterExp< EventType > > dynamic_filter)
BruteForcePartition(const std::vector< boost::shared_ptr< filter::FilterExp< EventType >> > &partition_filter_vector)
boost::shared_ptr< EventType > PayloadPtr
void createRendezvousPartition(const typename NetworkType::Key &)
creates a base partition for the RP (dynamic)
bool createPartition(const typename NetworkType::Key &)
can create a new partition for this channel if a new node (root) joins, return true, if a new partition was created, otherwise false (dynamic)
#define M2ETIS_LOG_INFO(module, message)
void addPartition(boost::shared_ptr< filter::FilterExp< EventType >>, const typename NetworkType::Key &)
virtual ~BruteForcePartition()
void changeRoot(size_t, typename NetworkType::Key &)
static const bool DYNAMIC_PARTITION
void changePredicate(size_t, boost::shared_ptr< filter::FilterExp< EventType >>)
changes the filter predicate for the partition with the given id (dynamic)
std::vector< int >::size_type getPublishTree(const PayloadPtr message, const typename NetworkType::Key &)
returns the tree index the given node with the given payload should publish on (static & dynamic) ...
boost::shared_ptr< filter::FilterExp< EventType > > getPredicate(size_t id)
returns the predicate for the given partition id (dynamic)
std::vector< int > getTreeNames()
returns amount of partitions this strategy contains (static & dynamic)
#define M2ETIS_THROW_API(module, message)
throws on wrong API usage
void removePartition(size_t)
removes the partition with the given id (dynamic)