RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParallelEventReceivingStrategy.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <set>
30 #include <utility>
31 
32 #include <boost/shared_ptr.hpp>
33 #include <boost/thread/shared_mutex.hpp>
34 
35 #include <rsc/runtime/Properties.h>
36 #include <rsc/logging/Logger.h>
37 #include <rsc/threading/OrderedQueueDispatcherPool.h>
38 
39 #include "../Event.h"
40 #include "../ParticipantConfig.h"
42 #include "rsb/rsbexports.h"
43 
44 namespace rsb {
45 namespace eventprocessing {
46 
47 // optimization brainstorming:
48 // could a req-req condition even be a static map for one process?
49 // and matching something like [cid]->invoke?!?
50 // could even be contained in the specific condition class like a ReplyCondition or a TopicCondition
51 // -> dtm or some other subscription language?!? maybe this is already too much
52 // router config may then allow very specific and optimized configurations for
53 // certain patterns using specific condition classes and ports
54 
63 public:
64  static EventReceivingStrategy* create(const rsc::runtime::Properties& props);
65 
66  ParallelEventReceivingStrategy(unsigned int numThreads = 5);
68 
69  std::string getClassName() const;
70  void printContents(std::ostream& stream) const;
71 
72  void setHandlerErrorStrategy(
73  const ParticipantConfig::ErrorStrategy& strategy);
74 
75  // Qualification of HandlerPtr is required since there is another
76  // HandlerPtr type in eventprocessing.
77  virtual void addHandler(rsb::HandlerPtr handler, const bool& wait);
78  virtual void removeHandler(rsb::HandlerPtr handler, const bool& wait);
79 
80  virtual void addFilter(filter::FilterPtr filter);
81  virtual void removeFilter(filter::FilterPtr filter);
82 
83  void handle(EventPtr e);
84 
85 private:
86  // Qualification of HandlerPtr is required since there is another
87  // HandlerPtr type in eventprocessing.
88  bool filter(rsb::HandlerPtr handler, EventPtr event);
89  void deliver(rsb::HandlerPtr handler, EventPtr event);
90 
91  void handleDispatchError(const std::string& message);
92 
93  rsc::logging::LoggerPtr logger;
94  rsc::threading::OrderedQueueDispatcherPool<EventPtr, rsb::Handler> pool;
95 
96  mutable boost::shared_mutex filtersMutex;
97  std::set<filter::FilterPtr> filters;
98 
99  mutable boost::recursive_mutex errorStrategyMutex;
101 
102 };
103 
104 }
105 }