Class: RServiceBus::AppResource

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

Overview

Wrapper base class for resources used by applications, allowing rservicebus to configure the resource

  • dependency injection.

Instance Method Summary collapse

Constructor Details

#initialize(host, uri) ⇒ AppResource

Resources are attached resources, and can be specified using the URI syntax.

Parameters:

  • uri (String)

    a location for the resource to which we will attach, eg redis://127.0.0.1/foo



26
27
28
29
30
31
32
# File 'lib/rservicebus/AppResource.rb', line 26

def initialize( host, uri )
    @host = host
    @uri = uri
    #Do a connect / disconnect loop on startup to validate the connection
    self._connect
    self.finished
end

Instance Method Details

#_connectObject



18
19
20
21
# File 'lib/rservicebus/AppResource.rb', line 18

def _connect
    @connection = self.connect(@uri)
    RServiceBus.rlog "#{self.class.name}. Connected to, #{@uri.to_s}"
end

#BeginObject

Transaction Semantics



60
61
62
# File 'lib/rservicebus/AppResource.rb', line 60

def Begin
    
end

#CommitObject

Transaction Semantics



65
66
67
# File 'lib/rservicebus/AppResource.rb', line 65

def Commit
    
end

#connect(uri) ⇒ Object

The method which actually connects to the resource.



14
15
16
# File 'lib/rservicebus/AppResource.rb', line 14

def connect(uri)
    raise 'Method, connect, needs to be implemented for resource'
end

#finishedObject

A notification that ocurs after getResource, to allow cleanup



42
43
44
# File 'lib/rservicebus/AppResource.rb', line 42

def finished
    @connection.close
end

#getResourceObject

The method which actually configures the resource.

Returns:

  • (Object)

    the configured object.



37
38
39
# File 'lib/rservicebus/AppResource.rb', line 37

def getResource
    return @connection
end

#reconnectObject

At least called in the Host rescue block, to ensure all network links are healthy



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rservicebus/AppResource.rb', line 47

def reconnect
    begin
        self.finished
        rescue Exception => e
        puts '** AppResource. An error was raised while closing connection to, ' + @uri.to_s
        puts 'Message: ' + e.message
        puts e.backtrace
    end

    self._connect
end

#RollbackObject

Transaction Semantics



70
71
72
# File 'lib/rservicebus/AppResource.rb', line 70

def Rollback
    
end