Class: AnyCable::Rack::Server
- Inherits:
-
Object
- Object
- AnyCable::Rack::Server
- Includes:
- Logging
- Defined in:
- lib/anycable/rack/server.rb
Constant Summary collapse
- DEFAULT_HEADERS =
%w[cookie x-api-token].freeze
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.
-
#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.
-
#pubsub_channel ⇒ Object
readonly
Returns the value of attribute pubsub_channel.
-
#rpc_host ⇒ Object
readonly
Returns the value of attribute rpc_host.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*args) ⇒ Server
constructor
A new instance of Server.
- #inspect ⇒ Object
-
#start! ⇒ Object
rubocop:enable.
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(*args) ⇒ Server
Returns a new instance of Server.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/anycable/rack/server.rb', line 30 def initialize(*args) = args.last.is_a?(Hash) ? args.last : {} @hub = Hub.new @pinger = Pinger.new @coder = .fetch(:coder, Coders::JSON) @pubsub_channel = pubsub_channel @headers = .fetch(:headers, DEFAULT_HEADERS) @rpc_host = .fetch(:rpc_host) @broadcast = BroadcastSubscribers::RedisSubscriber.new( hub: hub, coder: coder, **AnyCable.config.to_redis_params ) @middleware = Middleware.new( header_names: headers, pinger: pinger, hub: hub, rpc_host: rpc_host, coder: coder ) log(:info) { "Using RPC server at #{rpc_host}" } end |
Instance Attribute Details
#broadcast ⇒ Object (readonly)
Returns the value of attribute broadcast.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def broadcast @broadcast end |
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def coder @coder end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def headers @headers end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def hub @hub end |
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def middleware @middleware end |
#pinger ⇒ Object (readonly)
Returns the value of attribute pinger.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def pinger @pinger end |
#pubsub_channel ⇒ Object (readonly)
Returns the value of attribute pubsub_channel.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def pubsub_channel @pubsub_channel end |
#rpc_host ⇒ Object (readonly)
Returns the value of attribute rpc_host.
21 22 23 |
# File 'lib/anycable/rack/server.rb', line 21 def rpc_host @rpc_host end |
Instance Method Details
#call(env) ⇒ Object
84 85 86 |
# File 'lib/anycable/rack/server.rb', line 84 def call(env) middleware.call(env) end |
#inspect ⇒ Object
88 89 90 |
# File 'lib/anycable/rack/server.rb', line 88 def inspect "#<AnyCable::Rack::Server(rpc_host: #{rpc_host}, headers: [#{headers.join(', ')}])>" end |
#start! ⇒ Object
rubocop:enable
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/anycable/rack/server.rb', line 59 def start! log(:info) { "Starting..." } pinger.run broadcast.subscribe(AnyCable.config.redis_channel) log(:info) { "Subscribed to #{AnyCable.config.redis_channel}" } @_started = true end |
#started? ⇒ Boolean
71 72 73 |
# File 'lib/anycable/rack/server.rb', line 71 def started? @_started == true end |
#stop ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/anycable/rack/server.rb', line 75 def stop return unless started? @_started = false broadcast_subscriber.unsubscribe(@_redis_channel) pinger.stop hub.close_all end |