rservicebus 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rservicebus.rb CHANGED
@@ -28,6 +28,8 @@ require "rservicebus/Message/Subscription"
28
28
 
29
29
  require "rservicebus/UserMessage/WithPayload"
30
30
 
31
+ require "rservicebus/StateManager"
32
+
31
33
  require "rservicebus/AppResource"
32
34
  require "rservicebus/AppResource/Redis"
33
35
 
@@ -5,14 +5,18 @@ require "net/smb"
5
5
  class AppResource_Smb<AppResource
6
6
 
7
7
  def processUri
8
- parts = uri.path.split( "/" )
8
+ host = @uri.host
9
+
10
+ parts = @uri.path.split( "/" )
9
11
  parts.shift
10
- @share = parts.shift
11
- @path = parts.join( "/" )
12
+ share = parts.shift
13
+ path = parts.join( "/" )
14
+
15
+ @clean_path = "smb://#{host}/#{share}/#{URI.decode(path)}"
12
16
 
13
17
  @smb = Net::SMB.new
14
- @smb.auth_callback {|@uri.host, share|
15
- [uri.user,uri.password]
18
+ @smb.auth_callback {|host, share|
19
+ [@uri.user,@uri.password]
16
20
  }
17
21
  end
18
22
  end
@@ -1,5 +1,6 @@
1
1
  module RServiceBus
2
2
 
3
+ require "rservicebus/AppResource/Smb"
3
4
 
4
5
  class AppResource_SmbDir<AppResource_Smb
5
6
 
@@ -1,11 +1,13 @@
1
1
  module RServiceBus
2
2
 
3
+ require "rservicebus/AppResource/Smb"
3
4
 
4
5
  class AppResource_SmbFile<AppResource_Smb
5
6
 
6
7
  def connect(uri)
7
8
  self.processUri
8
- remote = SMB.open( s, "b" )
9
+ puts "@clean_path: #{@clean_path}"
10
+ remote = @smb.open( @clean_path )
9
11
  return remote
10
12
  end
11
13
 
@@ -51,12 +51,9 @@ module RServiceBus
51
51
  when "scpupload"
52
52
  require "rservicebus/AppResource/ScpUpload"
53
53
  resources[k.sub( "RSB_", "" )] = AppResource_ScpUpload.new( host, uri )
54
- when "smb"
55
- require "rservicebus/AppResource/Smb"
56
- resources[k.sub( "RSB_", "" )] = AppResource_Smb.new( host, uri )
57
- when "state"
58
- require "rservicebus/AppResource/State"
59
- resources[k.sub( "RSB_", "" )] = AppResource_State.new( host, uri )
54
+ when "smbfile"
55
+ require "rservicebus/AppResource/SmbFile"
56
+ resources[k.sub( "RSB_", "" )] = AppResource_SmbFile.new( host, uri )
60
57
  else
61
58
  abort("Scheme, #{uri.scheme}, not recognised when configuring app resource, #{k}=#{v}");
62
59
  end
@@ -10,9 +10,10 @@ module RServiceBus
10
10
  #
11
11
  # @param [RServiceBus::Host] host instance
12
12
  # @param [Hash] appResources As hash[k,v] where k is the name of a resource, and v is the resource
13
- def initialize( host, appResources )
13
+ def initialize( host, appResources, stateManager )
14
14
  @host = host
15
15
  @appResources = appResources
16
+ @stateManager = stateManager
16
17
 
17
18
  @handlerList = Hash.new
18
19
  @resourceListByHandlerName = Hash.new
@@ -31,6 +32,27 @@ module RServiceBus
31
32
  return self
32
33
  end
33
34
 
35
+ # setStateAttributeIfRequested
36
+ #
37
+ # @param [RServiceBus::Handler] handler
38
+ def setStateAttributeIfRequested( handler )
39
+ if defined?( handler.State ) then
40
+ handler.State = @stateManager.Get( handler )
41
+ @host.log "Bus attribute set for: " + handler.class.name
42
+ end
43
+
44
+ return self
45
+ end
46
+
47
+ # checkIfStateAttributeRequested
48
+ #
49
+ # @param [RServiceBus::Handler] handler
50
+ def checkIfStateAttributeRequested( handler )
51
+ @stateManager.Required if defined?( handler.State )
52
+
53
+ return self
54
+ end
55
+
34
56
  def interrogateHandlerForAppResources( handler )
35
57
  @host.log "Checking app resources for: #{handler.class.name}", true
36
58
  @host.log "If your attribute is not getting set, check that it is in the 'attr_accessor' list", true
@@ -52,6 +74,7 @@ module RServiceBus
52
74
 
53
75
  @handlerList[msgName] << handler
54
76
  self.setBusAttributeIfRequested( handler )
77
+ self.checkIfStateAttributeRequested( handler )
55
78
  self.interrogateHandlerForAppResources( handler )
56
79
  end
57
80
 
@@ -86,6 +109,8 @@ module RServiceBus
86
109
 
87
110
  def setResourcesForHandlersNeededToProcessMsg( msgName )
88
111
  @handlerList[msgName].each do |handler|
112
+ self.setStateAttributeIfRequested( handler )
113
+
89
114
  next if @resourceListByHandlerName[handler.class.name].nil?
90
115
  @resourceListByHandlerName[handler.class.name].each do |k|
91
116
  handler.instance_variable_set( "@#{k}", @appResources[k].getResource() )
@@ -98,6 +123,7 @@ module RServiceBus
98
123
  def getHandlerListForMsg( msgName )
99
124
  raise NoHandlerFound.new( msgName ) if @handlerList[msgName].nil?
100
125
 
126
+ @stateManager.Begin
101
127
  list = self.getListOfResourcesNeededToProcessMsg( msgName )
102
128
  list.each do |resourceName|
103
129
  r = @appResources[resourceName]
@@ -120,6 +146,7 @@ module RServiceBus
120
146
  r.Commit
121
147
  r.finished
122
148
  end
149
+ @stateManager.Commit
123
150
  end
124
151
 
125
152
  def rollbackResourcesUsedToProcessMsg( msgName )
@@ -51,6 +51,15 @@ module RServiceBus
51
51
  return self;
52
52
  end
53
53
 
54
+ #Thin veneer for Configuring external resources
55
+ #
56
+ def configureStateManager
57
+ @stateManager = StateManager.new
58
+ return self;
59
+ end
60
+
61
+
62
+
54
63
  #Thin veneer for Configuring external resources
55
64
  #
56
65
  def configureMonitors
@@ -80,7 +89,7 @@ module RServiceBus
80
89
  #
81
90
  def loadHandlers()
82
91
  log "Load Message Handlers"
83
- @handlerManager = HandlerManager.new( self, @appResources )
92
+ @handlerManager = HandlerManager.new( self, @appResources, @stateManager )
84
93
  @handlerLoader = HandlerLoader.new( self, @handlerManager )
85
94
 
86
95
  @config.handlerPathList.each do |path|
@@ -148,6 +157,7 @@ module RServiceBus
148
157
  .loadContracts()
149
158
  .loadLibs()
150
159
  .configureAppResource()
160
+ .configureStateManager()
151
161
  .configureMonitors()
152
162
  .loadHandlers()
153
163
  .connectToMq()
@@ -309,7 +319,7 @@ module RServiceBus
309
319
  log "Handler found for: " + msgName, true
310
320
  begin
311
321
  @queueForMsgsToBeSentOnComplete = Array.new
312
-
322
+
313
323
  handlerList.each do |handler|
314
324
  begin
315
325
  log "Handler, #{handler.class.name}, started processing msg, #{msgName}"
@@ -0,0 +1,78 @@
1
+ module RServiceBus
2
+
3
+ class StateManager
4
+
5
+
6
+ def Required
7
+ #Check if the State Dir has been specified
8
+ #If it has, make sure it exists, and is writable
9
+
10
+ workingDir = RServiceBus.getValue( "WORKING_DIR" )
11
+ defaultDir = "#{workingDir}/state"
12
+ specifiedStateDir = RServiceBus.getValue( "STATE_DIR" )
13
+ @stateDir = specifiedStateDir || defaultDir
14
+
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
+ end
35
+
36
+ #Start
37
+ def Begin
38
+ @list = Array.new
39
+ end
40
+
41
+ #Get
42
+ def Get( handler )
43
+ path = self.getPath( handler )
44
+ hash = self.load( path )
45
+ @list << Hash["path", path, "hash", hash]
46
+
47
+ return hash
48
+ end
49
+
50
+ #Finish
51
+ 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
62
+ end
63
+
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
+
75
+ end
76
+
77
+
78
+ 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.23
4
+ version: 0.1.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby interpretation of NServiceBus
15
15
  email: guy@guyirvine.com
@@ -38,7 +38,6 @@ files:
38
38
  - lib/rservicebus/AppResource/Smb.rb
39
39
  - lib/rservicebus/AppResource/SmbDir.rb
40
40
  - lib/rservicebus/AppResource/SmbFile.rb
41
- - lib/rservicebus/AppResource/State.rb
42
41
  - lib/rservicebus/AppResource.rb
43
42
  - lib/rservicebus/Audit.rb
44
43
  - lib/rservicebus/Config.rb
@@ -64,6 +63,7 @@ files:
64
63
  - lib/rservicebus/MQ/Beanstalk.rb
65
64
  - lib/rservicebus/MQ.rb
66
65
  - lib/rservicebus/Saga.rb
66
+ - lib/rservicebus/StateManager.rb
67
67
  - lib/rservicebus/Stats.rb
68
68
  - lib/rservicebus/SubscriptionManager.rb
69
69
  - lib/rservicebus/SubscriptionStorage/File.rb
@@ -1,68 +0,0 @@
1
- module RServiceBus
2
-
3
- class State
4
-
5
- def initialize( path )
6
- @path = path
7
- end
8
-
9
- def get( name )
10
- return -1 unless @state.has_key?(name)
11
-
12
- return @state[name]
13
- end
14
-
15
- def set( name, value )
16
- @state[name] = value
17
- end
18
-
19
- def load
20
- if !File.exists?( @path ) then
21
- @state = Hash.new if !File.exists?( @path )
22
- return
23
- end
24
-
25
- content = IO.read( @path )
26
- if content == "" then
27
- @state = Hash.new
28
- end
29
-
30
-
31
- @state = YAML::load( content )
32
- end
33
-
34
- def save
35
- content = YAML::dump( @state )
36
- IO.write( @path, content )
37
- end
38
-
39
- def close
40
-
41
- end
42
-
43
- end
44
-
45
-
46
- class AppResource_State<AppResource
47
-
48
- def connect(uri)
49
- return State.new( uri.path )
50
- end
51
-
52
- # Transaction Semantics
53
- def Begin
54
- @connection.load
55
- end
56
-
57
- # Transaction Semantics
58
- def Commit
59
- @connection.save
60
- end
61
-
62
- # Transaction Semantics
63
- def Rollback
64
- @connection.load
65
- end
66
- end
67
-
68
- end