Class: Vedeu::Distributed::Server Private

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vedeu/distributed/server.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def configuration
  @configuration
end

Class Method Details

.drb_restartvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



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

def restart
  instance.restart
end

.drb_startvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



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

def start
  instance.start
end

.drb_statusSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)

See Also:



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

def status
  instance.status
end

.drb_stopvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



67
68
69
# File 'lib/vedeu/distributed/server.rb', line 67

def stop
  instance.stop
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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:



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

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

.outputvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



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

def output
  instance.output
end

.restartvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



37
38
39
# File 'lib/vedeu/distributed/server.rb', line 37

def restart
  instance.restart
end

.shutdownvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



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

def shutdown
  instance.shutdown
end

.startvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



50
51
52
# File 'lib/vedeu/distributed/server.rb', line 50

def start
  instance.start
end

.statusSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)

See Also:



57
58
59
# File 'lib/vedeu/distributed/server.rb', line 57

def status
  instance.status
end

.stopvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

See Also:



64
65
66
# File 'lib/vedeu/distributed/server.rb', line 64

def stop
  instance.stop
end

Instance Method Details

#drb_running?|NilClass (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (|NilClass)


218
219
220
# File 'lib/vedeu/distributed/server.rb', line 218

def drb_running?
  DRb.thread
end

#input(data, type = :keypress) ⇒ void Also known as: read

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



77
78
79
# File 'lib/vedeu/distributed/server.rb', line 77

def input(data, type = :keypress)
  Vedeu.trigger(:_drb_input_, data, type)
end

#log(message) ⇒ void (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



223
224
225
# File 'lib/vedeu/distributed/server.rb', line 223

def log(message)
  Vedeu.log(type: :drb, message: "#{message}: '#{uri}'")
end

#not_enabledSymbol (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


228
229
230
231
232
# File 'lib/vedeu/distributed/server.rb', line 228

def not_enabled
  log('Not enabled')

  :drb_not_enabled
end

#outputvoid Also known as: write

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



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

def output
  Vedeu.trigger(:_drb_retrieve_output_)
end

#pidFixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The PID of the currently running application.

Returns:

  • (Fixnum)

    The PID of the currently running application.



89
90
91
# File 'lib/vedeu/distributed/server.rb', line 89

def pid
  Process.pid
end

#restartvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Restart the DRb server.

Examples:

Vedeu.drb_restart


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/vedeu/distributed/server.rb', line 99

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

#shutdownvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



125
126
127
128
129
130
131
132
133
# File 'lib/vedeu/distributed/server.rb', line 125

def shutdown
  return not_enabled unless Vedeu.config.drb?

  stop if drb_running?

  Vedeu.trigger(:_exit_)

  Vedeu::Terminal.restore_screen
end

#startVedeu::Distributed::Server

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start the DRb server.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/vedeu/distributed/server.rb', line 141

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

#statusSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fetch the status of the DRb server.

Examples:

Vedeu.drb_status

Returns:

  • (Symbol)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/vedeu/distributed/server.rb', line 164

def status
  log('Fetching status')

  return not_enabled unless Vedeu.config.drb?

  if drb_running?
    log('Running')

    :running

  else
    log('Stopped')

    :stopped

  end
end

#stopvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Stop the DRb server.

Examples:

Vedeu.drb_stop


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/vedeu/distributed/server.rb', line 188

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

#uriString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


235
236
237
238
# File 'lib/vedeu/distributed/server.rb', line 235

def uri
  Vedeu::Distributed::Uri.new(Vedeu.config.drb_host,
                              Vedeu.config.drb_port).to_s
end