langrove 0.0.4.4 → 0.0.4.5

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.
@@ -4,9 +4,9 @@
4
4
  :protocol:
5
5
  :class: SocketToFile
6
6
  :adaptor:
7
- :connection: Datagram
8
7
  :iface: 127.0.0.1
9
8
  :port: 12701
9
+ :transport: udp
10
10
  :client:
11
11
  :class: SocketToFile
12
12
  :handler:
@@ -10,6 +10,7 @@ module Client; end
10
10
  module Daemon; end
11
11
  module Handler; end
12
12
  module Protocol; end
13
+ module Job; end
13
14
 
14
15
  module LanGrove
15
16
 
@@ -24,3 +25,4 @@ require 'langrove/adaptor/base'
24
25
  require 'langrove/handler/base'
25
26
  require 'langrove/protocol/base'
26
27
  require 'langrove/client/base'
28
+ require 'langrove/job/base'
@@ -1,3 +1,2 @@
1
1
  module LanGrove::Adaptor; end
2
2
  require 'langrove/adaptor_base'
3
- require 'langrove/adaptor/datagram'
@@ -10,26 +10,104 @@ module LanGrove::Adaptor
10
10
 
11
11
  @config = config
12
12
  @logger = logger
13
-
13
+
14
+ @transport = :tcp
14
15
  @iface = '127.0.0.1'
15
16
  @port = 12701
16
17
 
17
- @iface = @config[ :iface ] if @config.has_key? :iface
18
- @port = @config[ :port ] if @config.has_key? :port
18
+ @iface = @config[ :iface ] if @config.has_key? :iface
19
+ @port = @config[ :port ] if @config.has_key? :port
20
+ @transport = @config[ :transport ].to_sym if @config.has_key? :transport
19
21
 
20
- if @config.has_key? :connector then
22
+ #
23
+ # Assign the call signature for the EventMachine server
24
+ #
25
+ @em_server_call = case @transport
21
26
 
22
- #
23
- # TODO: may need to override default connection handler
24
- #
27
+ when :tcp
28
+
29
+ :start_server
30
+
31
+ when :udp
32
+
33
+ :open_datagram_socket
34
+
35
+ else
36
+
37
+ :start_server
25
38
 
26
39
  end
27
40
 
28
41
  end
29
42
 
30
43
  def listen( client, protocol, handler )
44
+
45
+ #
46
+ # <client> = {
47
+ #
48
+ # :class => <loaded class constant>
49
+ # :config => <client's branch of config>
50
+ #
51
+ # }
52
+ #
53
+ # <protocol> = { ...the same, but protocolic }
54
+ #
55
+ #
31
56
 
32
- raise LanGrove::DaemonConfigException.new( "NotYetExtended: undefined listen()" )
57
+ @logger.info "starting listen at UDP #{@iface}:#{@port}"
58
+
59
+ EventMachine::send( @em_server_call, @iface, @port,
60
+
61
+ client[:class] ) do | client_connected |
62
+
63
+ #
64
+ # @em_server_call as:
65
+ #
66
+ # udp - EM::open_datagram_socket, yields an instance of
67
+ # client[:class] into here on bind to the port
68
+ #
69
+ # ie. at starting to listen
70
+ #
71
+ # unverified: ? If more than 1 datagram source is
72
+ # transmitting to here - will there still
73
+ # still be only ONE EM:Connection instance?
74
+ #
75
+ # tcp - EM::start_server yields an new instance of client[:class]
76
+ # with every connecting socket pair.
77
+ #
78
+ # ie. On socket pair binding - so each remote client will
79
+ # have it's own associated instance of a client[:class]
80
+ # running in the machine.
81
+ #
82
+
83
+
84
+ #
85
+ # Initialize the client with the (application layer) Protocol
86
+ #
87
+
88
+ client_connected.logger = @logger
89
+
90
+ client_connected.config = client[ :config ]
91
+
92
+ client_connected.protocol = protocol[ :class ]\
93
+
94
+ .new( protocol[ :config ], @logger )
95
+
96
+ @logger.info( "TODO: make a reference to the Client on the Handler" )
97
+
98
+ #
99
+ # Bi-Directionally bind the Client and Handler
100
+ #
101
+ handler.connect( client_connected )
102
+ client_connected.handler = handler
103
+
104
+ #
105
+ # Client is ready and running inside the reactor
106
+ #
107
+ # EM::start_server will yield again on the next connect.
108
+ #
109
+
110
+ end
33
111
 
34
112
  end
35
113
 
@@ -64,9 +64,25 @@ module LanGrove
64
64
  end
65
65
 
66
66
  def receive_data( data )
67
-
67
+
68
+ #
69
+ # Event machine writes into here at receiving data
70
+ # from the client.
71
+ #
72
+
68
73
  receive( @protocol.decode( data ) )
