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 ⇒ Vedeu::Configuration readonly protected
Class Method Summary collapse
- .drb_restart ⇒ void
- .drb_start ⇒ void
- .drb_status ⇒ Symbol
- .drb_stop ⇒ void
- .input(data, type = :key) ⇒ Object
- .output ⇒ void
- .restart ⇒ void
- .shutdown ⇒ void
- .start ⇒ void
- .status ⇒ Symbol
- .stop ⇒ void
Instance Method Summary collapse
- #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
Restart the DRb server.
-
#shutdown ⇒ void
When called will stop the DRb server and attempt to terminate the client application.
-
#start ⇒ Vedeu::Distributed::Server
Start the DRb server.
-
#status ⇒ Symbol
Fetch the status of the DRb server.
-
#stop ⇒ void
Stop the DRb server.
- #uri ⇒ String private
Instance Attribute Details
#configuration ⇒ Vedeu::Configuration (readonly, protected)
210 211 212 |
# File 'lib/vedeu/distributed/server.rb', line 210 def configuration @configuration end |
Class Method Details
.drb_restart ⇒ void
This method returns an undefined value.
37 38 39 |
# File 'lib/vedeu/distributed/server.rb', line 37 def restart instance.restart end |
.drb_start ⇒ void
This method returns an undefined value.
50 51 52 |
# File 'lib/vedeu/distributed/server.rb', line 50 def start instance.start end |
.drb_status ⇒ Symbol
57 58 59 |
# File 'lib/vedeu/distributed/server.rb', line 57 def status instance.status end |
.drb_stop ⇒ void
This method returns an undefined value.
64 65 66 |
# File 'lib/vedeu/distributed/server.rb', line 64 def stop instance.stop end |
.input(data, type = :key) ⇒ Object
22 23 24 |
# File 'lib/vedeu/distributed/server.rb', line 22 def input(data, type = :key) instance.input(data, type) end |
.output ⇒ void
This method returns an undefined value.
28 29 30 |
# File 'lib/vedeu/distributed/server.rb', line 28 def output instance.output end |
.restart ⇒ void
This method returns an undefined value.
34 35 36 |
# File 'lib/vedeu/distributed/server.rb', line 34 def restart instance.restart end |
.shutdown ⇒ void
This method returns an undefined value.
41 42 43 |
# File 'lib/vedeu/distributed/server.rb', line 41 def shutdown instance.shutdown end |
.start ⇒ void
This method returns an undefined value.
47 48 49 |
# File 'lib/vedeu/distributed/server.rb', line 47 def start instance.start end |
.status ⇒ Symbol
54 55 56 |
# File 'lib/vedeu/distributed/server.rb', line 54 def status instance.status end |
.stop ⇒ void
This method returns an undefined value.
61 62 63 |
# File 'lib/vedeu/distributed/server.rb', line 61 def stop instance.stop end |
Instance Method Details
#drb_running? ⇒ |NilClass (private)
215 216 217 |
# File 'lib/vedeu/distributed/server.rb', line 215 def drb_running? DRb.thread end |
#input(data, type = :keypress) ⇒ void Also known as: read
This method returns an undefined value.
74 75 76 |
# File 'lib/vedeu/distributed/server.rb', line 74 def input(data, type = :keypress) Vedeu.trigger(:_drb_input_, data, type) end |
#log(message) ⇒ void (private)
This method returns an undefined value.
220 221 222 |
# File 'lib/vedeu/distributed/server.rb', line 220 def log() Vedeu.log(type: :drb, message: "#{}: '#{uri}'") end |
#not_enabled ⇒ Symbol (private)
225 226 227 228 229 |
# File 'lib/vedeu/distributed/server.rb', line 225 def not_enabled log('Not enabled') :drb_not_enabled end |
#output ⇒ void Also known as: write
This method returns an undefined value.
80 81 82 |
# File 'lib/vedeu/distributed/server.rb', line 80 def output Vedeu.trigger(:_drb_retrieve_output_) end |
#pid ⇒ Fixnum
Returns The PID of the currently running application.
86 87 88 |
# File 'lib/vedeu/distributed/server.rb', line 86 def pid Process.pid end |
#restart ⇒ void
This method returns an undefined value.
Restart the DRb server.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vedeu/distributed/server.rb', line 96 def restart log('Attempting to restart') return not_enabled unless Vedeu.config.drb? if drb_running? log('Restarting') stop else log('Not running') end start end |
#shutdown ⇒ void
: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.
122 123 124 125 126 127 128 129 130 |
# File 'lib/vedeu/distributed/server.rb', line 122 def shutdown return not_enabled unless Vedeu.config.drb? stop if drb_running? Vedeu.trigger(:_exit_) Vedeu::Terminal.restore_screen end |
#start ⇒ Vedeu::Distributed::Server
Start the DRb server.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/distributed/server.rb', line 138 def start log('Attempting to start') return not_enabled unless Vedeu.config.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
Fetch the status of the DRb server.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/vedeu/distributed/server.rb', line 161 def status log('Fetching status') return not_enabled unless Vedeu.config.drb? if drb_running? log('Running') :running else log('Stopped') :stopped end end |
#stop ⇒ void
This method returns an undefined value.
Stop the DRb server.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/vedeu/distributed/server.rb', line 185 def stop log('Attempting to stop') return not_enabled unless Vedeu.config.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: :drb, message: 'Attempted to #join on DRb.thread.') end |