Class: AnyCable::Rack::Server
- Inherits:
-
Object
- Object
- AnyCable::Rack::Server
- Includes:
- Logging
- Defined in:
- lib/anycable/rack/server.rb
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#broadcast ⇒ Object
readonly
Returns the value of attribute broadcast.
-
#coder ⇒ Object
readonly
Returns the value of attribute coder.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
-
#pinger ⇒ Object
readonly
Returns the value of attribute pinger.
-
#rpc_cli ⇒ Object
readonly
Returns the value of attribute rpc_cli.
-
#rpc_client ⇒ Object
readonly
Returns the value of attribute rpc_client.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config: AnyCable::Rack.config) ⇒ Server
constructor
A new instance of Server.
- #inspect ⇒ Object
- #shutdown ⇒ Object
-
#start! ⇒ Object
rubocop:enable.
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(config: AnyCable::Rack.config) ⇒ Server
Returns a new instance of Server.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/anycable/rack/server.rb', line 28 def initialize(config: AnyCable::Rack.config) @config = config @hub = Hub.new @pinger = Pinger.new # TODO: Support other coders @coder = Coders::JSON @broadcast = resolve_broadcast_adapter @rpc_client = RPC::Client.new( host: config.rpc_addr, size: config.rpc_client_pool_size, timeout: config.rpc_client_timeout ) @middleware = Middleware.new( header_names: config.headers, pinger: pinger, hub: hub, rpc_client: rpc_client, coder: coder ) log(:info) { "Connecting to RPC server at #{config.rpc_addr}" } end |
Instance Attribute Details
#broadcast ⇒ Object (readonly)
Returns the value of attribute broadcast.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def broadcast @broadcast end |
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def coder @coder end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def config @config end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def headers @headers end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def hub @hub end |
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def middleware @middleware end |
#pinger ⇒ Object (readonly)
Returns the value of attribute pinger.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def pinger @pinger end |
#rpc_cli ⇒ Object (readonly)
Returns the value of attribute rpc_cli.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def rpc_cli @rpc_cli end |
#rpc_client ⇒ Object (readonly)
Returns the value of attribute rpc_client.
18 19 20 |
# File 'lib/anycable/rack/server.rb', line 18 def rpc_client @rpc_client end |
Instance Method Details
#call(env) ⇒ Object
85 86 87 |
# File 'lib/anycable/rack/server.rb', line 85 def call(env) middleware.call(env) end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/anycable/rack/server.rb', line 89 def inspect "#<AnyCable::Rack::Server(rpc_addr: #{config.rpc_addr}, headers: [#{config.headers.join(", ")}])>" end |
#shutdown ⇒ Object
66 67 68 69 70 |
# File 'lib/anycable/rack/server.rb', line 66 def shutdown log(:info) { "Shutting down..." } Rack.rpc_server&.shutdown hub.broadcast_all(coder.encode(type: "disconnect", reason: "server_restart", reconnect: true)) end |
#start! ⇒ Object
rubocop:enable
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/anycable/rack/server.rb', line 54 def start! log(:info) { "Starting..." } pinger.run broadcast.start Rack.rpc_server.run if config.run_rpc @_started = true end |
#started? ⇒ Boolean
72 73 74 |
# File 'lib/anycable/rack/server.rb', line 72 def started? @_started == true end |
#stop ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/anycable/rack/server.rb', line 76 def stop return unless started? @_started = false broadcast_subscriber.stop pinger.stop hub.close_all end |