stapfen 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,9 +3,9 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in stapfen.gemspec
4
4
  gemspec
5
5
 
6
-
7
6
  group :development do
8
7
  gem 'rake'
9
8
  gem 'rspec', '~> 2.11'
10
9
  gem 'guard-rspec'
10
+ gem 'yard'
11
11
  end
@@ -1,4 +1,5 @@
1
- require 'stomp'
1
+ require 'thread'
2
+ require 'onstomp'
2
3
 
3
4
  module Stapfen
4
5
  class Worker
@@ -28,20 +29,15 @@ module Stapfen
28
29
  attr_accessor :client
29
30
 
30
31
  def initialize
31
- @pool = []
32
- @workqueue = Queue.new
33
32
  handle_signals!
34
33
  end
35
34
 
36
- def main_thread(&block)
37
- @workqueue << block
38
- end
39
35
 
40
36
  def run
41
- @client = Stomp::Client.new(self.class.configuration)
37
+ @client = OnStomp::Client.new(generate_uri)
38
+ @client.connect
42
39
 
43
40
  self.class.consumers.each do |name, headers, block|
44
-
45
41
  # We're taking each block and turning it into a method so that we can
46
42
  # use the instance scope instead of the blocks originally bound scope
47
43
  # which would be at a class level
@@ -49,9 +45,8 @@ module Stapfen
49
45
  self.class.send(:define_method, method_name, &block)
50
46
 
51
47
  client.subscribe(name, headers) do |message|
52
- @pool << Thread.new do
53
- self.send(method_name, message)
54
- end
48
+ puts "invoking #{method_name} for #{message.inspect}"
49
+ self.send(method_name, message)
55
50
  end
56
51
  end
57
52
 
@@ -59,19 +54,8 @@ module Stapfen
59
54
  # Performing this join/open loop to make sure that we don't
60
55
  # experience potential deadlocks between signal handlers who might
61
56
  # close the connection, and an infinite Client#join call
62
- while client.open? do
63
- client.join(1)
64
-
65
- until @workqueue.empty?
66
- block = @workqueue.pop
67
- begin
68
- block.call
69
- rescue => e
70
- puts "Exception! #{e}"
71
- end
72
- end
73
-
74
- @pool = @pool.select { |t| t.alive? }
57
+ while client.connected? do
58
+ sleep(0.2)
75
59
  end
76
60
  rescue Interrupt
77
61
  exit_cleanly
@@ -89,15 +73,25 @@ module Stapfen
89
73
  end
90
74
 
91
75
  def exit_cleanly
92
- unless @pool.empty?
93
- puts "Giving #{@pool.size} threads 10s each to finish up"
94
- @pool.each do |t|
95
- t.join(10)
96
- end
76
+ if client.connected?
77
+ client.disconnect
97
78
  end
98
- unless client.closed?
99
- client.close
79
+ end
80
+
81
+ # Convert Stapfen configuration into an OnStomp URL
82
+ #
83
+ # @return [String]
84
+ def generate_uri
85
+ config = self.class.configuration
86
+ raise Stapfen::ConfigurationError if config.nil? || config.empty?
87
+
88
+ user_info = nil
89
+
90
+ if config[:login] && config[:passcode]
91
+ user_info = "#{config[:login]}:#{config[:passcode]}@"
100
92
  end
93
+
94
+ "stomp://#{user_info}#{config[:host]}:#{config[:port]}"
101
95
  end
102
96
  end
103
97
  end
data/spec/worker_spec.rb CHANGED
@@ -2,11 +2,10 @@ require 'spec_helper'
2
2
 
3
3
 
4
4
  describe Stapfen::Worker do
5
- let(:worker) { subject }
5
+ subject(:worker) { described_class.new }
6
6
 
7
7
  context 'class methods' do
8
- subject { described_class }
9
- let(:worker) { described_class }
8
+ subject(:worker) { described_class }
10
9
 
11
10
  it { should respond_to :run! }
12
11
  it { should respond_to :configure }
@@ -53,4 +52,39 @@ describe Stapfen::Worker do
53
52
  end
54
53
  end
55
54
  end
55
+
56
+ context 'instance methods' do
57
+ describe '#generate_uri' do
58
+ subject(:uri) { worker.generate_uri }
59
+ let(:conf) { {} }
60
+
61
+ before :each do
62
+ worker.class.stub(:configuration).and_return(conf)
63
+ end
64
+
65
+ context 'with a blank configuration' do
66
+ it 'should raise an error' do
67
+ expect { worker.generate_uri }.to raise_error(Stapfen::ConfigurationError)
68
+ end
69
+ end
70
+
71
+ context 'with an unauthenticated non-ssl host' do
72
+ let(:conf) { {:host => 'localhost', :port => 61613} }
73
+
74
+ it { should eql('stomp://localhost:61613') }
75
+ end
76
+
77
+ context 'with an authentication ssl host' do
78
+ let(:conf) do
79
+ {:host => 'localhost',
80
+ :port => 61613,
81
+ :login => 'admin',
82
+ :passcode => 'admin'}
83
+ end
84
+
85
+ it { should eql('stomp://admin:admin@localhost:61613') }
86
+ end
87
+ end
88
+
89
+ end
56
90
  end
data/stapfen.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
 
21
- gem.add_dependency('stomp', '>= 1.2.8')
21
+ gem.add_dependency('onstomp', '>= 1.0.7')
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stapfen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-02 00:00:00.000000000 Z
12
+ date: 2013-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: stomp
15
+ name: onstomp
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2.8
21
+ version: 1.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2.8
29
+ version: 1.0.7
30
30
  description: A simple gem for writing good basic STOMP workers
31
31
  email:
32
32
  - rtyler.croy@lookout.com
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: -2006440266819501787
64
+ hash: -4282538672362447376
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: -2006440266819501787
73
+ hash: -4282538672362447376
74
74
  requirements: []
75
75
  rubyforge_project:
76
76
  rubygems_version: 1.8.25
@@ -80,3 +80,4 @@ summary: A simple gem for writing good basic STOMP workers
80
80
  test_files:
81
81
  - spec/spec_helper.rb
82
82
  - spec/worker_spec.rb
83
+ has_rdoc: