Class: GameMachine::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/game_machine/application.rb

Class Method Summary collapse

Class Method Details

.akkaObject



15
16
17
# File 'lib/game_machine/application.rb', line 15

def akka
  Akka.instance
end

.configObject



19
20
21
# File 'lib/game_machine/application.rb', line 19

def config
  AppConfig.instance.config
end

.create_gridsObject



95
96
97
# File 'lib/game_machine/application.rb', line 95

def create_grids
  Grid.load_from_config
end

.data_storeObject



11
12
13
# File 'lib/game_machine/application.rb', line 11

def data_store
  DataStore.instance
end

.initialize!Object



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

def initialize!
  AppConfig.instance.load_config
  akka.initialize!
end

.load_gamesObject



99
100
101
102
# File 'lib/game_machine/application.rb', line 99

def load_games
  require_relative '../../games/routes.rb'
  require_relative '../../games/boot.rb'
end

.orm_connectObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/game_machine/application.rb', line 77

def orm_connect
  if config.orm
    pool = GameMachine::JavaLib::DbConnectionPool.getInstance
    unless pool.connect(
      'game_machine_orm',
      config.jdbc.hostname,
      config.jdbc.port,
      config.jdbc.database,
      config.jdbc.ds,
      config.jdbc.username,
      config.jdbc.password || ''
    )
      GameMachine.logger.error "Unable to establish database connection, exiting"
      System.exit 1
    end
  end
end

.register(system_class) ⇒ Object



27
28
29
30
# File 'lib/game_machine/application.rb', line 27

def register(system_class)
  registered << system_class
  GameMachine.logger.debug "#{system_class} registered"
end

.registeredObject



23
24
25
# File 'lib/game_machine/application.rb', line 23

def registered
  @@registered ||= Set.new
end

.startObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/game_machine/application.rb', line 45

def start
  create_grids

  unless GameMachine.env == 'test'
    GameMachine::Actor::Reloadable.update_paths(true)
  end

  start_actor_system
  data_store
  orm_connect
  start_endpoints
  start_core_systems
  start_handlers

  if GameMachine.env == 'development'
    start_development_systems
  end

  start_game_systems
  load_games
  start_mono

  GameMachine.logger.info("Game Machine start successful")
  
  # This call blocks, make it the last thing we do
  if config.http.enabled
    Thread.new do
      start_http
    end
  end
end

.start_actor_systemObject



32
33
34
# File 'lib/game_machine/application.rb', line 32

def start_actor_system
  akka.start
end

.start_core_systemsObject

TODO configurize router sizes



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/game_machine/application.rb', line 143

def start_core_systems
  JavaLib::GameMachineLoader.StartMessageGateway
  Actor::Builder.new(CloudUpdater).start
  Actor::Builder.new(ClusterMonitor).start
  Actor::Builder.new(ObjectDb).distributed(config.routers.objectdb).start
  Actor::Builder.new(MessageQueue).start
  Actor::Builder.new(SystemMonitor).start
  Actor::Builder.new(ReloadableMonitor).start
  Actor::Builder.new(Scheduler).start
  Actor::Builder.new(WriteBehindCache).distributed(config.routers.objectdb).start
  Actor::Builder.new(ClientManager).start
  Actor::Builder.new(SystemStats).start
  Actor::Builder.new(GameSystems::RemoteEcho).with_router(JavaLib::RoundRobinRouter,config.routers.game_handler).start

  if config.use_regions
    # Our cluster singleton for managing regions
    Actor::Builder.new(GameSystems::RegionManager).singleton

    # Hands out current region info to clients/other actors
    Actor::Builder.new(GameSystems::RegionService).start
  end

  if ENV.has_key?('RESTARTABLE')
    GameMachine.logger.info "restartable=true.  Will respond to tmp/gm_restart.txt"
    Actor::Builder.new(RestartWatcher).start
  end
end

.start_development_systemsObject



139
140
# File 'lib/game_machine/application.rb', line 139

def start_development_systems
end

.start_endpointsObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/game_machine/application.rb', line 115

def start_endpoints
  if config.tcp.enabled
    JavaLib::TcpServer.start(config.tcp.host, config.tcp.port);
    GameMachine.logger.info(
      "Tcp starting on #{config.tcp.host}:#{config.tcp.port}"
    )
  end

  if config.udp.enabled
    JavaLib::UdpServer.start(config.udp.host,config.udp.port)
    Actor::Builder.new(Endpoints::UdpIncoming).with_router(
      JavaLib::RoundRobinRouter,config.routers.udp).start
  end
end

.start_game_systemsObject



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/game_machine/application.rb', line 171

def start_game_systems
  Actor::Builder.new(GameSystems::Devnull).start#.with_router(JavaLib::RoundRobinRouter,4).start
  Actor::Builder.new(GameSystems::ObjectDbProxy).with_router(JavaLib::RoundRobinRouter,2).start
  JavaLib::GameMachineLoader.StartEntityTracking
  Actor::Builder.new(GameSystems::LocalEcho).with_router(JavaLib::RoundRobinRouter,1).start
  Actor::Builder.new(GameSystems::LocalEcho).with_name('DistributedLocalEcho').distributed(2).start
  Actor::Builder.new(GameSystems::StressTest).with_router(JavaLib::RoundRobinRouter,1).start
  Actor::Builder.new(GameSystems::ChatManager).start
  Actor::Builder.new(GameSystems::TeamManager).start
  Actor::Builder.new(GameSystems::JsonModelPersistence).start
end

.start_handlersObject



130
131
132
133
134
135
136
137
# File 'lib/game_machine/application.rb', line 130

def start_handlers
  Actor::Builder.new(Handlers::Request).with_router(
    JavaLib::RoundRobinRouter,config.routers.request_handler
  ).start
  Actor::Builder.new(Handlers::Game).with_router(
    JavaLib::RoundRobinRouter,config.routers.game_handler
  ).start
end

.start_httpObject



104
105
106
# File 'lib/game_machine/application.rb', line 104

def start_http
  require_relative '../../web/app'
end

.start_monoObject



108
109
110
111
112
113
# File 'lib/game_machine/application.rb', line 108

def start_mono
  if config.mono_enabled
    GameMachine.logger.info "Starting mono server"
    MonoServer.new.run!
  end
end

.stopObject



40
41
42
43
# File 'lib/game_machine/application.rb', line 40

def stop
  stop_actor_system
  DataStore.instance.shutdown
end

.stop_actor_systemObject



36
37
38
# File 'lib/game_machine/application.rb', line 36

def stop_actor_system
  akka.stop
end