Class: UState::Server::Backends::Base
- Inherits:
-
Object
- Object
- UState::Server::Backends::Base
- Defined in:
- lib/ustate/server/backends/base.rb
Overview
Largely stolen from Thin
Direct Known Subclasses
Constant Summary collapse
- TIMEOUT =
5
- MAXIMUM_CONNECTIONS =
1024
- MAX_CONNECTIONS =
512
Instance Attribute Summary collapse
-
#maximum_connections ⇒ Object
Returns the value of attribute maximum_connections.
-
#server ⇒ Object
Returns the value of attribute server.
-
#ssl ⇒ Object
writeonly
Sets the attribute ssl.
-
#ssl_options ⇒ Object
writeonly
Sets the attribute ssl_options.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#close ⇒ Object
Free up resources used by the backend.
-
#config ⇒ Object
Configure backend.
-
#connection_finished(connection) ⇒ Object
Called by a connection when it’s unbound.
-
#empty? ⇒ Boolean
No connections?.
-
#initialize(opts = {}) ⇒ Base
constructor
A new instance of Base.
- #running? ⇒ Boolean
-
#size ⇒ Object
No of connections.
- #ssl? ⇒ Boolean
- #start ⇒ Object
-
#stop ⇒ Object
Graceful stop.
-
#stop! ⇒ Object
Force stop.
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 |
# File 'lib/ustate/server/backends/base.rb', line 14 def initialize(opts = {}) @connections = [] @server = opts[:server] @timeout = opts[:timeout] || TIMEOUT @maximum_connections = opts[:maximum_connections] || MAXIMUM_CONNECTIONS end |
Instance Attribute Details
#maximum_connections ⇒ Object
Returns the value of attribute maximum_connections.
10 11 12 |
# File 'lib/ustate/server/backends/base.rb', line 10 def maximum_connections @maximum_connections end |
#server ⇒ Object
Returns the value of attribute server.
8 9 10 |
# File 'lib/ustate/server/backends/base.rb', line 8 def server @server end |
#ssl=(value) ⇒ Object (writeonly)
Sets the attribute ssl
11 12 13 |
# File 'lib/ustate/server/backends/base.rb', line 11 def ssl=(value) @ssl = value end |
#ssl_options=(value) ⇒ Object (writeonly)
Sets the attribute ssl_options
11 12 13 |
# File 'lib/ustate/server/backends/base.rb', line 11 def (value) @ssl_options = value end |
#timeout ⇒ Object
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/ustate/server/backends/base.rb', line 9 def timeout @timeout end |
Instance Method Details
#close ⇒ Object
Free up resources used by the backend
65 66 |
# File 'lib/ustate/server/backends/base.rb', line 65 def close end |
#config ⇒ Object
Configure backend
57 58 59 60 61 62 |
# File 'lib/ustate/server/backends/base.rb', line 57 def config EventMachine.epoll @maximum_connections = EventMachine.set_descriptor_table_size(@maximum_connections) end |
#connection_finished(connection) ⇒ Object
Called by a connection when it’s unbound
73 74 75 76 77 78 |
# File 'lib/ustate/server/backends/base.rb', line 73 def connection_finished(connection) @connections.delete connection # Finalize graceful stop if there's no more active connections. stop! if @stopping and @connections.empty? end |
#empty? ⇒ Boolean
No connections?
81 82 83 |
# File 'lib/ustate/server/backends/base.rb', line 81 def empty? @connections.empty? end |
#running? ⇒ Boolean
68 69 70 |
# File 'lib/ustate/server/backends/base.rb', line 68 def running? @running end |
#size ⇒ Object
No of connections
86 87 88 |
# File 'lib/ustate/server/backends/base.rb', line 86 def size @connections.size end |
#ssl? ⇒ Boolean
12 |
# File 'lib/ustate/server/backends/base.rb', line 12 def ssl?; @ssl; end |
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ustate/server/backends/base.rb', line 21 def start @stopping = false starter = proc do connect @running = true end # Allow for early run-up of eventmachine if EventMachine.reactor_running? starter.call else EventMachine.run &starter end end |
#stop ⇒ Object
Graceful stop
37 38 39 40 41 42 43 44 |
# File 'lib/ustate/server/backends/base.rb', line 37 def stop @running = false @stopping = true # Stop accepting connections disconnect stop! if @connections.empty? end |
#stop! ⇒ Object
Force stop
47 48 49 50 51 52 53 54 |
# File 'lib/ustate/server/backends/base.rb', line 47 def stop! @running = false @stopping = false EventMachine.stop if EventMachine.reactor_running? @connections.each { |connection| connection.close_connection } close end |