69
74
 
75
+ #
76
+ # ?Multi-message protocol?
77
+ #
78
+ # @protocol.accumulate( multi_message_part, self )
79
+ #
80
+ # ---- With protocol responding directly to source
81
+ #
82
+ # ---- With protocol then calling receive_decoded()
83
+ # via the self being passed in.
84
+ #
85
+
70
86
  end
71
87
 
72
88
  end
@@ -130,9 +130,20 @@ module LanGrove::Daemon class Base
130
130
 
131
131
  @server = @my_config[ :server ] if @my_config.has_key? :server
132
132
 
133
- @logger.info "TODO: fall back to default Adaptor::Base"
134
133
 
135
- adaptor = @my_config[ :adaptor ][ :connection ]
134
+
135
+ if @my_config[ :adaptor ].has_key? :class
136
+
137
+ adaptor = @my_config[ :adaptor ][ :class ]
138
+
139
+ else
140
+
141
+ @logger.warn( "Defaulting to Adaptor::Base" )
142
+ adaptor = 'Base'
143
+
144
+ end
145
+
146
+
136
147
 
137
148
  @logger.info "TODO: fall back to default Handler::Base"
138
149
 
@@ -165,7 +176,10 @@ module LanGrove::Daemon class Base
165
176
  # daemons:
166
177
  # name_of_daemon:
167
178
  # adaptor:
168
- # connection: TcpServer <----------
179
+ # class: MySocket <----------( optional )
180
+ # transport: tcp|udp
181
+ # iface: N.N.n.n
182
+ # port: nNn
169
183
  # handler:
170
184
  # collection: CollectionOfClients
171
185
  #
@@ -0,0 +1 @@
1
+ require 'langrove/job_base'
@@ -0,0 +1,24 @@
1
+ #
2
+ # no spec
3
+ #
4
+ module LanGrove
5
+
6
+ module Job
7
+
8
+ class Base
9
+
10
+ def initialize( config, queue_name, logger)
11
+
12
+ logger.info ( "starting unimplemented queuer") unless logger.nil?
13
+
14
+ end
15
+
16
+ def method_missing( symbol, *args, &block )
17
+ puts "#{self}.#{symbol}( #{args} )" unless @parameter == :silent
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -1,3 +1,3 @@
1
1
  module LanGrove
2
- Version = VERSION = '0.0.4.4'
2
+ Version = VERSION = '0.0.4.5'
3
3
  end
@@ -16,15 +16,30 @@ describe LanGrove::Adaptor::Base do
16
16
 
17
17
  :connector => @extendhandler,
18
18
 
19
- :client => {
20
-
21
- :class => 'Base'
22
-
23
- }
19
+ :transport => 'udp'
24
20
  }
25
21
 
26
22
  end
27
23
 
24
+
25
+
26
+ it 'assigns the session layer protocol as udp' do
27
+
28
+ subject = LanGrove::Adaptor::Base.new( @config, @logger )
29
+ subject.instance_variable_get( :@em_server_call ).should == :open_datagram_socket
30
+
31
+ end
32
+
33
+ it 'assigns the session layer protocol as tcp by default' do
34
+
35
+ @config.delete :transport
36
+
37
+ subject = LanGrove::Adaptor::Base.new( @config, @logger )
38
+
39
+ subject.instance_variable_get( :@em_server_call ).should == :start_server
40
+
41
+ end
42
+
28
43
  pending 'may need to override default connection handler' do
29
44
 
30
45
  LanGrove::Adaptor.const_set( @extendhandler, Class.new )
@@ -32,7 +47,7 @@ describe LanGrove::Adaptor::Base do
32
47
  subject = LanGrove::Adaptor::Base.new( @config, @logger )
33
48
  connector = subject.instance_variable_get( :@handler )
34
49
 
35
- connector.should be_a( LanGrove::Adaptor.const_get( @extendhandler ) )
50
+ connector.should == LanGrove::Adaptor.const_get( @extendhandler )
36
51
 
37
52
  end
38
53
 
@@ -4,11 +4,11 @@ describe LanGrove::Daemon::Base do
4
4
 
5
5
  before :each do
6
6
 
7
- @logger = LanGrove::FakeLogger.new :silent
7
+ @logger = LanGrove::FakeLogger.new :silent
8
8
 
9
9
  @daemon_name = 'pretend_daemon'
10
10
 
11
- @adaptor_class = 'Base'
11
+ @adaptor_class = 'MyEventMachineServer'
12
12
  @collection_class = 'Base'
13
13
  @client_class = 'Base'
14
14
  @protocol_class = 'Base'
@@ -23,7 +23,7 @@ describe LanGrove::Daemon::Base do
23
23
 
