Class: RServiceBus::SagaStorage_Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/SagaStorage/Dir.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ SagaStorage_Dir

Returns a new instance of SagaStorage_Dir.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 5

def initialize( uri )
    @sagaDir = uri.path

    inputDir = Dir.new( @sagaDir )
    unless File.writable?(@sagaDir) then
      puts "***** Directory is not writable, #{@sagaDir}."
      puts "***** Make the directory, #{@sagaDir}, writable and try again."
      puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>'
      abort();
    end
    rescue Errno::ENOENT => e
    puts "***** Directory does not exist, #{@sagaDir}."
    puts "***** Create the directory, #{@sagaDir}, and try again."
    puts "***** eg, mkdir #{@sagaDir}"
    puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>'
    abort();
    rescue Errno::ENOTDIR => e
    puts "***** The specified path does not point to a directory, #{@sagaDir}."
    puts "***** Either repoint path to a directory, or remove, #{@sagaDir}, and create it as a directory."
    puts "***** eg, rm #{@sagaDir} && mkdir #{@sagaDir}"
    puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>'
    abort();
end

Instance Method Details

#BeginObject

Start



30
31
32
33
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 30

def Begin
    @list = Array.new
    @deleted = Array.new
end

#CommitObject

Finish



51
52
53
54
55
56
57
58
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 51

def Commit
    @list.each do |e|
        File.open( e['path'], 'w') { |f| f.write( YAML::dump( e['data'] ) ) }
    end
    @deleted.each do |correlationId|
        File.unlink( self.getPath( correlationId ) )
    end
end

#Delete(correlationId) ⇒ Object



63
64
65
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 63

def Delete( correlationId )
    @deleted << correlationId
end

#Get(correlationId) ⇒ Object

Get



42
43
44
45
46
47
48
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 42

def Get( correlationId )
    path = self.getPath( correlationId )
    data = self.load( path )
    @list << Hash['path', path, 'data', data]
    
    return data
end

#getPath(correlationId) ⇒ Object

Detail Functions



68
69
70
71
72
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 68

def getPath( correlationId )
    path = "#{@sagaDir}/saga-#{correlationId}"

    return path
end

#load(path) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 74

def load( path )
    return Hash.new unless File.exists?(path)
    
    content = IO.read( path )
    
    return Hash.new if content == ''
    
    return YAML::load( content )
end

#RollbackObject



60
61
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 60

def Rollback
end

#Set(data) ⇒ Object

Set



36
37
38
39
# File 'lib/rservicebus/SagaStorage/Dir.rb', line 36

def Set( data )
    path = self.getPath( data.correlationId )
    @list << Hash['path', path, 'data', data]
end