Module: Pione::Global

Defined in:
lib/pione/global.rb,
lib/pione/global/item.rb,
lib/pione/global/config.rb,
lib/pione/global/log-variable.rb,
lib/pione/global/path-variable.rb,
lib/pione/global/relay-variable.rb,
lib/pione/global/client-variable.rb,
lib/pione/global/system-variable.rb,
lib/pione/global/global-exception.rb,
lib/pione/global/network-variable.rb,
lib/pione/global/package-variable.rb,
lib/pione/global/diagnosis-variable.rb,
lib/pione/global/interactive-variable.rb,
lib/pione/global/task-worker-variable.rb,
lib/pione/global/input-generator-variable.rb,
lib/pione/global/task-worker-broker-variable.rb,
lib/pione/global/tuple-space-notifier-variable.rb

Overview

Global is a table of global variables in PIONE system. It defines variable names, initial values, and configuration conditions. You can set and get value by calling item named method.

Defined Under Namespace

Modules: ValueConverter Classes: Config, GlobalError, InvalidConfigFile, Item, UnconfigurableVariableError, UnknownItem

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.__dependencies__Object (readonly)

Returns the value of attribute dependencies.



13
14
15
# File 'lib/pione/global/item.rb', line 13

def __dependencies__
  @__dependencies__
end

.itemObject (readonly)

Returns the value of attribute item.



12
13
14
# File 'lib/pione/global/item.rb', line 12

def item
  @item
end

Class Method Details

.define_computed_item(name, dependencies, &definition) ⇒ Object

Define a computed item. The item cannote be configured by user.



32
33
34
35
36
37
# File 'lib/pione/global/item.rb', line 32

def define_computed_item(name, dependencies, &definition)
  Item.new(name, false, :dependencies => dependencies).tap do |item|
    definition.call(item) if block_given?
    item.register
  end
end

.define_external_item(name, initial_value = nil, &definition) ⇒ Object

Define an external item. The item can be configured by user.



24
25
26
27
28
29
# File 'lib/pione/global/item.rb', line 24

def define_external_item(name, initial_value=nil, &definition)
  Item.new(name, true).tap do |item|
    definition.call(item) if block_given?
    item.register
  end
end

.define_internal_item(name, initial_value = nil, &definition) ⇒ Object

Define an internal item. The item cannot be configured by user.



16
17
18
19
20
21
# File 'lib/pione/global/item.rb', line 16

def define_internal_item(name, initial_value=nil, &definition)
  Item.new(name, false).tap do |item|
    definition.call(item) if block_given?
    item.register
  end
end

.get(name) ⇒ Object

Get value of the variable.

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pione/global/item.rb', line 40

def get(name)
  raise UnknownItem.new(name) unless @item.has_key?(name)

  # get current value
  val = @item[name].value

  if val.nil?
    # call updater
    @item[name].update(@item[name].init)

    # get value
    return @item[name].value
  else
    return val
  end
end

.set(name, val) ⇒ Object

Set value of the variable.



58
59
60
61
62
63
64
65
66
# File 'lib/pione/global/item.rb', line 58

def set(name, val)
  # set value
  @item[name].update(val)

  # update depended items
  @__dependencies__[name].each do |dependency|
    @item[dependency.name].update(nil)
  end
end