24
24
  :adaptor => {
25
25
 
26
- :connection => @adaptor_class
26
+ # Test default
27
27
 
28
28
  },
29
29
 
@@ -62,7 +62,11 @@ describe LanGrove::Daemon::Base do
62
62
 
63
63
  LanGrove::Daemon::Base.new( @config, @daemon_name, nil )
64
64
 
65
- }.to raise_error( LanGrove::DaemonConfigException, /Requires a logger/ )
65
+ }.to raise_error( LanGrove::DaemonConfigException,
66
+
67
+ /Requires a logger/
68
+
69
+ )
66
70
 
67
71
  end
68
72
 
@@ -72,15 +76,36 @@ describe LanGrove::Daemon::Base do
72
76
 
73
77
  LanGrove::Daemon::Base.new( {}, @daemon_name, @logger )
74
78
 
75
- }.to raise_error( LanGrove::DaemonConfigException, /Missing config item/ )
79
+ }.to raise_error( LanGrove::DaemonConfigException,
80
+
81
+ /Missing config item/
82
+
83
+ )
76
84
 
77
85
  end
78
86
 
79
- it 'latebinds an adaptor by config' do
87
+ it 'attempts to latebind an adaptor by config' do
88
+
89
+ @config[ :daemons ][ @daemon_name ][ :adaptor ][ :class ] = @adaptor_class
90
+
91
+ expect {
92
+
93
+ LanGrove::Daemon::Base.new( @config, @daemon_name, @logger )
94
+
95
+ }.to raise_error( LanGrove::ClassLoaderException,
96
+
97
+
98
+ "no such file to load -- adaptor/my_event_machine_server.rb"
99
+
100
+ )
101
+
102
+ end
103
+
104
+ it 'defaults to Adaptor::Base' do
80
105
 
81
- adaptor = subject.instance_variable_get( :@adaptor )
82
106
 
83
- adaptor.should be_a( LanGrove::Adaptor.const_get( @adaptor_class ) )
107
+ adaptor = subject.instance_variable_get( :@adaptor )
108
+ adaptor.should be_a( LanGrove::Adaptor::Base )
84
109
 
85
110
  end
86
111
 
@@ -125,17 +150,5 @@ describe LanGrove::Daemon::Base do
125
150
  end
126
151
 
127
152
  it 'it schedules periodics'
128
-
129
- it 'when run, it calls to listen if server is true' do
130
-
131
- expect {
132
-
133
- subject.instance_variable_set( :@server, true )
134
-
135
- subject.run
136
-
137
- }.to raise_error( LanGrove::DaemonConfigException, "NotYetExtended: undefined listen()" )
138
-
139
- end
140
153
 
141
154
  end
@@ -0,0 +1,28 @@
1
+ require 'langrove'
2
+
3
+ describe LanGrove::Job::Base do
4
+
5
+ before :each do
6
+
7
+ @logger = LanGrove::FakeLogger.new
8
+
9
+ @queue_name = :snooker_queue
10
+
11
+ @config = {}
12
+
13
+ end
14
+
15
+ it 'initializes' do
16
+
17
+ test = LanGrove::Job::Base.new( @config, @queue_name, @logger )
18
+ test.should be_a( LanGrove::Job::Base )
19
+
20
+ end
21
+
22
+ it 'has methods' do
23
+
24
+ LanGrove::Job::Base.new( @config, @queue_name, @logger ).undefined_method( "TEST" )
25
+
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langrove
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.4
4
+ version: 0.0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,7 @@ date: 2012-04-24 00:00:00.000000000Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: watchr
19
- requirement: &2153525920 !ruby/object:Gem::Requirement
19
+ requirement: &70148317913640 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0'
25
25
  type: :development
26
26
  prerelease: false
27
- version_requirements: *2153525920
27
+ version_requirements: *70148317913640
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
- requirement: &2153525420 !ruby/object:Gem::Requirement
30
+ requirement: &70148317912900 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '2.9'
36
36
  type: :development
37
37
  prerelease: false
38
- version_requirements: *2153525420
38
+ version_requirements: *70148317912900
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rake
41
- requirement: &2153524900 !ruby/object:Gem::Requirement
41
+ requirement: &70148317912160 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: 0.8.7
50
50
  type: :development
51
51
  prerelease: false
52
- version_requirements: *2153524900
52
+ version_requirements: *70148317912160
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: eventmachine
55
- requirement: &2153524160 !ruby/object:Gem::Requirement
55
+ requirement: &70148317911420 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -63,10 +63,10 @@ dependencies:
63
63
  version: 0.12.10
64
64
  type: :runtime
65
65
  prerelease: false
