packet 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ # class implements general worker
2
+ module Packet
3
+ class Worker
4
+ include Core
5
+ iattr_accessor :fd_reader,:msg_writer,:msg_reader,:worker_name
6
+ iattr_accessor :worker_proxy
7
+ iattr_accessor :no_auto_load
8
+ attr_accessor :worker_started, :worker_options
9
+ after_connection :provide_workers
10
+
11
+ # method initializes the eventloop for the worker
12
+ def self.start_worker(messengers = {})
13
+ # @fd_reader = args.shift if args.length > 2
14
+ @msg_writer = messengers[:write_end]
15
+ @msg_reader = messengers[:read_end]
16
+ @fd_reader = messengers[:read_fd]
17
+ t_instance = new
18
+ t_instance.worker_options = messengers[:options]
19
+ t_instance.worker_init if t_instance.respond_to?(:worker_init)
20
+ t_instance.start_reactor
21
+ end
22
+
23
+ def initialize
24
+ super
25
+ @read_ios << msg_reader
26
+ @read_ios << fd_reader
27
+ @tokenizer = BinParser.new
28
+ end
29
+
30
+ def send_data p_data
31
+ dump_object(p_data,msg_writer)
32
+ end
33
+
34
+ def send_request(options = {})
35
+ t_data = options[:data]
36
+ if t_callback = options[:callback]
37
+ callback_hash[t_callback.signature] = t_callback
38
+ send_data(:data => t_data,:function => options[:function],:callback_signature => t_callback.signature)
39
+ else
40
+ send_data(:data => t_data,:function => options[:function],:requested_worker => options[:worker],:requesting_worker => worker_name,:type => :request)
41
+ end
42
+ end
43
+
44
+ # method handles internal requests from internal sockets
45
+ def handle_internal_messages(t_sock)
46
+ t_data = read_data(t_sock)
47
+ receive_internal_data(t_data)
48
+ end
49
+
50
+ def receive_internal_data data
51
+ @tokenizer.extract(data) do |b_data|
52
+ data_obj = Marshal.load(b_data)
53
+ receive_data(data_obj)
54
+ end
55
+ end
56
+
57
+ # FIXME: this method is being duplicated between packet and worker classes, may be its a
58
+ # good idea to merge them.
59
+ def provide_workers(handler_instance,connection)
60
+ class << handler_instance
61
+ extend Forwardable
62
+ attr_accessor :worker, :connection, :reactor, :initialized, :signature
63
+ include NbioHelper
64
+ def send_data p_data
65
+ begin
66
+ write_data(p_data,connection)
67
+ rescue Errno::EPIPE
68
+ # probably a callback
69
+ end
70
+ end
71
+
72
+ def invoke_init
73
+ @initialized = true
74
+ post_init
75
+ end
76
+
77
+ def close_connection
78
+ unbind
79
+ reactor.remove_connection(connection)
80
+ end
81
+
82
+ def close_connection_after_writing
83
+ connection.flush
84
+ unbind
85
+ reactor.remove_connection(connection)
86
+ end
87
+
88
+ def send_object p_object
89
+ dump_object(p_object,connection)
90
+ end
91
+
92
+ def_delegators :@reactor, :start_server, :connect, :add_periodic_timer, :add_timer, :cancel_timer,:reconnect
93
+ end
94
+ handler_instance.connection = connection
95
+ handler_instance.worker = self
96
+ handler_instance.reactor = self
97
+ end
98
+
99
+ def log log_data
100
+ send_data(:requested_worker => :log_worker,:data => log_data,:type => :request)
101
+ end
102
+
103
+ # method receives data from external TCP Sockets
104
+ def receive_data p_data
105
+ raise "Not implemented for worker"
106
+ end
107
+
108
+ # method checks if client has asked to execute a internal function
109
+ def invoke_internal_function
110
+ raise "Not implemented for worker"
111
+ end
112
+
113
+ # message returns data to parent process, using UNIX Sockets
114
+ def invoke_callback
115
+ raise "Not implemented for worker"
116
+ end
117
+
118
+ end # end of class#Worker
119
+ end
120
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: packet
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-11-21 00:00:00 +05:30
8
+ summary: Packet, Events... we got em.
9
+ require_paths:
10
+ - lib
11
+ email: foo@bar.com
12
+ homepage: http://code.google.com/p/packet/
13
+ rubyforge_project:
14
+ description: Packet, Events... we got em.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.4
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Hemant
31
+ files:
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - TODO
36
+ - bin/packet_mongrel.rb
37
+ - bin/runner.rb
38
+ - lib/buftok.rb
39
+ - lib/io_worker.rb
40
+ - lib/disconnect_error.rb
41
+ - lib/event.rb
42
+ - lib/packet_mongrel.rb
43
+ - lib/meta_pimp.rb
44
+ - lib/pimp.rb
45
+ - lib/packet.rb
46
+ - lib/bin_parser.rb
47
+ - lib/packet_guid.rb
48
+ - lib/core.rb
49
+ - lib/periodic_event.rb
50
+ - lib/connection.rb
51
+ - lib/worker.rb
52
+ - lib/deferrable.rb
53
+ - lib/nbio.rb
54
+ - lib/ruby_hacks.rb
55
+ - lib/packet_master.rb
56
+ - lib/cpu_worker.rb
57
+ - lib/double_keyed_hash.rb
58
+ - lib/attribute_accessors.rb
59
+ - lib/callback.rb
60
+ test_files: []
61
+
62
+ rdoc_options: []
63
+
64
+ extra_rdoc_files:
65
+ - README
66
+ - LICENSE
67
+ - TODO
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ requirements: []
73
+
74
+ dependencies: []
75
+