event_aggregator 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- data.tar.gz: 8e02703a95246297b726756d8d37d3a19a518d1e
4
- metadata.gz: 7fc37e093b95d0031783fe65badfa94aab39e8d8
5
2
  SHA512:
6
- data.tar.gz: e54aa9a193509076e5814213466d2697656b51d6d3f584752103cb5e45063b46bde002c0d8f052b51a0466f097329e9acc4531e39705cd1af2d75303807b8228
7
- metadata.gz: 9dd7dd3a8910ccfc61167e623a519ec3cd002b318fecfb1cbe9f2dd4d127cd1c44068d525ebd934afea8799d1538bcf1f139816c9283372913140614f9e0a1ca
3
+ metadata.gz: e881aefb5e0e91954065b076a7812c034893cb7d453ee2bb83d7cc21547028ebff2255f0b8284a7495c480df6068e7013c791dfde491cd0c82ce1a4ecbe383c0
4
+ data.tar.gz: 5e6d092c11a2c3740e91385823fb3f5c66f63759eee94c4e17a578b927cccb1c666b4853202a8ec47d7c068220220bc0944d8bd39711d4ad59261b676caa00b9
5
+ SHA1:
6
+ metadata.gz: 7c6f7f2e65af541dd7a64557fbae4f5ca2838cb2
7
+ data.tar.gz: 89ba6cafac97b7bd659843c1510aaa4c75281f7a
data/.travis.yml CHANGED
@@ -12,10 +12,9 @@ rvm:
12
12
  - ruby-head
13
13
  matrix:
14
14
  allow_failures:
15
+ - rvm: 1.8.7
15
16
  - rvm: jruby-head
16
17
  - rvm: ruby-head
17
- - rvm: jruby-18mode
18
- - rvm: 1.8.7
19
18
  - rvm: 1.9.2
20
19
  - rvm: rbx
21
20
  fast_finish: true
data/README.md CHANGED
@@ -74,24 +74,16 @@ Or install it yourself as:
74
74
  #=> data
75
75
 
76
76
  ### IMPORTANT: Asynchronous by Default
