Class: Vedeu::Distributed::Server
- Inherits:
-
Object
- Object
- Vedeu::Distributed::Server
- Includes:
- Singleton
- Defined in:
- lib/vedeu/distributed/server.rb
Overview
A class for the server side of the DRb server/client relationship.
Instance Attribute Summary collapse
- #configuration ⇒ Configuration readonly protected
Class Method Summary collapse
- .input(data, type = :key) ⇒ Object
- .output ⇒ void
- .restart ⇒ void
- .shutdown ⇒ void
- .start ⇒ void
- .status ⇒ Symbol
- .stop ⇒ void
Instance Method Summary collapse
- #drb? ⇒ Boolean private
- #drb_host ⇒ String private
- #drb_port ⇒ Fixnum|String private
- #drb_running? ⇒ |NilClass private
- #input(data, type = :keypress) ⇒ void (also: #read)
- #log(message) ⇒ void private
- #not_enabled ⇒ Symbol private
- #output ⇒ void (also: #write)
-
#pid ⇒ Fixnum
The PID of the currently running application.
- #restart ⇒ void
-
#shutdown ⇒ void
When called will stop the DRb server and attempt to terminate the client application.
- #start ⇒ Vedeu::Distributed::Server
- #status ⇒ Symbol
- #stop ⇒ void
- #uri ⇒ String private
Instance Attribute Details
#configuration ⇒ Configuration (readonly, protected)
167 168 169 |
# File 'lib/vedeu/distributed/server.rb', line 167 def configuration @configuration end |
Class Method Details
.input(data, type = :key) ⇒ Object
13 14 15 |
# File 'lib/vedeu/distributed/server.rb', line 13 def self.input(data, type = :key) instance.input(data, type) end |
.output ⇒ void
18 19 20 |
# File 'lib/vedeu/distributed/server.rb', line 18 def self.output instance.output end |
.restart ⇒ void
23 24 25 |
# File 'lib/vedeu/distributed/server.rb', line 23 def self.restart instance.restart end |
.shutdown ⇒ void
28 29 30 |
# File 'lib/vedeu/distributed/server.rb', line 28 def self.shutdown instance.shutdown end |
.start ⇒ void
33 34 35 |
# File 'lib/vedeu/distributed/server.rb', line 33 def self.start instance.start end |
.status ⇒ Symbol
38 39 40 |
# File 'lib/vedeu/distributed/server.rb', line 38 def self.status instance.status end |
.stop ⇒ void
43 44 45 |
# File 'lib/vedeu/distributed/server.rb', line 43 def self.stop instance.stop end |
Instance Method Details
#drb? ⇒ Boolean (private)
172 173 174 |
# File 'lib/vedeu/distributed/server.rb', line 172 def drb? Vedeu::Configuration.drb? end |
#drb_host ⇒ String (private)
177 178 179 |
# File 'lib/vedeu/distributed/server.rb', line 177 def drb_host Vedeu::Configuration.drb_host end |
#drb_port ⇒ Fixnum|String (private)
187 188 189 |
# File 'lib/vedeu/distributed/server.rb', line 187 def drb_port Vedeu::Configuration.drb_port end |
#drb_running? ⇒ |NilClass (private)
182 183 184 |
# File 'lib/vedeu/distributed/server.rb', line 182 def drb_running? DRb.thread end |
#input(data, type = :keypress) ⇒ void Also known as: read
50 51 52 |
# File 'lib/vedeu/distributed/server.rb', line 50 def input(data, type = :keypress) Vedeu.trigger(:_drb_input_, data, type) end |
#log(message) ⇒ void (private)
192 193 194 |
# File 'lib/vedeu/distributed/server.rb', line 192 def log() Vedeu.log(type: :drb, message: "#{}: '#{uri}'") end |
#not_enabled ⇒ Symbol (private)
197 198 199 200 201 |
# File 'lib/vedeu/distributed/server.rb', line 197 def not_enabled log('Not enabled') :drb_not_enabled end |
#output ⇒ void Also known as: write
56 57 58 |
# File 'lib/vedeu/distributed/server.rb', line 56 def output Vedeu.trigger(:_drb_retrieve_output_) end |
#pid ⇒ Fixnum
62 63 64 |
# File 'lib/vedeu/distributed/server.rb', line 62 def pid Process.pid end |
#restart ⇒ void
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vedeu/distributed/server.rb', line 67 def restart log('Attempting to restart') return not_enabled unless drb? if drb_running? log('Restarting') stop start else log('Not running') start end end |
#shutdown ⇒ void
Note:
:exit never gets triggered as when the DRb server goes away, no further methods will be called.
This method returns an undefined value.
When called will stop the DRb server and attempt to terminate the client application.
95 96 97 98 99 100 101 102 103 |
# File 'lib/vedeu/distributed/server.rb', line 95 def shutdown return not_enabled unless drb? stop if drb_running? Vedeu.trigger(:_exit_) Vedeu::Terminal.restore_screen end |
#start ⇒ Vedeu::Distributed::Server
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/vedeu/distributed/server.rb', line 106 def start log('Attempting to start') return not_enabled unless drb? if drb_running? log('Already started') else log('Starting') DRb.start_service(uri, self) # DRb.thread.join # not convinced this is needed here end end |
#status ⇒ Symbol
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vedeu/distributed/server.rb', line 124 def status log('Fetching status') return not_enabled unless drb? if drb_running? log('Running') :running else log('Stopped') :stopped end end |
#stop ⇒ void
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/vedeu/distributed/server.rb', line 143 def stop log('Attempting to stop') return not_enabled unless drb? if drb_running? log('Stopping') DRb.stop_service DRb.thread.join else log('Already stopped') end rescue NoMethodError # raised when #join is called on NilClass. Vedeu.log(type: :debug, message: 'Attempted to #join on DRb.thread.') end |
#uri ⇒ String (private)
204 205 206 |
# File 'lib/vedeu/distributed/server.rb', line 204 def uri Vedeu::Distributed::Uri.new(drb_host, drb_port).to_s end |