Class: GameMachine::Akka

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
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.



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

def address
  @address
end

#app_configObject (readonly)

Returns the value of attribute app_config.



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

def app_config
  @app_config
end

#hashringObject (readonly)

Returns the value of attribute hashring.



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

def hashring
  @hashring
end

Class Method Details

.addressObject



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

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



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

def actor_system
  @actor_system.actor_system
end

#akka_configObject



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

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

#config_nameObject



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

def config_name
  'cluster'
end

#init_cluster!(address) ⇒ Object



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

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

#initialize!Object



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

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

#startObject



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

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



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

def stop
  @actor_system.shutdown!
end