euston-daemons 1.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +101 -0
  3. data/LICENSE +19 -0
  4. data/Rakefile +161 -0
  5. data/euston-daemons.gemspec +69 -0
  6. data/lib/euston-daemons.rb +15 -0
  7. data/lib/euston-daemons/command_processor_daemon/config/environment.rb +14 -0
  8. data/lib/euston-daemons/command_processor_daemon/lib/components/command_handler_component.rb +55 -0
  9. data/lib/euston-daemons/command_processor_daemon/lib/daemon.rb +43 -0
  10. data/lib/euston-daemons/command_processor_daemon/lib/settings.rb +19 -0
  11. data/lib/euston-daemons/command_processor_daemon/rake_task.rb +31 -0
  12. data/lib/euston-daemons/event_processor_daemon/config/environment.rb +20 -0
  13. data/lib/euston-daemons/event_processor_daemon/lib/components/event_handler_component.rb +72 -0
  14. data/lib/euston-daemons/event_processor_daemon/lib/daemon.rb +72 -0
  15. data/lib/euston-daemons/event_processor_daemon/lib/settings.rb +22 -0
  16. data/lib/euston-daemons/event_processor_daemon/rake_task.rb +37 -0
  17. data/lib/euston-daemons/framework/basic_component.rb +33 -0
  18. data/lib/euston-daemons/framework/component_shutdown.rb +22 -0
  19. data/lib/euston-daemons/framework/daemon.rb +27 -0
  20. data/lib/euston-daemons/framework/queue.rb +71 -0
  21. data/lib/euston-daemons/message_buffer_daemon/config/environment.rb +26 -0
  22. data/lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb +74 -0
  23. data/lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb +51 -0
  24. data/lib/euston-daemons/message_buffer_daemon/lib/daemon.rb +48 -0
  25. data/lib/euston-daemons/message_buffer_daemon/lib/message_logger.rb +54 -0
  26. data/lib/euston-daemons/message_buffer_daemon/lib/publisher.rb +56 -0
  27. data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb +54 -0
  28. data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb +36 -0
  29. data/lib/euston-daemons/message_buffer_daemon/lib/settings.rb +14 -0
  30. data/lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb +60 -0
  31. data/lib/euston-daemons/message_buffer_daemon/rake_task.rb +30 -0
  32. data/lib/euston-daemons/rake_task.rb +116 -0
  33. data/lib/euston-daemons/version.rb +5 -0
  34. metadata +235 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem 'mongoid', :git => 'https://github.com/guyboertje/mongoid.git'
