rservicebus 0.1.57 → 0.1.58

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ module RServiceBus
2
+
3
+ class SagaStorage_Dir
4
+
5
+ def initialize( uri )
6
+ @sagaDir = uri.path
7
+
8
+ inputDir = Dir.new( @sagaDir )
9
+ if !File.writable?( @sagaDir ) then
10
+ puts "***** Directory is not writable, #{@sagaDir}."
11
+ puts "***** Make the directory, #{@sagaDir}, writable and try again."
12
+ puts "***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>"
13
+ abort();
14
+ end
15
+ rescue Errno::ENOENT => e
16
+ puts "***** Directory does not exist, #{@sagaDir}."
17
+ puts "***** Create the directory, #{@sagaDir}, and try again."
18
+ puts "***** eg, mkdir #{@sagaDir}"
19
+ puts "***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>"
20
+ abort();
21
+ rescue Errno::ENOTDIR => e
22
+ puts "***** The specified path does not point to a directory, #{@sagaDir}."
23
+ puts "***** Either repoint path to a directory, or remove, #{@sagaDir}, and create it as a directory."
24
+ puts "***** eg, rm #{@sagaDir} && mkdir #{@sagaDir}"
25
+ puts "***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>"
26
+ abort();
27
+ end
28
+
29
+ #Start
30
+ def Begin
31
+ @list = Array.new
32
+ @deleted = Array.new
33
+ end
34
+
35
+ #Set
36
+ def Set( data )
37
+ path = self.getPath( data.correlationId )
38
+ @list << Hash["path", path, "data", data]
39
+ end
40
+
41
+ #Get
42
+ def Get( correlationId )
43
+ path = self.getPath( correlationId )
44
+ data = self.load( path )
45
+ @list << Hash["path", path, "data", data]
46
+
47
+ return data
48
+ end
49
+
50
+ #Finish
51
+ def Commit
52
+ @list.each do |e|
53
+ IO.write( e['path'], YAML::dump( e['data'] ) )
54
+ end
55
+ @deleted.each do |correlationId|
56
+ File.unlink( self.getPath( correlationId ) )
57
+ end
58
+ end
59
+
60
+ def Rollback
61
+ end
62
+
63
+ def Delete( correlationId )
64
+ @deleted << correlationId
65
+ end
66
+
67
+ #Detail Functions
68
+ def getPath( correlationId )
69
+ path = "#{@sagaDir}/saga-#{correlationId}"
70
+
71
+ return path
72
+ end
73
+
74
+ def load( path )
75
+ return Hash.new if !File.exists?( path )
76
+
77
+ content = IO.read( path )
78
+
79
+ return Hash.new if content == ""
80
+
81
+ return YAML::load( content )
82
+ end
83
+
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,41 @@
1
+ module RServiceBus
2
+
3
+
4
+ class SagaStorage_InMemory
5
+
6
+ def initialize( uri )
7
+ end
8
+
9
+ #Start
10
+ def Begin
11
+ @hash = Hash.new
12
+ @deleted = Array.new
13
+ end
14
+
15
+ #Set
16
+ def Set( data )
17
+ @hash[data.correlationId] = data
18
+ end
19
+
20
+ #Get
21
+ def Get( correlationId )
22
+ return @hash[correlationId]
23
+ end
24
+
25
+ #Finish
26
+ def Commit
27
+ @deleted.each do |correlationId|
28
+ @hash.delete( correlationId )
29
+ end
30
+ end
31
+
32
+ def Delete( correlationId )
33
+ @deleted << correlationId
34
+ end
35
+
36
+ def Rollback
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -1,11 +1,13 @@
1
1
  module RServiceBus
2
2
 
3
3
  class Test_Bus
4
- attr_accessor :publishList, :sendList, :replyList, :logList
4
+ attr_accessor :publishList, :sendList, :replyList, :logList, :sagaData
5
+
5
6
  @publishList
6
7
  @sendList
7
8
  @replyList
8
9
  @logList
10
+ @sagaData
9
11
 
10
12
  def initialize
11
13
  @publishList = Array.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.57
4
+ version: 0.1.58
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-29 00:00:00.000000000 Z
12
+ date: 2014-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
16
- requirement: &70227782467900 !ruby/object:Gem::Requirement
16
+ requirement: &70346625881440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70227782467900
24
+ version_requirements: *70346625881440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70227782467220 !ruby/object:Gem::Requirement
27
+ requirement: &70346625880860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70227782467220
35
+ version_requirements: *70346625880860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: beanstalk-client
38
- requirement: &70227782466420 !ruby/object:Gem::Requirement
38
+ requirement: &70346625879800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70227782466420
46
+ version_requirements: *70346625879800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fluiddb
49
- requirement: &70227782480800 !ruby/object:Gem::Requirement
49
+ requirement: &70346625879100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70227782480800
57
+ version_requirements: *70346625879100
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: parse-cron
60
- requirement: &70227782480020 !ruby/object:Gem::Requirement
60
+ requirement: &70346625878260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70227782480020
68
+ version_requirements: *70346625878260
69
69
  description: A Ruby interpretation of NServiceBus
70
70
  email: guy@guyirvine.com
71
71
  executables:
@@ -121,7 +121,14 @@ files:
121
121
  - lib/rservicebus/MQ/RabbitMq.rb
