Class: Baykit::BayServer::Agent::CommandReceiver

Inherits:
Ships::Ship
  • Object
show all
Includes:
Baykit::BayServer, Monitor, Util
Defined in:
lib/baykit/bayserver/agent/command_receiver.rb

Overview

CommandReceiver receives commands from GrandAgentMonitor

Constant Summary

Constants inherited from Ships::Ship

Ships::Ship::INVALID_SHIP_ID, Ships::Ship::SHIP_ID_NOCHECK

Instance Attribute Summary

Attributes inherited from Ships::Ship

#agent_id, #initialized, #keeping, #object_id, #rudder, #ship_id, #transporter

Instance Method Summary collapse

Methods inherited from Ships::Ship

#check_ship_id, #id, #initialize, #post_close, #reset, #resume_read

Constructor Details

This class inherits a constructor from Baykit::BayServer::Ships::Ship

Instance Method Details

#check_timeout(duration_sec) ⇒ Object



60
61
62
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 60

def check_timeout(duration_sec)
  return false
end

#closeObject



122
123
124
125
126
127
128
129
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 122

def close
  if @closed
    return
  end

  @rudder.close
  @closed = true
end

#endObject



111
112
113
114
115
116
117
118
119
120
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 111

def end
  BayLog.debug("%s send end to monitor", self)
  begin
    send_command_to_monitor(nil, GrandAgent::CMD_CLOSE, true)
  rescue IOError => e
    BayLog.error_e(e)
  end

  close
end

#init(agt_id, rd, tp) ⇒ Object



18
19
20
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 18

def init(agt_id, rd, tp)
  super
end

#notify_closeObject



57
58
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 57

def notify_close
end

#notify_connectObject

Raises:



33
34
35
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 33

def notify_connect
  raise Sink.new
end

#notify_eofObject



44
45
46
47
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 44

def notify_eof
  BayLog.debug("%s notify_eof", self)
  return NextSocketAction::CLOSE
end

#notify_error(e) ⇒ Object



49
50
51
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 49

def notify_error(e)
  BayLog.error_e(e)
end

#notify_handshake_done(proto) ⇒ Object

Implements Ship

Raises:



29
30
31
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 29

def notify_handshake_done(proto)
  raise Sink.new
end

#notify_protocol_error(e) ⇒ Object

Raises:



53
54
55
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 53

def notify_protocol_error(e)
  raise Sink.new
end

#notify_read(buf) ⇒ Object



37
38
39
40
41
42
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 37

def notify_read(buf)
  BayLog.debug("%s notify_read", self)
  cmd = GrandAgentMonitor.buffer_to_int(buf)
  on_read_command(cmd)
  return NextSocketAction::CONTINUE
end

#on_read_command(cmd) ⇒ Object

Custom methods



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 67

def on_read_command(cmd)
  agt = GrandAgent.get(@agent_id)

  BayLog.debug("%s receive command %d rd=%s", self, cmd, @rudder)
  begin
    if cmd == nil
      BayLog.debug("%s pipe closed", self)
      agt.abort_agent
    else
      case cmd
      when GrandAgent::CMD_RELOAD_CERT
        agt.reload_cert
      when GrandAgent::CMD_MEM_USAGE
        agt.print_usage
      when GrandAgent::CMD_SHUTDOWN
        agt.req_shutdown
      when GrandAgent::CMD_ABORT
        send_command_to_monitor(agt, GrandAgent::CMD_OK, true)
        agt.abort_agent
        return
      when GrandAgent::CMD_CATCHUP
        agt.catch_up
        return
      else
        BayLog.error("Unknown command: %d", cmd)
      end

      send_command_to_monitor(agt, GrandAgent::CMD_OK, false)
    end
  rescue IOError => e
    BayLog.error_e(e, "%s Command thread aborted(end)", self)
    close
  ensure
    BayLog.debug("%s Command ended", self)
  end
end

#send_command_to_monitor(agt, cmd, sync) ⇒ Object



104
105
106
107
108
109
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 104

def send_command_to_monitor(agt, cmd, sync)
  buf = GrandAgentMonitor.int_to_buffer(cmd)
  if sync

  end
end

#to_sObject



22
23
24
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 22

def to_s()
  return "ComReceiver##{@agent_id}"
end