66
- version_requirements: *2153524160
66
+ version_requirements: *70148317911420
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: em-http-request
69
- requirement: &2153523420 !ruby/object:Gem::Requirement
69
+ requirement: &70148317910660 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
72
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.3.0
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *2153523420
80
+ version_requirements: *70148317910660
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: daemon-kit
83
- requirement: &2153522680 !ruby/object:Gem::Requirement
83
+ requirement: &70148317909900 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -91,10 +91,10 @@ dependencies:
91
91
  version: 0.1.8.2
92
92
  type: :runtime
93
93
  prerelease: false
94
- version_requirements: *2153522680
94
+ version_requirements: *70148317909900
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: resque
97
- requirement: &2153521940 !ruby/object:Gem::Requirement
97
+ requirement: &70148317909160 !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
100
100
  - - ~>
@@ -105,7 +105,7 @@ dependencies:
105
105
  version: 1.20.0
106
106
  type: :runtime
107
107
  prerelease: false
108
- version_requirements: *2153521940
108
+ version_requirements: *70148317909160
109
109
  description: ''
110
110
  email: richard@clue.co.za
111
111
  executables:
@@ -134,7 +134,6 @@ files:
134
134
  - functional/tmp/README
135
135
  - lib/langrove/_base.rb
136
136
  - lib/langrove/adaptor/base.rb
137
- - lib/langrove/adaptor/datagram.rb
138
137
  - lib/langrove/adaptor_base.rb
139
138
  - lib/langrove/client/base.rb
140
139
  - lib/langrove/client/datagram.rb
@@ -151,13 +150,14 @@ files:
151
150
  - lib/langrove/ext.rb
152
151
  - lib/langrove/handler/base.rb
153
152
  - lib/langrove/handler_base.rb
153
+ - lib/langrove/job/base.rb
154
+ - lib/langrove/job_base.rb
154
155
  - lib/langrove/protocol/base.rb
155
156
  - lib/langrove/protocol/syslog.rb
156
157
  - lib/langrove/protocol_base.rb
157
158
  - lib/langrove/version.rb
158
159
  - lib/langrove.rb
159
160
  - spec/functional/daemon/datagram_spec.rb
160
- - spec/langrove/adaptor/datagram_spec.rb
161
161
  - spec/langrove/adaptor_base_spec.rb
162
162
  - spec/langrove/client/datagram_spec.rb
163
163
  - spec/langrove/client_base_spec.rb
@@ -170,6 +170,7 @@ files:
170
170
  - spec/langrove/ext/persistable_spec.rb
171
171
  - spec/langrove/ext/string_spec.rb
172
172
  - spec/langrove/handler_base_spec.rb
173
+ - spec/langrove/job_base_spec.rb
173
174
  - spec/langrove/protocol/syslog_spec.rb
174
175
  - spec/langrove/protocol_base_spec.rb
175
176
  - spec/todo_spec.rb
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  requirements: []
195
196
  rubyforge_project:
196
- rubygems_version: 1.8.8
197
+ rubygems_version: 1.8.10
197
198
  signing_key:
198
199
  specification_version: 3
199
200
  summary: eventmachine based networked daemon framework
@@ -1,63 +0,0 @@
1
- require 'langrove/adaptor/base'
2
-
3
- module LanGrove::Adaptor
4
-
5
- class Datagram < Base
6
-
7
- def listen( client, protocol, handler )
8
-
9
- #
10
- # <client> = {
11
- #
12
- # :class => <loaded class constant>
13
- # :config => <client's branch of config>
14
- #
15
- # }
16
- #
17
- # <protocol> = { ...the same, but protocolic }
18
- #
19
- #
20
-
21
- @logger.info "starting listen at UDP #{@iface}:#{@port}"
22
-
23
- EventMachine::open_datagram_socket( @iface, @port,
24
-
25
- client[:class] ) do | client_connected |
26
-
27
- #
28
- # EM::open_datagram_socket (udp) yields on connect
29
- # to the socket.
30
- #
31
- # EM::start_server (tcp) yields on connect from the
32
- # client.
33
- #
34
-
35
- #
36
- # Initialize the client with a Protocol
37
- #
38
-
39
- client_connected.logger = @logger
40
-
41
- client_connected.config = client[ :config ]
42
-
43
- client_connected.protocol = protocol[ :class ]\
44
-
45
- .new( protocol[ :config ], @logger )
46
-
47
- @logger.info( "TODO: make a reference to the Client on the Handler" )
48
-
49
- #
50
- # Insert the Client into th Handler collection
51
- #
52
- handler.connect( client_connected )
53
-
54
- #
55
- # Client is ready and running inside the reactor
56
- #
57
- # EM::start_server will yield again on the next connect.
58
- #
59
-
60
- end
61
- end
62
- end
63
- end
@@ -1,6 +0,0 @@
1
- require 'langrove'
2
-
3
- describe LanGrove::Adaptor::Datagram do
4
-
5
-
6
- end