m2etis  0.4
InternalMessage.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_MESSAGE_INTERNALMESSAGE_H__
23 #define __M2ETIS_MESSAGE_INTERNALMESSAGE_H__
24 
27 
35 
36 #include "boost/serialization/export.hpp"
37 #include "boost/serialization/base_object.hpp"
38 #include "boost/serialization/list.hpp"
39 #include "boost/serialization/map.hpp"
40 #include "boost/serialization/shared_ptr.hpp"
41 #include "boost/serialization/variant.hpp"
42 #include "boost/serialization/vector.hpp"
43 
44 namespace m2etis {
45 namespace message {
46 
47  enum class ControlType : short {
48  NONE = 0,
49  DELIVER,
50  FILTER,
51  ORDER,
53  ROUTING,
54  SECURITY,
55  VALIDITY
56  };
57 
58  template<class NetworkType, class ChannelType, class EventType>
59  class InternalMessage : public M2Message<EventType>, public NetworkMessage<NetworkType> {
60  public:
61  // Message Ptr
62  typedef boost::shared_ptr<InternalMessage> Ptr;
63 
64  typedef typename ChannelType::DeliverStrategy::DeliverInfoType DInfo;
65  typedef typename ChannelType::FilterStrategy::FilterInfoType FInfo;
66  typedef typename ChannelType::OrderStrategy::OrderInfoType OInfo;
67  typedef typename ChannelType::PersistenceStrategy::PersistenceInfoType PInfo;
68  typedef typename ChannelType::RoutingStrategy::RoutingInfoType RInfo;
69  typedef typename ChannelType::SecurityStrategy::SecurityInfoType SInfo;
70  typedef typename ChannelType::ValidityStrategy::ValidityInfoType VInfo;
71 
72  typedef struct TreeHelper {
73  uint16_t topic;
74  boost::shared_ptr<pubsub::filter::FilterExp<EventType>> predicates;
75  typename NetworkType::Key root;
76 
77  TreeHelper() : topic(), predicates(), root() {}
78  TreeHelper(uint16_t t, boost::shared_ptr<pubsub::filter::FilterExp<EventType>> p, typename NetworkType::Key r) : topic(t), predicates(p), root(r) {
79  }
80 
82  template <class Archive>
83  void serialize(Archive & ar, const unsigned int) {
84  ar & topic;
85  ar & predicates;
86  ar & root;
87  }
88  } TreeHelper;
89 
91 
95  typename DInfo::Ptr deliverInfo;
96 
100  // FilterPtr filterInfo;
101  typename FInfo::Ptr filterInfo;
102 
106  typename OInfo::Ptr orderInfo;
107 
111  typename PInfo::Ptr persistenceInfo;
112 
116  typename RInfo::Ptr routingInfo;
117 
121  typename SInfo::Ptr securityInfo;
122 
126  typename VInfo::Ptr validityInfo;
127 
132 
136  std::vector<typename NetworkType::Key> _nodeList;
137 
141  uint64_t _time;
142 
146  std::vector<TreeHelper> _trees;
147 
151  std::set<uint16_t> _topics;
152 
153  InternalMessage() : M2Message<EventType>(&type), NetworkMessage<NetworkType>(&type),
154  type(),
155  deliverInfo(boost::make_shared<DInfo>()),
156  filterInfo(boost::make_shared<FInfo>()),
157  orderInfo(boost::make_shared<OInfo>()),
158  persistenceInfo(boost::make_shared<PInfo>()),
159  routingInfo(boost::make_shared<RInfo>()),
160  securityInfo(boost::make_shared<SInfo>()),
161  validityInfo(boost::make_shared<VInfo>()),
162  ctrlType_(ControlType::NONE),
163  _nodeList(),
164  _time(0),
165  _trees(),
166  _topics() {
167  }
168 
169  explicit InternalMessage(const EventType & v) : M2Message<EventType>(v, &type), NetworkMessage<NetworkType>(&type),
170  type(),
171  deliverInfo(boost::make_shared<DInfo>()),
172  filterInfo(boost::make_shared<FInfo>()),
173  orderInfo(boost::make_shared<OInfo>()),
174  persistenceInfo(boost::make_shared<PInfo>()),
175  routingInfo(boost::make_shared<RInfo>()),
176  securityInfo(boost::make_shared<SInfo>()),
177  validityInfo(boost::make_shared<VInfo>()),
178  ctrlType_(ControlType::NONE),
179  _nodeList(),
180  _time(0),
181  _trees(),
182  _topics() {
183  }
184 
185  explicit InternalMessage(const InternalMessage & msg) : M2Message<EventType>(msg, &type), NetworkMessage<NetworkType>(msg, &type),
186  type(msg.type),
187  deliverInfo(boost::make_shared<DInfo>(*msg.deliverInfo)),
188  filterInfo(boost::make_shared<FInfo>(*msg.filterInfo)),
189  orderInfo(boost::make_shared<OInfo>(*msg.orderInfo)),
190  persistenceInfo(boost::make_shared<PInfo>(*msg.persistenceInfo)),
191  routingInfo(boost::make_shared<RInfo>(*msg.routingInfo)),
192  securityInfo(boost::make_shared<SInfo>(*msg.securityInfo)),
193  validityInfo(boost::make_shared<VInfo>(*msg.validityInfo)),
194  ctrlType_(msg.ctrlType_),
195  _nodeList(msg._nodeList),
196  _time(msg._time),
197  _trees(msg._trees),
198  _topics(msg._topics) {
199  }
200 
202  }
203 
204  std::string toString() {
205  std::stringstream ss;
206  ss << "IMessage(" << int(type) << ", " << int(ctrlType_) << ", removeTopics: " << _topics.size() << ", trees: " << _trees.size() << "(";
207  for (int i = 0; i < _trees.size(); i++) {
208  ss << _trees[i].topic << ":" << _trees[i].root.toStr() << ", ";
209  }
210  ss << "), nodelist: " << _nodeList.size() << "(";
211  for (size_t i = 0; i < _nodeList.size(); i++) {
212  ss << _nodeList[i].toStr() << ", ";
213  }
214  ss << ")";
215  ss << ")";
216  return ss.str();
217  }
218  private:
220 
221  template<class Archive>
222  void serialize(Archive & ar, const unsigned int) {
223  ar & type;
224  ActionType actionType = ActionType(type & ACTION_TYPE_MASK);
225  if (actionType == PUBLISH || actionType == NOTIFY) {
226  ar & boost::serialization::base_object<m2etis::message::M2Message<EventType>>(*this);
227  }
228  ar & boost::serialization::base_object<m2etis::message::NetworkMessage<NetworkType>>(*this);
229  if (RInfo::doSerialize(actionType)) {
230  ar & routingInfo;
231  }
232  if (FInfo::doSerialize(actionType)) {
233  ar & filterInfo;
234  }
235  if (PInfo::doSerialize(actionType)) {
236  ar & persistenceInfo;
237  }
238  if (VInfo::doSerialize(actionType)) {
239  ar & validityInfo;
240  }
241  if (SInfo::doSerialize(actionType)) {
242  ar & securityInfo;
243  }
244  if (OInfo::doSerialize(actionType)) {
245  ar & orderInfo;
246  }
247  if (DInfo::doSerialize(actionType)) {
248  ar & deliverInfo;
249  }
250  if (actionType == CONTROL) {
251  ar & ctrlType_;
252  }
253  if (actionType == STATE) {
254  ar & _nodeList;
255  ar & _time;
256  ar & _trees;
257  }
258  if (actionType == LEAVE) {
259  ar & _topics;
260  }
261  }
262  };
263 
264 } /* namespace message */
265 } /* namespace m2etis */
266 
267 #endif /* __M2ETIS_MESSAGE_INTERNALMESSAGE_H__ */
268 
ChannelType::DeliverStrategy::DeliverInfoType DInfo
ControlType ctrlType_
type containing the strategie that sent this message
RInfo::Ptr routingInfo
contains message dependent datas for Routing
InternalMessage(const EventType &v)
ChannelType::PersistenceStrategy::PersistenceInfoType PInfo
std::vector< TreeHelper > _trees
list of all trees existing
SInfo::Ptr securityInfo
contains message dependent datas for Security
ChannelType::RoutingStrategy::RoutingInfoType RInfo
std::set< uint16_t > _topics
list of all topics being removed during leave
boost::shared_ptr< pubsub::filter::FilterExp< EventType > > predicates
FInfo::Ptr filterInfo
contains message dependent datas for Filtering
ChannelType::OrderStrategy::OrderInfoType OInfo
TreeHelper(uint16_t t, boost::shared_ptr< pubsub::filter::FilterExp< EventType >> p, typename NetworkType::Key r)
InternalMessage(const InternalMessage &msg)
std::vector< typename NetworkType::Key > _nodeList
list of all nodes for join
ChannelType::SecurityStrategy::SecurityInfoType SInfo
ChannelType::ValidityStrategy::ValidityInfoType VInfo
ChannelType::FilterStrategy::FilterInfoType FInfo
PInfo::Ptr persistenceInfo
contains message dependent datas for Persistency
VInfo::Ptr validityInfo
contains message dependent datas for Validity
friend class boost::serialization::access
uint64_t _time
current time of RP
OInfo::Ptr orderInfo
contains message dependent datas for Odering
void serialize(Archive &ar, const unsigned int)
friend class boost::serialization::access
uint32_t MessageType
Definition: MessageType.h:35
boost::shared_ptr< InternalMessage > Ptr
struct m2etis::message::InternalMessage::TreeHelper TreeHelper
static const uint32_t ACTION_TYPE_MASK
Definition: MessageType.h:32
DInfo::Ptr deliverInfo
contains message dependent datas for Delivering