Class: GameMachine::Akka

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
server/lib/game_machine/akka.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address


8
9
10
# File 'server/lib/game_machine/akka.rb', line 8

def address
  @address
end

#app_configObject (readonly)

Returns the value of attribute app_config


8
9
10
# File 'server/lib/game_machine/akka.rb', line 8

def app_config
  @app_config
end

#hashringObject (readonly)

Returns the value of attribute hashring


8
9
10
# File 'server/lib/game_machine/akka.rb', line 8

def hashring
  @hashring
end

Class Method Details

.addressObject


10
11
12
13
14
# File 'server/lib/game_machine/akka.rb', line 10

def self.address
  host = AppConfig.instance.config.akka.host
  port = AppConfig.instance.config.akka.port
  "akka.tcp://#{Akka.instance.config_name}@#{host}:#{port}"
end

Instance Method Details

#actor_systemObject


27
28
29
# File 'server/lib/game_machine/akka.rb', line 27

def actor_system
  @actor_system.actor_system
end

#akka_configObject


35
36
37
38
39
# File 'server/lib/game_machine/akka.rb', line 35

def akka_config
  config = load_akka_config(config_name)
  config = set_address(config)
  config = set_seeds(config)
end

#config_nameObject


31
32
33
# File 'server/lib/game_machine/akka.rb', line 31

def config_name
  'cluster'
end

#init_cluster!(address) ⇒ Object


22
23
24
25
# File 'server/lib/game_machine/akka.rb', line 22

def init_cluster!(address)
  @address = address
  @hashring = JavaLib::Hashring.new('servers',[address],3)
end

#initialize!Object


16
17
18
19
20
# File 'server/lib/game_machine/akka.rb', line 16

def initialize!
  @app_config = AppConfig.instance
  @address = self.class.address
  @hashring = JavaLib::Hashring.new('servers',[address],3)
end

#startObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'server/lib/game_machine/akka.rb', line 41

def start
  @actor_system = Actor::System.new(config_name,akka_config)
  @actor_system.create!
  JavaLib::GameMachineLoader.new.run(actor_system)
  if Application.config.seeds.size >= 1
    Application.config.seeds.each do |seed|
      host,port = seed.split(':')
      GameMachine.logger.info "JOINING REMOTE #{host} #{port}"
      JavaLib::ActorUtil.joinCluster("akka.tcp", config_name, host, port.to_i)
    end
  else
    GameMachine.logger.info "JOINING SELF"
    JavaLib::ActorUtil.joinCluster("akka.tcp", config_name, app_config.config.akka.host, app_config.config.akka.port)
  end
end

#stopObject


57
58
59
# File 'server/lib/game_machine/akka.rb', line 57

def stop
  @actor_system.shutdown!
end