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)
197 198 199 |
# File 'lib/vedeu/distributed/server.rb', line 197 def configuration @configuration end |
Class Method Details
.drb_restart ⇒ void
This method returns an undefined value.
35 36 37 |
# File 'lib/vedeu/distributed/server.rb', line 35 def restart instance.restart end |
.drb_start ⇒ void
This method returns an undefined value.
48 49 50 |
# File 'lib/vedeu/distributed/server.rb', line 48 def start instance.start end |
.drb_status ⇒ Symbol
55 56 57 |
# File 'lib/vedeu/distributed/server.rb', line 55 def status instance.status end |
.drb_stop ⇒ void
This method returns an undefined value.
62 63 64 |
# File 'lib/vedeu/distributed/server.rb', line 62 def stop instance.stop end |
.input(data, type = :key) ⇒ Object
20 21 22 |
# File 'lib/vedeu/distributed/server.rb', line 20 def input(data, type = :key) instance.input(data, type) end |
.output ⇒ void
This method returns an undefined value.
26 27 28 |
# File 'lib/vedeu/distributed/server.rb', line 26 def output instance.output end |
.restart ⇒ void
This method returns an undefined value.
32 33 34 |
# File 'lib/vedeu/distributed/server.rb', line 32 def restart instance.restart end |
.shutdown ⇒ void
This method returns an undefined value.
39 40 41 |
# File 'lib/vedeu/distributed/server.rb', line 39 def shutdown instance.shutdown end |
.start ⇒ void
This method returns an undefined value.
45 46 47 |
# File 'lib/vedeu/distributed/server.rb', line 45 def start instance.start end |
.status ⇒ Symbol
52 53 54 |
# File 'lib/vedeu/distributed/server.rb', line 52 def status instance.status end |
.stop ⇒ void
This method returns an undefined value.
59 60 61 |
# File 'lib/vedeu/distributed/server.rb', line 59 def stop instance.stop end |
Instance Method Details
#drb_running? ⇒ |NilClass (private)
202 203 204 |
# File 'lib/vedeu/distributed/server.rb', line 202 def drb_running? DRb.thread end |
#input(data, type = :keypress) ⇒ void Also known as: read
This method returns an undefined value.
72 73 74 |
# File 'lib/vedeu/distributed/server.rb', line 72 def input(data, type = :keypress) Vedeu.trigger(:_drb_input_, data, type) end |
#log(message) ⇒ void (private)
This method returns an undefined value.
207 208 209 |
# File 'lib/vedeu/distributed/server.rb', line 207 def log() Vedeu.log(type: :drb, message: "#{}: '#{uri}'") end |
#not_enabled ⇒ Symbol (private)
212 213 214 215 216 |
# File 'lib/vedeu/distributed/server.rb', line 212 def not_enabled log('Not enabled') :drb_not_enabled end |
#output ⇒ void Also known as: write
This method returns an undefined value.
78 79 80 |
# File 'lib/vedeu/distributed/server.rb', line 78 def output Vedeu.trigger(:_drb_retrieve_output_) end |
#pid ⇒ Fixnum
Returns The PID of the currently running application.
84 85 86 |
# File 'lib/vedeu/distributed/server.rb', line 84 def pid Process.pid end |
#restart ⇒ void
This method returns an undefined value.
Restart the DRb server.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vedeu/distributed/server.rb', line 91 def restart log('Attempting to restart') return not_enabled unless Vedeu::Configuration.drb? if drb_running? log('Restarting') stop start else log('Not running') start end 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.
119 120 121 122 123 124 125 126 127 |
# File 'lib/vedeu/distributed/server.rb', line 119 def shutdown return not_enabled unless Vedeu::Configuration.drb? stop if drb_running? Vedeu.trigger(:_exit_) Vedeu::Terminal.restore_screen end |
#start ⇒ Vedeu::Distributed::Server
Start the DRb server.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vedeu/distributed/server.rb', line 132 def start log('Attempting to start') return not_enabled unless Vedeu::Configuration.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.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/vedeu/distributed/server.rb', line 152 def status log('Fetching status') return not_enabled unless Vedeu::Configuration.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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/vedeu/distributed/server.rb', line 173 def stop log('Attempting to stop') return not_enabled unless Vedeu::Configuration.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 |
#uri ⇒ String (private)
219 220 221 222 |
# File 'lib/vedeu/distributed/server.rb', line 219 def uri Vedeu::Distributed::Uri.new(Vedeu::Configuration.drb_host, Vedeu::Configuration.drb_port).to_s end |