Class: Semian::ProtectedResource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/semian/protected_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, bulkhead, circuit_breaker) ⇒ ProtectedResource

Returns a new instance of ProtectedResource.



11
12
13
14
15
# File 'lib/semian/protected_resource.rb', line 11

def initialize(name, bulkhead, circuit_breaker)
  @name = name
  @bulkhead = bulkhead
  @circuit_breaker = circuit_breaker
end

Instance Attribute Details

#bulkheadObject (readonly)

Returns the value of attribute bulkhead.



9
10
11
# File 'lib/semian/protected_resource.rb', line 9

def bulkhead
  @bulkhead
end

#circuit_breakerObject (readonly)

Returns the value of attribute circuit_breaker.



9
10
11
# File 'lib/semian/protected_resource.rb', line 9

def circuit_breaker
  @circuit_breaker
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/semian/protected_resource.rb', line 9

def name
  @name
end

Instance Method Details

#acquire(timeout: nil, scope: nil, adapter: nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/semian/protected_resource.rb', line 22

def acquire(timeout: nil, scope: nil, adapter: nil)
  acquire_circuit_breaker(scope, adapter) do
    acquire_bulkhead(timeout, scope, adapter) do
      yield self
    end
  end
end

#destroyObject



17
18
19
20
# File 'lib/semian/protected_resource.rb', line 17

def destroy
  @bulkhead.destroy unless @bulkhead.nil?
  @circuit_breaker.destroy unless @circuit_breaker.nil?
end