122
122
  - lib/rservicebus/MQ/Redis.rb
123
123
  - lib/rservicebus/MQ.rb
124
- - lib/rservicebus/Saga.rb
124
+ - lib/rservicebus/ResourceManager.rb
125
+ - lib/rservicebus/Saga/Base.rb
126
+ - lib/rservicebus/Saga/Data.rb
127
+ - lib/rservicebus/Saga/Manager.rb
128
+ - lib/rservicebus/SagaLoader.rb
129
+ - lib/rservicebus/SagaStorage/Dir.rb
130
+ - lib/rservicebus/SagaStorage/InMemory.rb
131
+ - lib/rservicebus/SagaStorage.rb
125
132
  - lib/rservicebus/StateManager.rb
126
133
  - lib/rservicebus/StateStorage/Dir.rb
127
134
  - lib/rservicebus/StateStorage.rb
@@ -1,141 +0,0 @@
1
- module RServiceBus
2
-
3
- #Requirements for Saga.
4
- #
5
- #Technicalities
6
- #correlation: how to tie two independant msgs together in a single saga
7
- #
8
- #Multiple messages - Any of which can start the saga
9
- #Timeouts
10
- #Persistent Data between calls
11
- #Ability to "complete" a saga, but not compulsory to do so.
12
-
13
-
14
- require "uri"
15
-
16
-
17
- class Saga_Data_InMemory
18
-
19
- attr_reader :data_hash
20
-
21
- @data_hash
22
-
23
- def initialize
24
- @data_hash = Hash.new
25
- end
26
-
27
- def get( saga, msg, mapping )
28
- @data_hash[saga.class.name] = Hash.new if @data_hash[saga.class.name].nil?
29
- @data_hash[saga.class.name][msg.class.name] = Array.new if @data_hash[saga.class.name][msg.class.name].nil?
30
-
31
- if !mapping[msg.class.name].nil? then
32
- mapping[msg.class.name].each do |msgFieldName,sagaFieldName|
33
-
34
- @data_hash[saga.class.name][msg.class.name].each do |data|
35
- if !data[sagaFieldName].nil? then
36
- return data if msg.instance_variable_get(msgFieldName) == data[sagaFieldName]
37
- end
38
- end
39
- end
40
- end
41
-
42
- hash = Hash.new
43
- @data_hash[saga.class.name][msg.class.name].push( hash )
44
- return hash;
45
- end
46
-
47
- end
48
-
49
- # Wrapper base class for resources used by applications, allowing rservicebus to configure the resource
50
- # - dependency injection.
51
- #
52
- class Saga_Manager
53
-
54
- #correlation strategy
55
- # correlation strategy return an instance of the saga.
56
- # that way, we can return an existing one, or create a new one
57
-
58
- # Start with sagaid
59
-
60
- # def Handle_MsgName( msg, data )
61
-
62
- # end
63
-
64
- def initialize
65
- @sagas = Hash.new
66
- @saga_data = Saga_Data_InMemory.new
67
- end
68
-
69
- def getMsgNames( sagaClass )
70
- list = []
71
- sagaClass.instance_methods.each do |name|
72
- list.push name.to_s.sub( "Handle_", "" ) if name.to_s.slice( 0,7 ) == "Handle_"
73
- end
74
-
75
- return list
76
- end
77
-
78
- def addSaga( sagaClass )
79
- saga = sagaClass.new
80
- hash = Hash["saga", saga, "mapping", saga.mapping]
81
- self.getMsgNames( sagaClass ).each do |name|
82
- sagas[name] = Array.new if sagas[name].nil?
83
- @sagas[name].push( hash )
84
- end
85
- end
86
-
87
- def Handle( msg )
88
- return if @sagas[msg.class.name].nil?
89
-
90
- @sagas[msg.class.name].each do |hash|
91
- saga = hash["saga"]
92
-
93
- data = @saga_data.get( saga, msg, hash["mapping"] )
94
-
95
- saga.data = data
96
- saga.Handle( msg )
97
- end
98
-
99
- end
100
- end
101
-
102
-
103
- class Saga
104
- attr_accessor :data, :mapping
105
- attr_reader :data
106
-
107
- @data
108
- @mapping
109
-
110
- def initialize
111
- @mapping = Hash.new
112
- self.ConfigureHowToFindSaga
113
- end
114
-
115
- def ConfigureHowToFindSaga()
116
- throw StandardError.new( "ConfigureHowToFindSaga needs to be implemented" );
117
- end
118
-
119
- def ConfigureMapping( msg, sagaFieldName, msgFieldName);
120
- # if !msg.has_attribute?( msgFieldName ) then
121
- # raise StandardError.new( "Msg, #{msg.name}, doesn't have a field named, #{msgFieldName}" )
122
- #end
123
- @mapping[msg.name] = Hash.new if @mapping[msg.name].nil?
124
- @mapping[msg.name]["@" + msgFieldName] = sagaFieldName
125
- end
126
-
127
- def complete
128
- end
129
-
130
- def Handle( msg )
131
- methodName = "Handle_#{msg.class.name}"
132
-
133
- self.send methodName, msg
134
- end
135
- end
136
-
137
- class Saga_Manager
138
-
139
-
140
- end
141
- end