Class: ASIR::Transport::File
- Inherits:
-
Stream
- Object
- ASIR::Transport
- Stream
- ASIR::Transport::File
- Includes:
- PayloadIO
- Defined in:
- lib/asir/transport/file.rb
Overview
!SLIDE File Transport
Send Message one-way to a file. Can be used as a log or named pipe service.
Constant Summary
Constants included from PayloadIO
PayloadIO::FOOTER, PayloadIO::HEADER
Constants included from ASIR::ThreadVariable
ASIR::ThreadVariable::DEBUG, ASIR::ThreadVariable::EMPTY_HASH, ASIR::ThreadVariable::SETTER
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#perms ⇒ Object
Returns the value of attribute perms.
-
#stream ⇒ Object
!SLIDE File Transport Support.
Attributes inherited from ASIR::Transport
#after_invoke_message, #after_receive_message, #before_send_message, #coder_needs_result_message, #decoder, #encoder, #invoker, #message_count, #needs_message_identifier, #needs_message_timestamp, #on_exception, #on_result_exception, #one_way, #running, #verbose
Attributes included from Log
Instance Method Summary collapse
-
#_receive_message(state) ⇒ Object
Returns a Message payload String.
-
#_receive_result(state) ⇒ Object
one-way; no Result.
-
#_send_message(state) ⇒ Object
Writes a Message payload String.
-
#_send_result(state) ⇒ Object
one-way; no Result.
-
#initialize(opts = nil) ⇒ File
constructor
A new instance of File.
-
#prepare_server! ⇒ Object
(also: #prepare_pipe_server!)
!SLIDE Named Pipe Server.
- #run_server! ⇒ Object (also: #run_pipe_server!)
-
#serve_file! ⇒ Object
!SLIDE Process (receive) messages from a file.
Methods included from PayloadIO
#_read, #_read_line_and_expect!, #_write, #close
Methods inherited from Stream
#_serve_stream!, #serve_stream!, #serve_stream_message!, #stream_eof?
Methods inherited from ASIR::Transport
#_subclass_responsibility, #invoke_message!, #needs_message_identifier?, #needs_message_timestamp?, #receive_message, #receive_result, #send_message, #send_result, #serve_message!, #stop!, #with_server_signals!
Methods included from Log
#_log, #_log_enabled=, #_log_enabled?, #_log_format, #_log_result, enabled, enabled=, included
Methods included from AdditionalData
#[], #[]=, #_additional_data, #additional_data, #additional_data!, #additional_data=, included
Methods included from Message::Delay
#relative_message_delay!, #wait_for_delay!
Methods included from ASIR::ThreadVariable
Constructor Details
#initialize(opts = nil) ⇒ File
Returns a new instance of File.
15 |
# File 'lib/asir/transport/file.rb', line 15 def initialize opts = nil; @one_way = true; super; end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
13 14 15 |
# File 'lib/asir/transport/file.rb', line 13 def file @file end |
#mode ⇒ Object
Returns the value of attribute mode.
13 14 15 |
# File 'lib/asir/transport/file.rb', line 13 def mode @mode end |
#perms ⇒ Object
Returns the value of attribute perms.
13 14 15 |
# File 'lib/asir/transport/file.rb', line 13 def perms @perms end |
#stream ⇒ Object
!SLIDE File Transport Support
42 43 44 |
# File 'lib/asir/transport/file.rb', line 42 def stream @stream end |
Instance Method Details
#_receive_message(state) ⇒ Object
Returns a Message payload String.
25 26 27 |
# File 'lib/asir/transport/file.rb', line 25 def state state. = _read(state.in_stream || stream, state) end |
#_receive_result(state) ⇒ Object
one-way; no Result.
35 36 37 |
# File 'lib/asir/transport/file.rb', line 35 def _receive_result state nil end |
#_send_message(state) ⇒ Object
Writes a Message payload String.
18 19 20 21 22 |
# File 'lib/asir/transport/file.rb', line 18 def state _write(state., state.out_stream || stream, state) ensure close if file && ::File.pipe?(file) end |
#_send_result(state) ⇒ Object
one-way; no Result.
30 31 32 |
# File 'lib/asir/transport/file.rb', line 30 def _send_result state nil end |
#prepare_server! ⇒ Object Also known as: prepare_pipe_server!
!SLIDE Named Pipe Server
65 66 67 68 69 70 |
# File 'lib/asir/transport/file.rb', line 65 def prepare_server! unless ::File.exist? file system(cmd = "mkfifo #{file.inspect}") or raise "cannot run #{cmd.inspect}" ::File.chmod(perms, file) rescue nil if perms end end |
#run_server! ⇒ Object Also known as: run_pipe_server!
73 74 75 76 77 78 79 80 |
# File 'lib/asir/transport/file.rb', line 73 def run_server! with_server_signals! do @running = true while @running serve_file! end end end |
#serve_file! ⇒ Object
!SLIDE Process (receive) messages from a file.
55 56 57 58 59 60 |
# File 'lib/asir/transport/file.rb', line 55 def serve_file! ::File.open(file, "r") do | stream | @running = true _serve_stream! stream, nil # One-way: no result stream. end end |