Class: DRbQS::Node::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/node/connection.rb

Overview

The class of connection to server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, logger = DRbQS::Misc::LoggerDummy.new) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
12
# File 'lib/drbqs/node/connection.rb', line 7

def initialize(message, logger = DRbQS::Misc::LoggerDummy.new)
  @message = message
  @logger = logger
  @node_number = nil
  @id = create_id_string
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/drbqs/node/connection.rb', line 5

def id
  @id
end

#node_numberObject (readonly)

Returns the value of attribute node_number.



5
6
7
# File 'lib/drbqs/node/connection.rb', line 5

def node_number
  @node_number
end

Instance Method Details

#get_finalizationObject



41
42
43
# File 'lib/drbqs/node/connection.rb', line 41

def get_finalization
  get_special_task(:finalize)
end

#get_initializationObject



37
38
39
# File 'lib/drbqs/node/connection.rb', line 37

def get_initialization
  get_special_task(:initialize)
end

#respond_signalObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/drbqs/node/connection.rb', line 45

def respond_signal
  begin
    node_id, sym = @message.take([@node_number, Symbol], 0)
    @logger.info("Get signal: #{sym.inspect}")
    case sym
    when :alive_p
      @message.write([:server, :alive, @node_number])
      @logger.info("Send alive signal of node id #{@node_number}")
    when :exit, :finalize, :exit_after_task, :sleep, :wake
      return sym
    else
      raise "Get invalid signal: #{sym.inspect}"
    end
  rescue Rinda::RequestExpiredError
  end
end

#send_node_error(error_message) ⇒ Object



62
63
64
# File 'lib/drbqs/node/connection.rb', line 62

def send_node_error(error_message)
  @message.write([:server, :node_error, [@node_number, error_message]])
end