rservicebus 0.1.33 → 0.1.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,77 +1,40 @@
1
1
  module RServiceBus
2
2
 
3
+ require 'rservicebus/StateStorage'
4
+
3
5
  class StateManager
4
-
5
-
6
+
7
+
6
8
  def Required
7
9
  #Check if the State Dir has been specified
8
10
  #If it has, make sure it exists, and is writable
11
+
12
+ string = RServiceBus.getValue( "STATE_URI" )
13
+ if string.nil? then
14
+ string = "dir:///tmp"
15
+ end
9
16
 
10
- workingDir = RServiceBus.getValue( "WORKING_DIR" )
11
- defaultDir = "#{workingDir}/state"
12
- specifiedStateDir = RServiceBus.getValue( "STATE_DIR" )
13
- @stateDir = specifiedStateDir || defaultDir
17
+ uri = URI.parse( string )
18
+ @stateStorage = StateStorage.Get( uri )
14
19
 
15
- inputDir = Dir.new( @stateDir )
16
- if !File.writable?( @stateDir ) then
17
- puts "***** Directory is not writable, #{@stateDir}."
18
- puts "***** Make the directory, #{@stateDir}, writable and try again."
19
- puts "***** Or, set the State Directory explicitly by, STATE_DIR=</path/to/state>" if specifiedStateDir.nil?
20
- abort();
21
- end
22
- rescue Errno::ENOENT => e
23
- puts "***** Directory does not exist, #{@stateDir}."
24
- puts "***** Create the directory, #{@stateDir}, and try again."
25
- puts "***** eg, mkdir #{@stateDir}"
26
- puts "***** Or, set the State Directory explicitly by, STATE_DIR=</path/to/state>" if specifiedStateDir.nil?
27
- abort();
28
- rescue Errno::ENOTDIR => e
29
- puts "***** The specified path does not point to a directory, #{@stateDir}."
30
- puts "***** Either repoint path to a directory, or remove, #{@stateDir}, and create it as a directory."
31
- puts "***** eg, rm #{@stateDir} && mkdir #{@stateDir}"
32
- puts "***** Or, set the State Directory explicitly by, STATE_DIR=</path/to/state>" if specifiedStateDir.nil?
33
- abort();
34
20
  end
35
21
 
36
22
  #Start
37
23
  def Begin
38
- @list = Array.new
24
+ @stateStorage.Begin
39
25
  end
40
26
 
41
27
  #Get
42
28
  def Get( handler )
43
- path = self.getPath( handler )
44
- hash = self.load( path )
45
- @list << Hash["path", path, "hash", hash]
46
-
47
- return hash
29
+ return @stateStorage.Get( handler )
48
30
  end
49
31
 
50
32
  #Finish
51
33
  def Commit
52
- @list.each do |e|
53
- IO.write( e['path'], YAML::dump( e['hash'] ) )
54
- end
55
- end
56
-
57
- #Detail Functions
58
- def getPath( handler )
59
- path = "#{@stateDir}/#{handler.class.name}"
60
-
61
- return path
34
+ @stateStorage.Commit
62
35
  end
63
36
 
64
- def load( path )
65
- return Hash.new if !File.exists?( path )
66
-
67
- content = IO.read( path )
68
-
69
- return Hash.new if content == ""
70
-
71
- return YAML::load( content )
72
- end
73
-
74
-
37
+
75
38
  end
76
39
 
77
40
 
