Class: Pindo::TaskSystem::TaskResources::ResourceType
- Inherits:
-
Object
- Object
- Pindo::TaskSystem::TaskResources::ResourceType
- Defined in:
- lib/pindo/module/task/task_resources/resource_type.rb
Overview
资源类型基类
职责:
-
定义资源的冲突检查逻辑
-
子类实现不同的冲突策略
资源冲突策略:
-
:directory_based - 基于目录的资源(相同目录互斥,不同目录可并行)
-
:global_exclusive - 全局互斥资源(任何时候只能一个任务使用)
-
:global_shared - 全局共享资源(无限制并发)
Direct Known Subclasses
DirectoryBasedResourceType, GlobalExclusiveResourceType, GlobalSharedResourceType
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#conflicts?(instance1, instance2) ⇒ Boolean
检查两个资源实例是否冲突(抽象方法,子类必须实现).
-
#directory_based? ⇒ Boolean
检查是否为基于目录的资源.
-
#global_exclusive? ⇒ Boolean
检查是否为全局互斥资源.
-
#global_shared? ⇒ Boolean
检查是否为全局共享资源.
-
#initialize(name, strategy) ⇒ ResourceType
constructor
A new instance of ResourceType.
-
#to_s ⇒ String
资源类型的字符串表示.
Constructor Details
#initialize(name, strategy) ⇒ ResourceType
Returns a new instance of ResourceType.
19 20 21 22 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 19 def initialize(name, strategy) @name = name @strategy = strategy end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 15 def name @name end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
15 16 17 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 15 def strategy @strategy end |
Instance Method Details
#conflicts?(instance1, instance2) ⇒ Boolean
检查两个资源实例是否冲突(抽象方法,子类必须实现)
29 30 31 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 29 def conflicts?(instance1, instance2) raise NotImplementedError, "#{self.class} must implement #conflicts?" end |
#directory_based? ⇒ Boolean
检查是否为基于目录的资源
41 42 43 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 41 def directory_based? @strategy == :directory_based end |
#global_exclusive? ⇒ Boolean
检查是否为全局互斥资源
47 48 49 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 47 def global_exclusive? @strategy == :global_exclusive end |
#global_shared? ⇒ Boolean
检查是否为全局共享资源
53 54 55 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 53 def global_shared? @strategy == :global_shared end |
#to_s ⇒ String
资源类型的字符串表示
35 36 37 |
# File 'lib/pindo/module/task/task_resources/resource_type.rb', line 35 def to_s "#{@name}(#{@strategy})" end |