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.
-
#tickets ⇒ Object
readonly
Returns the value of attribute tickets.
Class Method Summary collapse
-
.instance(name, **kwargs) ⇒ Object
Ensure that there can only be one resource of a given type.
Instance Method Summary collapse
- #acquire {|wait_time| ... } ⇒ Object
- #count ⇒ Object
- #destroy ⇒ Object
- #in_use? ⇒ Boolean
-
#initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0) ⇒ Resource
constructor
A new instance of Resource.
- #key ⇒ Object
- #registered_workers ⇒ Object
- #reset_registered_workers! ⇒ Object
- #semid ⇒ Object
- #unregister_worker ⇒ Object
Constructor Details
#initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0) ⇒ Resource
Returns a new instance of Resource.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/semian/resource.rb', line 12 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.
3 4 5 |
# File 'lib/semian/resource.rb', line 3 def name @name end |
#tickets ⇒ Object (readonly)
Returns the value of attribute tickets.
3 4 5 |
# File 'lib/semian/resource.rb', line 3 def tickets @tickets end |
Class Method Details
.instance(name, **kwargs) ⇒ Object
Ensure that there can only be one resource of a given type
7 8 9 |
# File 'lib/semian/resource.rb', line 7 def instance(name, **kwargs) Semian.resources[name] ||= ProtectedResource.new(name, new(name, **kwargs), nil) end |
Instance Method Details
#acquire {|wait_time| ... } ⇒ Object
36 37 38 39 |
# File 'lib/semian/resource.rb', line 36 def acquire(*) wait_time = 0 yield wait_time end |
#count ⇒ Object
41 42 43 |
# File 'lib/semian/resource.rb', line 41 def count 0 end |
#destroy ⇒ Object
30 31 |
# File 'lib/semian/resource.rb', line 30 def destroy end |
#in_use? ⇒ Boolean
61 62 63 |
# File 'lib/semian/resource.rb', line 61 def in_use? false end |
#key ⇒ Object
57 58 59 |
# File 'lib/semian/resource.rb', line 57 def key '0x00000000' end |
#registered_workers ⇒ Object
49 50 51 |
# File 'lib/semian/resource.rb', line 49 def registered_workers 0 end |
#reset_registered_workers! ⇒ Object
27 28 |
# File 'lib/semian/resource.rb', line 27 def reset_registered_workers! end |
#semid ⇒ Object
53 54 55 |
# File 'lib/semian/resource.rb', line 53 def semid 0 end |
#unregister_worker ⇒ Object
33 34 |
# File 'lib/semian/resource.rb', line 33 def unregister_worker end |