0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReactorFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #ifndef AsyncComm_ReactorFactory_h
30 #define AsyncComm_ReactorFactory_h
31 
32 #include "Reactor.h"
33 
34 #include <boost/thread/thread.hpp>
35 
36 #include <atomic>
37 #include <cassert>
38 #include <mutex>
39 #include <random>
40 #include <set>
41 #include <vector>
42 
43 namespace Hypertable {
44 
53 
54  public:
55 
65  static void initialize(uint16_t reactor_count);
66 
69  static void destroy();
70 
72  static void join();
73 
81  static void get_reactor(ReactorPtr &reactor,
83  assert(ms_reactors.size() > 0);
84  if (priority == Reactor::Priority::HIGH)
85  reactor = ms_reactors.front();
86  else
87  reactor = ms_reactors[(ms_next_reactor++ % (ms_reactors.size()-2))+1];
88  }
89 
93  static void get_timer_reactor(ReactorPtr &reactor) {
94  assert(ms_reactors.size() > 0);
95  reactor = ms_reactors.back();
96  }
97 
99  static std::vector<ReactorPtr> ms_reactors;
100 
102  static boost::thread_group ms_threads;
103 
105  static std::default_random_engine rng;
106 
108  static bool ms_epollet;
109 
110  // Use POSIX poll() as polling mechanism
111  static bool use_poll;
112 
114  static bool proxy_master;
115 
117  static bool verbose;
118 
119  private:
120 
123 
125  static std::atomic<int> ms_next_reactor;
126 
127  };
129 }
130 
131 #endif // AsyncComm_ReactorFactory_h
132 
static void get_reactor(ReactorPtr &reactor, Reactor::Priority priority=Reactor::Priority::NORMAL)
This method returns the 'next' reactor.
static std::mutex mutex
Definition: Logger.cc:43
static bool verbose
Verbose mode.
static void initialize(uint16_t reactor_count)
Initializes I/O reactors.
static bool ms_epollet
Use "edge triggered" epoll.
static std::vector< ReactorPtr > ms_reactors
Vector of reactors (last position is timer reactor)
static std::default_random_engine rng
Pseudo random number generator.
Static class used to setup and manage I/O reactors.
static std::atomic< int > ms_next_reactor
Atomic integer used for round-robin assignment of reactors.
static boost::thread_group ms_threads
Boost thread_group for managing reactor threads.
static void destroy()
This method shuts down the reactors.
static void join()
Joins with reactor threads.
std::shared_ptr< Reactor > ReactorPtr
Shared smart pointer to Reactor.
Definition: Reactor.h:295
Declarations for Reactor.
Hypertable definitions
Priority
Enumeration for reactor priority.
Definition: Reactor.h:73
static std::mutex ms_mutex
Mutex to serialize calls to initialize.
static bool proxy_master
Set to true if this process is acting as "Proxy Master".
static void get_timer_reactor(ReactorPtr &reactor)
This method returns the timer reactor.