@@ -0,0 +1,70 @@
1
+ module RServiceBus
2
+
3
+ class StateStorage_Dir
4
+
5
+ def initialize( uri )
6
+ @stateDir = uri.path
7
+
8
+ inputDir = Dir.new( @stateDir )
9
+ if !File.writable?( @stateDir ) then
10
+ puts "***** Directory is not writable, #{@stateDir}."
11
+ puts "***** Make the directory, #{@stateDir}, writable and try again."
12
+ puts "***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>"
13
+ abort();
14
+ end
15
+ rescue Errno::ENOENT => e
16
+ puts "***** Directory does not exist, #{@stateDir}."
17
+ puts "***** Create the directory, #{@stateDir}, and try again."
18
+ puts "***** eg, mkdir #{@stateDir}"
19
+ puts "***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>"
20
+ abort();
21
+ rescue Errno::ENOTDIR => e
22
+ puts "***** The specified path does not point to a directory, #{@stateDir}."
23
+ puts "***** Either repoint path to a directory, or remove, #{@stateDir}, and create it as a directory."
24
+ puts "***** eg, rm #{@stateDir} && mkdir #{@stateDir}"
25
+ puts "***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>"
26
+ abort();
27
+ end
28
+
29
+ #Start
30
+ def Begin
31
+ @list = Array.new
32
+ end
33
+
34
+ #Get
35
+ def Get( handler )
36
+ path = self.getPath( handler )
37
+ hash = self.load( path )
38
+ @list << Hash["path", path, "hash", hash]
39
+
40
+ return hash
41
+ end
42
+
43
+ #Finish
44
+ def Commit
45
+ @list.each do |e|
46
+ IO.write( e['path'], YAML::dump( e['hash'] ) )
47
+ end
48
+ end
49
+
50
+ #Detail Functions
51
+ def getPath( handler )
52
+ path = "#{@stateDir}/#{handler.class.name}"
53
+
54
+ return path
55
+ end
56
+
57
+ def load( path )
58
+ return Hash.new if !File.exists?( path )
59
+
60
+ content = IO.read( path )
61
+
62
+ return Hash.new if content == ""
63
+
64
+ return YAML::load( content )
65
+ end
66
+
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,19 @@
1
+ module RServiceBus
2
+
3
+ class StateStorage
4
+
5
+ def StateStorage.Get( uri )
6
+ case uri.scheme
7
+ when "dir"
8
+ require 'rservicebus/StateStorage/Dir.rb'
9
+ return StateStorage_Dir.new( uri )
10
+ else
11
+ abort("Scheme, #{uri.scheme}, not recognised when configuring StateStorage, #{uri.to_s}");
12
+ end
13
+
14
+ end
15
+
16
+
17
+ end
18
+
19
+ end
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.33
4
+ version: 0.1.34
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-10-03 00:00:00.000000000 Z
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
16
- requirement: &70168920560860 !ruby/object:Gem::Requirement
16
+ requirement: &70247617650940 !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: *70168920560860
24
+ version_requirements: *70247617650940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70168920555700 !ruby/object:Gem::Requirement
27
+ requirement: &70247617650040 !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: *70168920555700
35
+ version_requirements: *70247617650040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: beanstalk-client
38
- requirement: &70168920924560 !ruby/object:Gem::Requirement
38
+ requirement: &70247617649240 !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: *70168920924560
46
+ version_requirements: *70247617649240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fluiddb
49
- requirement: &70168920923940 !ruby/object:Gem::Requirement
49
+ requirement: &70247617648580 !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: *70168920923940
57
+ version_requirements: *70247617648580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: parse-cron
60
- requirement: &70168920923200 !ruby/object:Gem::Requirement
60
+ requirement: &70247617648160 !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: *70168920923200
68
+ version_requirements: *70247617648160
69
69
  description: A Ruby interpretation of NServiceBus
70
70
  email: guy@guyirvine.com
71
71
  executables:
@@ -121,6 +121,8 @@ files:
121
121
  - lib/rservicebus/MQ.rb
122
122
  - lib/rservicebus/Saga.rb
123
123
  - lib/rservicebus/StateManager.rb
124
+ - lib/rservicebus/StateStorage/Dir.rb
125
+ - lib/rservicebus/StateStorage.rb
124
126
  - lib/rservicebus/Stats.rb
125
127
  - lib/rservicebus/SubscriptionManager.rb
126
128
  - lib/rservicebus/SubscriptionStorage/File.rb