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: 0660, 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: 0660, timeout: 0) ⇒ Resource
Returns a new instance of Resource.
12 13 14 15 16 17 18 19 |
# File 'lib/semian/resource.rb', line 12 def initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0) if Semian.semaphores_enabled? initialize_semaphore(name, tickets, quota, , timeout) if respond_to?(:initialize_semaphore) 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
30 31 32 33 |
# File 'lib/semian/resource.rb', line 30 def acquire(*) wait_time = 0 yield wait_time end |
#count ⇒ Object
35 36 37 |
# File 'lib/semian/resource.rb', line 35 def count 0 end |
#destroy ⇒ Object
24 25 |
# File 'lib/semian/resource.rb', line 24 def destroy end |
#in_use? ⇒ Boolean
55 56 57 |
# File 'lib/semian/resource.rb', line 55 def in_use? false end |
#key ⇒ Object
51 52 53 |
# File 'lib/semian/resource.rb', line 51 def key '0x00000000' end |
#registered_workers ⇒ Object
43 44 45 |
# File 'lib/semian/resource.rb', line 43 def registered_workers 0 end |
#reset_registered_workers! ⇒ Object
21 22 |
# File 'lib/semian/resource.rb', line 21 def reset_registered_workers! end |
#semid ⇒ Object
47 48 49 |
# File 'lib/semian/resource.rb', line 47 def semid 0 end |
#unregister_worker ⇒ Object
27 28 |
# File 'lib/semian/resource.rb', line 27 def unregister_worker end |