Class: Wamp::Router::Realm

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp/router/realm.rb

Overview

Realm

Constant Summary collapse

DEALER_MESSAGES =
[
  Wampproto::Message::Call,
  Wampproto::Message::Yield,
  Wampproto::Message::Register,
  Wampproto::Message::Unregister
].freeze
BROKER_MESSAGES =
[
  Wampproto::Message::Publish,
  Wampproto::Message::Subscribe,
  Wampproto::Message::Unsubscribe
].freeze
GOODBYE_MESSAGE =
Wampproto::Message::Goodbye

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Realm

Returns a new instance of Realm.



24
25
26
27
28
29
# File 'lib/wamp/router/realm.rb', line 24

def initialize(name)
  @name   = name
  @broker = Wampproto::Broker.new(id_gen)
  @dealer = Wampproto::Dealer.new(id_gen)
  @clients = {}
end

Instance Attribute Details

#brokerObject (readonly)

Returns the value of attribute broker.



7
8
9
# File 'lib/wamp/router/realm.rb', line 7

def broker
  @broker
end

#clientsObject (readonly)

Returns the value of attribute clients.



7
8
9
# File 'lib/wamp/router/realm.rb', line 7

def clients
  @clients
end

#dealerObject (readonly)

Returns the value of attribute dealer.



7
8
9
# File 'lib/wamp/router/realm.rb', line 7

def dealer
  @dealer
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/wamp/router/realm.rb', line 7

def name
  @name
end

Instance Method Details

#attach_client(client) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/wamp/router/realm.rb', line 31

def attach_client(client)
  session_id = client.session_id
  session_details = client.acceptor.session_details

  clients[session_id] = client
  broker.add_session(session_details)
  dealer.add_session(session_details)
end

#clearObject



44
45
46
# File 'lib/wamp/router/realm.rb', line 44

def clear
  clients.each { |client| remove_client(client.session_id) }
end

#detach_client(client) ⇒ Object



40
41
42
# File 'lib/wamp/router/realm.rb', line 40

def detach_client(client)
  remove_client(client.session_id)
end

#receive_message(session_id, message) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/wamp/router/realm.rb', line 48

def receive_message(session_id, message)
  case message
  when *DEALER_MESSAGES then handle_dealer(session_id, message)
  when *BROKER_MESSAGES then handle_broker(session_id, message)
  when GOODBYE_MESSAGE then handle_goodbye(session_id, message)
  end
end