Class: JerbilService::Base
- Inherits:
-
Object
- Object
- JerbilService::Base
- Defined in:
- lib/jerbil/jerbil_service/base.rb
Overview
JerbilService::Base
Parent class to be used for all services. Manages all interactions with Jerbil and sets up a Jellog logger.
In general, services using this class are intended to be started and stopped using Supervisor and clients are expected to interact with the service through Client.
Further details can be found in Jerbil Service Readme
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
deprecated
Deprecated.
-
unless I can find why I allowed it!
-
Instance Method Summary collapse
-
#drb_address ⇒ Object
deprecated
Deprecated.
-
as above
-
-
#initialize(name, pkey, options) ⇒ Base
constructor
create a Jerbil Service.
-
#stop_callback(pkey = "") ⇒ Object
used to stop the service.
-
#verify_callback(skey = "") ⇒ Object
this is used by callers just to check that the service is running if caller is unaware of the key, this will fail.
-
#wait(pkey = '') ⇒ Object
wait for calls.
Constructor Details
#initialize(name, pkey, options) ⇒ Base
create a Jerbil Service
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/jerbil/jerbil_service/base.rb', line 74 def initialize(name, pkey, ) @name = name.to_s.capitalize @env = [:environment] @private_key = pkey # change the process name $0 = "#{@name.downcase}-#{@env}" # start up a logger log_opts = Jellog::Config.intersection() @logger = Jellog::Logger.new(@name, log_opts) # @logger.log_level = options[:log_level] @exit = [:exit_on_stop] begin @service = Jerbil::ServiceRecord.new(name, @env, :verify_callback, :stop_callback) # register the service # Note that if the options hash includes a :jerbil_env, then this # will be passed to select a Jerbil system running at other than :prod, the default # This is not documented above because it is for testing Jerbil only @jerbil_server = Jerbil::Servers.get_local_server([:jerbil_env]) # now connect to it jerbil = @jerbil_server.connect # and register self jerbil.register(@service) # and start it - preventing anything nasty from coming over DRb $SAFE = 1 unless [:unsafe] DRb.start_service(@service.drb_address, self) rescue Jerbil::MissingServer @logger.fatal("Cannot find a local Jerbil server") raise rescue Jerbil::JerbilConfigError => err @logger.fatal("Error in Jerbil Config File: #{err.}") raise rescue Jerbil::JerbilServiceError =>jerr @logger.fatal("Error with Jerbil Service: #{jerr.}") raise rescue Jerbil::ServerConnectError @logger.fatal("Error connecting to Jerbil Server") raise rescue DRb::DRbConnError =>derr @logger.fatal("Error setting up DRb Server: #{derr.}") raise Jerbil::ServerConnectError end @logger.system "Started service: #{@service.ident}" @logger.info "Jerbil Service #{@service.ident} running under #{RUBY_VERSION}" end |
Instance Attribute Details
#service ⇒ Object (readonly)
-
unless I can find why I allowed it!
give access to Jerbil::ServiceRecord Record for this service
131 132 133 |
# File 'lib/jerbil/jerbil_service/base.rb', line 131 def service @service end |
Instance Method Details
#drb_address ⇒ Object
-
as above
return the DRb address for the service
135 136 137 |
# File 'lib/jerbil/jerbil_service/base.rb', line 135 def drb_address @service.drb_address end |
#stop_callback(pkey = "") ⇒ Object
used to stop the service. Requires the private key
This method is not intended to be called directly. To stop a service, the user should use the Supervisor class.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/jerbil/jerbil_service/base.rb', line 160 def stop_callback(pkey="") check_key(pkey) # deregister jerbil = @jerbil_server.connect jerbil.remove(@service) @logger.system "Stopped service: #{@service.ident}" @logger.close # and stop the DRb service, to exit gracefully DRb.stop_service end |
#verify_callback(skey = "") ⇒ Object
this is used by callers just to check that the service is running if caller is unaware of the key, this will fail
This method is not intended to be called directly. It is usually called when connecting to the service (see Jerbil::ServiceRecord#connect).
147 148 149 150 151 |
# File 'lib/jerbil/jerbil_service/base.rb', line 147 def verify_callback(skey="") check_key(skey, @service.key) @logger.info "Verify called" return true end |
#wait(pkey = '') ⇒ Object
wait for calls. This hides the DRb call to be made once the service is up and running. It is not intended to be called by anyone outside of Supervisor
175 176 177 178 |
# File 'lib/jerbil/jerbil_service/base.rb', line 175 def wait(pkey='') check_key(pkey) DRb.thread.join end |