data/Gemfile.lock ADDED
@@ -0,0 +1,101 @@
1
+ GIT
2
+ remote: https://github.com/guyboertje/mongoid.git
3
+ revision: 3e5d48a14baf274998202dda9e6540cd4aeb7fe6
4
+ specs:
5
+ mongoid (2.1.0)
6
+ activemodel (~> 3.0)
7
+ jmongo
8
+ mongo (~> 1.3)
9
+ tzinfo (~> 0.3.22)
10
+
11
+ PATH
12
+ remote: .
13
+ specs:
14
+ euston-daemons (1.0.0-java)
15
+ activemodel (~> 3.0.0)
16
+ activesupport (~> 3.0.0)
17
+ erb-yaml (~> 1.0.0)
18
+ euston (~> 1.0.0)
19
+ euston-eventstore (~> 1.0.0)
20
+ euston-rabbitmq (~> 1.0.0)
21
+ hollywood (~> 1.0.0)
22
+ i18n (~> 0.5.0)
23
+ jessica (~> 1.0.0)
24
+ jmongo (~> 1.0.0)
25
+ mongoid-glue (~> 1.0.0)
26
+ require_all (~> 1.2.0)
27
+ safely (~> 0.3.0)
28
+
29
+ GEM
30
+ remote: http://rubygems.org/
31
+ specs:
32
+ activemodel (3.0.10)
33
+ activesupport (= 3.0.10)
34
+ builder (~> 2.1.2)
35
+ i18n (~> 0.5.0)
36
+ activesupport (3.0.10)
37
+ bson (1.3.1-java)
38
+ builder (2.1.2)
39
+ diff-lcs (1.1.3)
40
+ erb-yaml (1.0.0)
41
+ hash-keys (>= 1.0.0, < 2.0.0)
42
+ euston (1.0.0)
43
+ activesupport (~> 3.0.9)
44
+ euston-eventstore (~> 1.0.0)
45
+ require_all (~> 1.2.0)
46
+ euston-eventstore (1.0.4-java)
47
+ activesupport (~> 3.0.9)
48
+ hash-keys (~> 1.0.0)
49
+ jmongo (~> 1.0.0)
50
+ json-jruby (~> 1.5.0)
51
+ require_all (~> 1.2.0)
52
+ uuid (~> 2.3.0)
53
+ euston-rabbitmq (1.0.0-java)
54
+ activesupport (~> 3.0.0)
55
+ euston (~> 1.0.0)
56
+ euston-eventstore (~> 1.0.0)
57
+ hash-keys (~> 1.0.0)
58
+ hollywood (~> 1.0.0)
59
+ jessica (~> 1.0.0)
60
+ jmongo (~> 1.0.0)
61
+ require_all (~> 1.2.0)
62
+ robustthread (~> 0.5.2)
63
+ safely (~> 0.3.0)
64
+ hash-keys (1.0.0)
65
+ hollywood (1.0.0)
66
+ i18n (0.5.0)
67
+ jessica (1.0.2-java)
68
+ require_all (~> 1.2.0)
69
+ jmongo (1.0.3)
70
+ require_all (~> 1.2)
71
+ json (1.5.0-java)
72
+ json-jruby (1.5.0-java)
73
+ json (= 1.5.0)
74
+ macaddr (1.4.0)
75
+ systemu (~> 2.2.0)
76
+ mongo (1.3.1)
77
+ bson (>= 1.3.1)
78
+ mongoid-glue (1.0.0)
79
+ require_all (1.2.0)
80
+ robustthread (0.5.2)
81
+ rspec (2.6.0)
82
+ rspec-core (~> 2.6.0)
83
+ rspec-expectations (~> 2.6.0)
84
+ rspec-mocks (~> 2.6.0)
85
+ rspec-core (2.6.4)
86
+ rspec-expectations (2.6.0)
87
+ diff-lcs (~> 1.1.2)
88
+ rspec-mocks (2.6.0)
89
+ safely (0.3.0)
90
+ systemu (2.2.0)
91
+ tzinfo (0.3.29)
92
+ uuid (2.3.4)
93
+ macaddr (~> 1.0)
94
+
95
+ PLATFORMS
96
+ java
97
+
98
+ DEPENDENCIES
99
+ euston-daemons!
100
+ mongoid!
101
+ rspec (~> 2.6.0)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Lee Henson, Guy Boertje
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,161 @@
1
+ require 'date'
2
+ require 'rspec/core/rake_task'
3
+
4
+ #############################################################################
5
+ #
6
+ # Helper functions
7
+ #
8
+ #############################################################################
9
+
10
+ def name
11
+ @name ||= Dir['*.gemspec'].first.split('.').first
12
+ end
13
+
14
+ def version
15
+ line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
16
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
17
+ end
18
+
19
+ def date
20
+ Date.today.to_s
21
+ end
22
+
23
+ def rubyforge_project
24
+ name
25
+ end
26
+
27
+ def gemspec_file
28
+ "#{name}.gemspec"
29
+ end
30
+
31
+ def gem_file
32
+ "#{name}-#{version}.gem"
33
+ end
34
+
35
+ def replace_header(head, header_name, provider = nil)
36
+ if provider
37
+ value = send(provider)
38
+ else
39
+ value = "'#{send(header_name)}'"
40
+ end
41
+
42
+ provider ||= header_name
43
+ head.sub!(/(\.#{header_name}\s*= ).*/) { "#{$1}#{value}"}
44
+ end
45
+
46
+ def platform
47
+ jruby? ? '-java' : ''
48
+ end
49
+
50
+ def platform_dependant_gem_file
51
+ "#{name}-#{version}#{platform}.gem"
52
+ end
53
+
54
+ def platform_dependent_version
55
+ "'#{version}#{platform}'"
56
+ end
57
+
58
+ def jruby?
59
+ RUBY_PLATFORM.to_s == 'java'
60
+ end
61
+
62
+ def trim_array_ends array
63
+ array.shift
64
+ array.pop
65
+ array
66
+ end
67
+
68
+ #############################################################################
69
+ #
70
+ # Custom tasks
71
+ #
72
+ #############################################################################
73
+
74
+ default_rspec_opts = %w[--colour --format Fuubar]
75
+
76
+ desc "Run all examples"
77
+ RSpec::Core::RakeTask.new(:spec) do |t|
78
+ t.rspec_opts = default_rspec_opts
79
+ end
80
+
81
+ #############################################################################
82
+ #
83
+ # Packaging tasks
84
+ #
85
+ #############################################################################
86
+
87
+ def built_gem
88
+ @built_gem ||= Dir["#{name}*.gem"].first
89
+ end
90
+
91
+ desc "Create tag v#{platform_dependent_version} and build and push #{platform_dependant_gem_file} to Rubygems"
92
+ task :release => :build do
93
+ unless `git branch` =~ /^\* master$/
94
+ puts "You must be on the master branch to release!"
95
+ exit!
96
+ end
97
+
98
+ sh "git commit --allow-empty -a -m 'Release #{platform_dependent_version}'"
99
+ sh "git tag v#{platform_dependent_version}"
100
+ sh "git push origin master"
101
+ sh "git push origin v#{platform_dependent_version}"
102
+
103
+ command = "gem push pkg/#{platform_dependant_gem_file}"
104
+
105
+ if jruby?
106
+ puts "--------------------------------------------------------------------------------------"
107
+ puts "can't push to rubygems using jruby at the moment, so switch to mri and run: #{command}"
108
+ puts "--------------------------------------------------------------------------------------"
109
+ else
110
+ sh command
111
+ end
112
+ end
113
+
114
+ desc "Build #{platform_dependant_gem_file} into the pkg directory"
115
+ task :build => :gemspec do
116
+ sh "mkdir -p pkg"
117
+ sh "gem build #{gemspec_file}"
118
+ sh "mv #{built_gem} pkg"
119
+ end
120
+
121
+ desc "Generate #{gemspec_file}"
122
+ task :gemspec => :validate do
123
+ # read spec file and split out manifest section
124
+ spec = File.read(gemspec_file)
125
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
126
+
127
+ # replace name version and date
128
+ replace_header(head, :name)
129
+ replace_header(head, :version)
130
+ replace_header(head, :date)
131
+ #comment this out if your rubyforge_project has a different name
132
+ #replace_header(head, :rubyforge_project)
133
+
134
+ # determine file list from git ls-files
135
+ files = `git ls-files`.
136
+ split("\n").
137
+ sort.
138
+ reject { |file| file =~ /^\./ }.
139
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
140
+ map { |file| " #{file}" }.
141
+ join("\n")
142
+
143
+ # piece file back together and write
144
+ manifest = " s.files = %w[\n#{files}\n ]\n"
145
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
146
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
147
+ puts "Updated #{gemspec_file}"
148
+ end
149
+
150
+ desc "Validate #{gemspec_file}"
151
+ task :validate do
152
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
153
+ unless libfiles.empty?
154
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
155
+ exit!
156
+ end
157
+ unless Dir['VERSION*'].empty?
158
+ puts "A `VERSION` file at root level violates Gem best practices."
159
+ exit!
160
+ end
161
+ end
@@ -0,0 +1,69 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'euston-daemons'
3
+ s.version = '1.0.0'
4
+ s.platform = 'java'
5
+ s.authors = ['Lee Henson', 'Guy Boertje']
6
+ s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
7
+ s.homepage = "http://github.com/leemhenson/euston-daemons"
8
+ s.summary = %q{Message buffer, command processor and event processor daemons for Euston-RabbitMq}
9
+ s.description = %q{}
10
+
11
+ # = MANIFEST =
12
+ s.files = %w[
13
+ Gemfile
14
+ Gemfile.lock
15
+ LICENSE
16
+ Rakefile
17
+ euston-daemons.gemspec
18
+ lib/euston-daemons.rb
19
+ lib/euston-daemons/command_processor_daemon/config/environment.rb
20
+ lib/euston-daemons/command_processor_daemon/lib/components/command_handler_component.rb
21
+ lib/euston-daemons/command_processor_daemon/lib/daemon.rb
22
+ lib/euston-daemons/command_processor_daemon/lib/settings.rb
23
+ lib/euston-daemons/command_processor_daemon/rake_task.rb
24
+ lib/euston-daemons/event_processor_daemon/config/environment.rb
25
+ lib/euston-daemons/event_processor_daemon/lib/components/event_handler_component.rb
26
+ lib/euston-daemons/event_processor_daemon/lib/daemon.rb
27
+ lib/euston-daemons/event_processor_daemon/lib/settings.rb
28
+ lib/euston-daemons/event_processor_daemon/rake_task.rb
29
+ lib/euston-daemons/framework/basic_component.rb
30
+ lib/euston-daemons/framework/component_shutdown.rb
31
+ lib/euston-daemons/framework/daemon.rb
32
+ lib/euston-daemons/framework/queue.rb
33
+ lib/euston-daemons/message_buffer_daemon/config/environment.rb
34
+ lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb
35
+ lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb
36
+ lib/euston-daemons/message_buffer_daemon/lib/daemon.rb
37
+ lib/euston-daemons/message_buffer_daemon/lib/message_logger.rb
38
+ lib/euston-daemons/message_buffer_daemon/lib/publisher.rb
39
+ lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb
40
+ lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb
41
+ lib/euston-daemons/message_buffer_daemon/lib/settings.rb
42
+ lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb
43
+ lib/euston-daemons/message_buffer_daemon/rake_task.rb
44
+ lib/euston-daemons/rake_task.rb
45
+ lib/euston-daemons/version.rb
46
+ ]
47
+ # = MANIFEST =
48
+
49
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
50
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
51
+
52
+ s.add_dependency 'activemodel', '~> 3.0.0'
53
+ s.add_dependency 'activesupport', '~> 3.0.0'
54
+ s.add_dependency 'erb-yaml', '~> 1.0.0'
55
+ s.add_dependency 'hollywood', '~> 1.0.0'
56
+ s.add_dependency 'i18n', '~> 0.5.0'
57
+ s.add_dependency 'require_all', '~> 1.2.0'
58
+ s.add_dependency 'safely', '~> 0.3.0'
59
+
60
+ s.add_dependency 'euston', '~> 1.0.0'
61
+ s.add_dependency 'euston-eventstore', '~> 1.0.0'
62
+ s.add_dependency 'euston-rabbitmq', '~> 1.0.0'
63
+ s.add_dependency 'jessica', '~> 1.0.0'
64
+ s.add_dependency 'jmongo', '~> 1.0.0'
65
+ # s.add_dependency 'mongoid'
66
+ s.add_dependency 'mongoid-glue', '~> 1.0.0'
67
+
68
+ s.add_development_dependency 'rspec', '~> 2.6.0'
69
+ end
@@ -0,0 +1,15 @@
1
+ if RUBY_PLATFORM.to_s == 'java'
2
+ require 'logger'
3
+ require 'rake/tasklib'
4
+
5
+ module Uuid
6
+ def self.generate
7
+ Java::JavaUtil::UUID.randomUUID().toString()
8
+ end
9
+ end
10
+
11
+ require_rel 'euston-daemons/rake_task.rb'
12
+ require_rel 'euston-daemons/command_processor_daemon/rake_task.rb'
13
+ require_rel 'euston-daemons/event_processor_daemon/rake_task.rb'
14
+ require_rel 'euston-daemons/message_buffer_daemon/rake_task.rb'
15
+ end
@@ -0,0 +1,14 @@
1
+ require_rel '../lib'
2
+
3
+ Safely::Strategy::Log.logger = EUSTON_LOG
4
+ Cqrs.uuid = Uuid
5
+ AMQP.settings.merge! ErbYaml.read(AMQP_CONFIG_PATH, EUSTON_ENV)
6
+ Euston::CommandProcessorDaemon::Settings.configure ErbYaml.read(DAEMON_CONFIG_PATH, EUSTON_ENV)
7
+
8
+ EventStore::Persistence::Mongodb::Config.instance.logger = EUSTON_LOG
9
+ EventStore::Persistence::Mongodb::Config.instance.database = Euston::CommandProcessorDaemon::Settings.mongo_db_name
10
+
11
+ Cqrs::RabbitMq.event_store = EventStore::Persistence::Mongodb::MongoPersistenceFactory.build
12
+ Cqrs::RabbitMq.event_store.init
13
+
14
+ Cqrs::Repository.event_store = EventStore::OptimisticEventStore.new Cqrs::RabbitMq.event_store
@@ -0,0 +1,55 @@
1
+ module Euston
2
+ module CommandProcessorDaemon
3
+ class CommandHandlerComponent
4
+ attr_reader :rmq_client, :cli_thread
5
+
6
+ def initialize
7
+ @rmq_client = AMQP::Channel.new
8
+ end
9
+
10
+ def start
11
+ @cli_thread = Thread.new do
12
+ begin
13
+ command_handler_bindings = Cqrs::RabbitMq::CommandHandlerBindings.new(@rmq_client)
14
+ command_handler_bindings.add_namespace Cqrs::RabbitMq::CommandHandlers
15
+
16
+ if Object.const_defined? 'COMMAND_HANDLER_NAMESPACES'
17
+ COMMAND_HANDLER_NAMESPACES.each do |handler_namespace|
18
+ ns = Object
19
+ found = true
20
+
21
+ handler_namespace.split('::').each do |c|
22
+ if found && ns.const_defined?(c)
23
+ ns = ns.const_get c.to_sym
24
+ elsif found
25
+ EUSTON_LOG.warn "Couldn't find requested command handler namespace: #{handler_namespace}"
26
+ found = false
27
+ end
28
+ end
29
+
30
+ if found
31
+ EUSTON_LOG.debug "Successfully found command handler namespace: #{handler_namespace}"
32
+ command_handler_bindings.add_namespace ns
33
+ end
34
+ end
35
+ end
36
+
37
+ command_handler_bindings.finalize_bindings
38
+ rescue => e
39
+ Thread.current[:exception] = e
40
+ Safely.report! e
41
+ end
42
+ end
43
+ end
44
+
45
+ def thread_state
46
+ @cli_thread.status
47
+ end
48
+
49
+ def stop
50
+ @cli_thread[:stop] = true
51
+ @rmq_client.disconnect
52
+ end
53
+ end
54
+ end
55
+ end