77
- Message.publish is asynchronous by default. This means that if you run event_aggregator in a script that terminates, there is a chance that the script will terminate before the workers have processed the messages and you can receive an error looking like the following:
78
-
79
- W, [2013-12-29T11:17:29.659902 #48097] WARN -- : Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
80
- D, [2013-12-29T11:17:29.660142 #48097] DEBUG -- : Celluloid::PoolManager: async call `perform` aborted!
81
- Celluloid::Task::TerminatedError: task was terminated
82
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:32:in `terminate'
83
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:404:in `block in cleanup'
84
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:404:in `each'
85
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:404:in `cleanup'
86
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:375:in `shutdown'
87
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:185:in `run'
88
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/actor.rb:157:in `block in initialize'
89
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/thread_handle.rb:13:in `block in initialize'
90
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/internal_pool.rb:100:in `call'
91
- /Users/user/.rvm/gems/ruby-1.9.3-p429/gems/celluloid-0.15.2/lib/celluloid/internal_pool.rb:100:in `block in create'
92
- W, [2013-12-29T11:17:29.660271 #48097] WARN -- : Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:callwait
93
-
94
- To make it synchronous (not recommended) use the following:
77
+ Message.publish is asynchronous by default. This means that if you run event_aggregator in a script that terminates, there is a chance that the script will terminate before the workers have processed the messages. This might cause errors.
78
+
79
+ A simple way to get around this problem is to do the following:
80
+
81
+ #....setup...
82
+ EventAggregator::Message.new("foo2", "data").publish
83
+
84
+ gets #This will wait for user input.
85
+
86
+ To make the message processing synchronous (not recommended) use the following:
95
87
 
96
88
  EventAggregator::Message.new("foo", "data", false).publish
97
89
  #=> data
@@ -129,6 +121,33 @@ This enables the following:
129
121
  #=> "foo bar bar bar bar"
130
122
 
131
123
 
124
+ ## Producers
125
+ In version 1.1+ the concept of producers are added. They are blocks or methods that responds to requests. A producer must be registered, which is done like this:
126
+
127
+ #listener is an instance of a class that includes EventAggregator::Listener, similar to the Foo class above.
128
+ listener.producer_register("MultiplyByTwo", lambda{|data| return data*2})
129
+
130
+ Then, somewhere in your code, you can do the following:
131
+
132
+ number = EventAggregator::Message.new("MultiplyByTwo", 3).request
133
+ puts number
134
+ # => 6
135
+
136
+ The producers are a good way to abstract away the retrieval of certain information.
137
+
138
+ Note: Message reqests are always blocking.
139
+
140
+ ## Message translation
141
+ In version 1.1+ the concept of message translation is added. This allows you to have messages on a specific type spawn other messages. To translate message type "type_1" into "type_2" you do:
142
+
143
+ #Anywhere in your code
144
+ EventAggregator::Aggregator.translate_message_with("type_1", "type_2")
145
+
146
+ It is also possible to transform the data in the conversion. To double the data value between "type_1" and "type_2" you do:
147
+
148
+ EventAggregator::Aggregator.translate_message_with("type_1", "type_2", lambda{|data| data*2})
149
+
150
+ This is often very usefull when you have one module that has a specific task, and it should be truly independent of other objects, even the message type they produce. The message translation allows you to have one file where you list all translations to give you a good overview and high maintainability.
132
151
 
133
152
  ## Usage Considerations
134
153
  All messages are processed asynchronous by default. This means that there might be raise conditions in your code.
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'faker', '~> 1.2'
26
26
  spec.add_development_dependency 'coveralls', '~> 0.7'
27
27
 
28
- spec.add_dependency 'eventmachine'
28
+ spec.add_dependency 'thread'
29
29
  end
@@ -1,4 +1,4 @@
1
- require "eventmachine"
1
+ require "thread/pool"
2
2
  require "event_aggregator/version"
3
3
  require "event_aggregator/aggregator"
4
4
  require "event_aggregator/listener"
@@ -11,7 +11,7 @@ module EventAggregator
11
11
  # end
12
12
  class Aggregator
13
13
  class <<self; private :new; end
14
-
14
+ @@pool = Thread.pool(4)
15
15
  @@listeners = Hash.new{|h, k| h[k] = Hash.new }
16
16
  @@listeners_all = Hash.new
17
17
  @@message_translation = Hash.new{|h, k| h[k] = Hash.new }
@@ -156,8 +156,8 @@ module EventAggregator
156
156
  private
157
157
  def self.perform_message_job(data, callback, async, consisten_data)
158
158
  case [async, consisten_data]
159
- when [true, true] then EventMachine.run{EventAggregator::MessageJob.new.perform(data, callback) ; EventMachine.stop }
160
- when [true, false] then EventMachine.run{EventAggregator::MessageJob.new.perform(data.clone, callback) ; EventMachine.stop }
159
+ when [true, true] then @@pool.process{ EventAggregator::MessageJob.new.perform(data, callback) }
160
+ when [true, false] then @@pool.process{ EventAggregator::MessageJob.new.perform(data.clone, callback) }
161
161
  when [false, true] then EventAggregator::MessageJob.new.perform(data, callback)
162
162
  when [false, false] then EventAggregator::MessageJob.new.perform(data.clone, callback)
163
163
  end
@@ -71,7 +71,7 @@ module EventAggregator
71
71
  #
72
72
  # Excample:
73
73
  # listener.producer_register("MultiplyByTwo", lambda{|data| return data*2})
74
- # number = EventAggregator::Message.new("MultiplyByTwo", 3)
74
+ # number = EventAggregator::Message.new("MultiplyByTwo", 3).request
75
75
  # # => 6
76
76
  #
77
77
  def producer_register(message_type, callback)
@@ -1,3 +1,3 @@
1
1
  module EventAggregator
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,20 @@ require 'rspec'
4
4
  #require 'rack/test'
5
5
  require "faker"
6
6
  require "event_aggregator"
7
+ #require "sucker_punch/testing/inline"
7
8
  require 'coveralls'
8
9
  Coveralls.wear!
9
10
 
10
11
 
12
+
13
+ class Thread::Pool
14
+
15
+ # Public: Overriding the process-call of the thread::pool so we can do tests better
16
+ def process (*args, &block)
17
+ block.call(*args)
18
+ end
19
+ end
20
+
11
21
  RSpec.configure do |config|
12
22
  config.treat_symbols_as_metadata_keys_with_true_values = true
13
23
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_aggregator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Eriksen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-02-06 00:00:00 Z
12
+ date: 2014-02-07 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :development
76
76
  version_requirements: *id006
77
77
  - !ruby/object:Gem::Dependency
78
- name: eventmachine
78
+ name: thread
79
79
  prerelease: false
80
80
  requirement: &id007 !ruby/object:Gem::Requirement
81
81
  requirements: