Class: Packet::Worker
- Inherits:
-
Object
- Object
- Packet::Worker
- Includes:
- Core
- Defined in:
- lib/packet/packet_worker.rb
Instance Attribute Summary collapse
-
#worker_options ⇒ Object
Returns the value of attribute worker_options.
-
#worker_started ⇒ Object
Returns the value of attribute worker_started.
Class Method Summary collapse
-
.inherited(subklass) ⇒ Object
copy the inherited attribute in class thats inheriting this class.
- .is_worker? ⇒ Boolean
-
.start_worker(messengers = {}) ⇒ Object
method initializes the eventloop for the worker.
Instance Method Summary collapse
-
#handle_internal_messages(t_sock) ⇒ Object
method handles internal requests from internal sockets.
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
-
#invoke_callback ⇒ Object
message returns data to parent process, using UNIX Sockets.
-
#invoke_internal_function ⇒ Object
method checks if client has asked to execute a internal function.
- #log(log_data) ⇒ Object
-
#receive_data(p_data) ⇒ Object
method receives data from external TCP Sockets.
- #receive_internal_data(data) ⇒ Object
- #send_data(p_data) ⇒ Object
- #send_request(options = {}) ⇒ Object
Methods included from Core
Constructor Details
Instance Attribute Details
#worker_options ⇒ Object
Returns the value of attribute worker_options.
9 10 11 |
# File 'lib/packet/packet_worker.rb', line 9 def @worker_options end |
#worker_started ⇒ Object
Returns the value of attribute worker_started.
9 10 11 |
# File 'lib/packet/packet_worker.rb', line 9 def worker_started @worker_started end |
Class Method Details
.inherited(subklass) ⇒ Object
copy the inherited attribute in class thats inheriting this class
25 26 27 |
# File 'lib/packet/packet_worker.rb', line 25 def self.inherited(subklass) subklass.send(:"connection_callbacks=",connection_callbacks) end |
.is_worker? ⇒ Boolean
29 |
# File 'lib/packet/packet_worker.rb', line 29 def self.is_worker?; true; end |
.start_worker(messengers = {}) ⇒ Object
method initializes the eventloop for the worker
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/packet/packet_worker.rb', line 12 def self.start_worker(messengers = {}) # @fd_reader = args.shift if args.length > 2 @msg_writer = messengers[:write_end] @msg_reader = messengers[:read_end] t_instance = new t_instance. = messengers[:options] t_instance.worker_init if t_instance.respond_to?(:worker_init) t_instance.start_reactor t_instance end |
Instance Method Details
#handle_internal_messages(t_sock) ⇒ Object
method handles internal requests from internal sockets
52 53 54 55 56 57 58 59 60 |
# File 'lib/packet/packet_worker.rb', line 52 def (t_sock) begin t_data = read_data(t_sock) receive_internal_data(t_data) rescue DisconnectError => sock_error # Means, when there is an error from sockets from which we are reading better just terminate terminate_me() end end |
#invoke_callback ⇒ Object
message returns data to parent process, using UNIX Sockets
84 85 86 |
# File 'lib/packet/packet_worker.rb', line 84 def invoke_callback raise "Not implemented for worker" end |
#invoke_internal_function ⇒ Object
method checks if client has asked to execute a internal function
79 80 81 |
# File 'lib/packet/packet_worker.rb', line 79 def invoke_internal_function raise "Not implemented for worker" end |
#log(log_data) ⇒ Object
69 70 71 |
# File 'lib/packet/packet_worker.rb', line 69 def log log_data send_data(:requested_worker => :log_worker,:data => log_data,:type => :request) end |
#receive_data(p_data) ⇒ Object
method receives data from external TCP Sockets
74 75 76 |
# File 'lib/packet/packet_worker.rb', line 74 def receive_data p_data raise "Not implemented for worker" end |
#receive_internal_data(data) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/packet/packet_worker.rb', line 62 def receive_internal_data data @tokenizer.extract(data) do |b_data| data_obj = Marshal.load(b_data) receive_data(data_obj) end end |
#send_data(p_data) ⇒ Object
37 38 39 |
# File 'lib/packet/packet_worker.rb', line 37 def send_data p_data dump_object(p_data,msg_writer) end |
#send_request(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/packet/packet_worker.rb', line 41 def send_request( = {}) t_data = [:data] if t_callback = [:callback] callback_hash[t_callback.signature] = t_callback send_data(:data => t_data,:function => [:function],:callback_signature => t_callback.signature) else send_data(:data => t_data,:function => [:function],:requested_worker => [:worker],:requesting_worker => worker_name,:type => :request) end end |