Class: Vedeu::Distributed::Client Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/distributed/client.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 client side of the DRb server/client relationship.

Examples:

client = Vedeu::Distributed::Client.
           connect("druby://localhost:21420")
client.input('a')
client.output # => 'some content...'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Vedeu::Distributed::Client

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 a new instance of Vedeu::Distributed::Client.

Parameters:



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

def initialize(uri)
  @uri = uri.to_s
end

Instance Attribute Details

#uriString (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.

Returns:

  • (String)


103
104
105
# File 'lib/vedeu/distributed/client.rb', line 103

def uri
  @uri
end

Class Method Details

.connect(uri) ⇒ 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:



24
25
26
# File 'lib/vedeu/distributed/client.rb', line 24

def self.connect(uri)
  new(uri).connect
end

Instance Method Details

#connectSymbol

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.

Simulate connecting to the DRb server by requesting its status.

Returns:

  • (Symbol)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vedeu/distributed/client.rb', line 40

def connect
  server.status

rescue DRb::DRbConnError
  drb_connection_error

rescue DRb::DRbBadURI
  Vedeu.log_stdout(message: 'Could not connect to DRb server, URI may ' \
                            'be bad.')

  :drb_bad_uri
end

#drb_connection_errorSymbol (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)


113
114
115
116
117
# File 'lib/vedeu/distributed/client.rb', line 113

def drb_connection_error
  Vedeu.log_stdout(message: 'Could not connect to DRb server.')

  :drb_connection_error
end

#input(data) ⇒ void|Symbol 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.

Send input to the DRb server.

Parameters:

  • data (String|Symbol)

Returns:

  • (void|Symbol)


57
58
59
60
61
62
# File 'lib/vedeu/distributed/client.rb', line 57

def input(data)
  server.input(data)

rescue DRb::DRbConnError
  drb_connection_error
end

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

Fetch output from the DRb server.

Returns:

  • (void|Symbol)


68
69
70
71
72
73
# File 'lib/vedeu/distributed/client.rb', line 68

def output
  server.output

rescue DRb::DRbConnError
  drb_connection_error
end

#servervoid (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.



108
109
110
# File 'lib/vedeu/distributed/client.rb', line 108

def server
  @server ||= DRbObject.new_with_uri(uri)
end

#shutdownvoid|Symbol

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:

Runtime::Application will raise StopIteration when its ‘.stop` method is called. Here we rescue that to give a clean client exit.

Shutdown the DRb server and the client application.

Returns:

  • (void|Symbol)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vedeu/distributed/client.rb', line 84

def shutdown
  server.shutdown

  Process.kill('KILL', server.pid)

rescue DRb::DRbConnError
  drb_connection_error

rescue Interrupt
  Vedeu.log_stdout(message: 'Client application exited.')

ensure
  :shutdown
end