Class: Semian::Resource
- Inherits:
-
Object
- Object
- Semian::Resource
- Defined in:
- lib/semian/resource.rb,
ext/semian/semian.c
Overview
Resource is the fundamental class of Semian. It is essentially a wrapper around a
SystemV semaphore.
You should not create this class directly, it will be created indirectly via Semian.register.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.instance(name, **kwargs) ⇒ Object
Ensure that there can only be one resource of a given type.
Instance Method Summary collapse
-
#initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0) ⇒ Resource
Returns a new instance of Resource.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/semian/resource.rb', line 20 def initialize(name, tickets: nil, quota: nil, permissions: Semian., timeout: 0) unless name.is_a?(String) || name.is_a?(Symbol) raise TypeError, "name must be a string or symbol, got: #{name.class}" end if Semian.semaphores_enabled? if respond_to?(:initialize_semaphore) initialize_semaphore("#{Semian.namespace}#{name}", tickets, quota, , timeout) end else Semian.issue_disabled_semaphores_warning end @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/semian/resource.rb', line 5 def name @name end |
Class Method Details
.instance(name, **kwargs) ⇒ Object
Ensure that there can only be one resource of a given type
9 10 11 |
# File 'lib/semian/resource.rb', line 9 def instance(name, **kwargs) Semian.resources[name] ||= ProtectedResource.new(name, new(name, **kwargs), nil) end |