lib/ruby_skynet/server.rb in ruby_skynet-0.8.1 vs lib/ruby_skynet/server.rb in ruby_skynet-1.0.0

- old
+ new

@@ -15,11 +15,11 @@ # Start a single instance of the server def self.start(start_port = nil, ip_address = nil) @@server ||= new(start_port, ip_address) # Stop the skynet server on shutdown - # To ensure services are de-registered in doozer + # To ensure services are de-registered in the service registry at_exit do ::RubySkynet::Server.stop end end @@ -124,10 +124,22 @@ # Wait forever until the running server stops def wait_until_server_stops @listener_thread.join end + # Registers a Service Class as being available at this server + def register_service(klass) + logger.info "Registering Service: #{klass.name} with name: #{klass.skynet_name}" + ::RubySkynet.service_registry.register_service(klass.skynet_name, klass.skynet_version || 1, klass.skynet_region, @hostname, @port) + end + + # De-register service from this server + def deregister_service(klass) + logger.info "De-registering Service: #{klass.name} with name: #{klass.skynet_name}" + ::RubySkynet.service_registry.deregister_service(klass.skynet_name, klass.skynet_version || 1, klass.skynet_region, @hostname, @port) + end + ############################################################################ protected def run logger.info("Starting listener on #{hostname}:#{port}") @@ -200,21 +212,9 @@ logger.error "#handle_connection Exception", exc ensure # Disconnect from the client client.close logger.debug "Disconnected from the client" - end - - # Registers a Service Class as being available at this server - def register_service(klass) - logger.info "Registering Service: #{klass.name} with name: #{klass.skynet_name}" - ::RubySkynet.services.register_service(klass.skynet_name, klass.skynet_version || 1, klass.skynet_region, @hostname, @port) - end - - # De-register service from this server - def deregister_service(klass) - logger.info "De-registering Service: #{klass.name} with name: #{klass.skynet_name}" - ::RubySkynet.services.deregister_service(klass.skynet_name, klass.skynet_version || 1, klass.skynet_region, @hostname, @port) end # Called for each message received from the client # Returns a Hash that is sent back to the caller def on_message(skynet_name, method, params)