Class: Vedeu::Distributed::Server

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configurationVedeu::Configuration (readonly, protected)



197
198
199
# File 'lib/vedeu/distributed/server.rb', line 197

def configuration
  @configuration
end

Class Method Details

.drb_restartvoid

This method returns an undefined value.

See Also:



35
36
37
# File 'lib/vedeu/distributed/server.rb', line 35

def restart
  instance.restart
end

.drb_startvoid

This method returns an undefined value.

See Also:



48
49
50
# File 'lib/vedeu/distributed/server.rb', line 48

def start
  instance.start
end

.drb_statusSymbol

Returns:

  • (Symbol)

See Also:



55
56
57
# File 'lib/vedeu/distributed/server.rb', line 55

def status
  instance.status
end

.drb_stopvoid

This method returns an undefined value.

See Also:



62
63
64
# File 'lib/vedeu/distributed/server.rb', line 62

def stop
  instance.stop
end

.input(data, type = :key) ⇒ Object

Parameters:

  • data (String|Symbol)

    The input to send to Vedeu.

  • type (Symbol) (defaults to: :key)

    Either :command or :keypress. Will trigger the respective capture mode within Input::Input, or if not given, will treat the data as a keypress.

See Also:



20
21
22
# File 'lib/vedeu/distributed/server.rb', line 20

def input(data, type = :key)
  instance.input(data, type)
end

.outputvoid

This method returns an undefined value.

See Also:



26
27
28
# File 'lib/vedeu/distributed/server.rb', line 26

def output
  instance.output
end

.restartvoid

This method returns an undefined value.

See Also:



32
33
34
# File 'lib/vedeu/distributed/server.rb', line 32

def restart
  instance.restart
end

.shutdownvoid

This method returns an undefined value.

See Also:



39
40
41
# File 'lib/vedeu/distributed/server.rb', line 39

def shutdown
  instance.shutdown
end

.startvoid

This method returns an undefined value.

See Also:



45
46
47
# File 'lib/vedeu/distributed/server.rb', line 45

def start
  instance.start
end

.statusSymbol

Returns:

  • (Symbol)

See Also:



52
53
54
# File 'lib/vedeu/distributed/server.rb', line 52

def status
  instance.status
end

.stopvoid

This method returns an undefined value.

See Also:



59
60
61
# File 'lib/vedeu/distributed/server.rb', line 59

def stop
  instance.stop
end

Instance Method Details

#drb_running?|NilClass (private)

Returns:

  • (|NilClass)


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.

Parameters:

  • data (String|Symbol)

    The input to send to Vedeu.

  • type (Symbol) (defaults to: :keypress)

    Either :command or :keypress. Will trigger the respective capture mode within Input::Input, or if not given, will treat the data as a keypress.



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(message)
  Vedeu.log(type: :drb, message: "#{message}: '#{uri}'")
end

#not_enabledSymbol (private)

Returns:

  • (Symbol)


212
213
214
215
216
# File 'lib/vedeu/distributed/server.rb', line 212

def not_enabled
  log('Not enabled')

  :drb_not_enabled
end

#outputvoid 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

#pidFixnum

Returns The PID of the currently running application.

Returns:

  • (Fixnum)

    The PID of the currently running application.



84
85
86
# File 'lib/vedeu/distributed/server.rb', line 84

def pid
  Process.pid
end

#restartvoid

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

#shutdownvoid

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.



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

#startVedeu::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

#statusSymbol

Fetch the status of the DRb server.

Returns:

  • (Symbol)


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

#stopvoid

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

#uriString (private)

Returns:

  • (String)


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