Async::ServiceSourceAsyncServiceGeneric

class Generic

Captures the stateful behaviour of a specific service. Specifies the interfaces required by derived classes.

Designed to be invoked within an Async::Controller::Container.

Definitions

def self.wrap(environment)

Convert the given environment into a service if possible.

Signature

parameter environment Environment

The environment to use to construct the service.

returns Generic | Nil

The constructed service if the environment specifies a service class.

Implementation

def self.wrap(environment)
	evaluator = environment.evaluator
	
	if evaluator.key?(:service_class)
		if service_class = evaluator.service_class
			return service_class.new(environment, evaluator)
		end
	end
end

def initialize(environment, evaluator = environment.evaluator)

Initialize the service from the given environment.

Signature

parameter environment Environment

Implementation

def initialize(environment, evaluator = environment.evaluator)
	@environment = environment
	@evaluator = evaluator
end

attr :environment

Signature

attribute Environment

The environment which is used to configure the service.

def to_h

Convert the service evaluator to a hash.

Signature

returns Hash

A hash representation of the evaluator.

Implementation

def to_h
	@evaluator.to_h
end

def name

The name of the service - used for informational purposes like logging. e.g. myapp.com.

Implementation

def name
	@evaluator.name
end

def start

Start the service. Called before the container setup.

Implementation

def start
	Console.debug(self){"Starting service #{self.name}..."}
end

def setup(container)

Setup the service into the specified container.

Signature

parameter container Async::Container::Generic

Implementation

def setup(container)
	Console.debug(self){"Setting up service #{self.name}..."}
end

def stop(graceful = true)

Stop the service. Called after the container is stopped.

Implementation

def stop(graceful = true)
	Console.debug(self){"Stopping service #{self.name}..."}
end