Class: CodinRep::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/codin_rep/command.rb
Defined Under Namespace
Classes: MalformedResponsePayload, UnknownHeader
Constant Summary
collapse
- COMMAND_PREFIX =
"PGREP".freeze
Instance Method Summary
collapse
Constructor Details
#initialize(host_address, tcp_port) ⇒ Command
Returns a new instance of Command.
50
51
52
53
54
|
# File 'lib/codin_rep/command.rb', line 50
def initialize(host_address, tcp_port)
@host_address = host_address
@tcp_port = tcp_port
@communication = Communication.new(@host_address, @tcp_port, get_timeout_time, get_max_attempts)
end
|
Instance Method Details
87
88
89
|
# File 'lib/codin_rep/command.rb', line 87
def
raise_not_implemented_error
end
|
#execute ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/codin_rep/command.rb', line 56
def execute
@command_data =
@command_data += generate_command_payload
@response = communicate!
@payload = get_response_payload
return get_data_from_response_payload
rescue
@communication.close
raise
ensure
@communication.close if should_close_connection?
end
|
#generate_command_payload ⇒ Object
83
84
85
|
# File 'lib/codin_rep/command.rb', line 83
def generate_command_payload
raise_not_implemented_error
end
|
78
79
80
81
|
# File 'lib/codin_rep/command.rb', line 78
def
COMMAND_PREFIX.dup + self.class::COMMAND_CODE.dup
end
|
#get_data_from_response_payload ⇒ Object
91
92
93
|
# File 'lib/codin_rep/command.rb', line 91
def get_data_from_response_payload
raise_not_implemented_error
end
|
#get_expected_response_size ⇒ Object
95
96
97
|
# File 'lib/codin_rep/command.rb', line 95
def get_expected_response_size
raise_not_implemented_error
end
|
#get_max_attempts ⇒ Object
74
75
76
|
# File 'lib/codin_rep/command.rb', line 74
def get_max_attempts
3
end
|
#get_timeout_time ⇒ Object
70
71
72
|
# File 'lib/codin_rep/command.rb', line 70
def get_timeout_time
3
end
|
#should_close_connection? ⇒ Boolean
99
100
101
|
# File 'lib/codin_rep/command.rb', line 99
def should_close_connection?
!!@response
end
|