Class: Andromeda::Spot

Inherits:
Impl::ConnectorBase show all
Includes:
Impl::To_S
Defined in:
lib/andromeda/spot.rb

Overview

A spot is a reachable destination to which data may be sent for processing. It encapsulates addressing the processing logic of a Plan into a separate, immutable Object that may be passed around freely.

It is somewhat similiar/a mixture of notions such as actor address, RPC endpoint, and stack frame in other frameworks

 You MUST not inherit from this class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Impl::To_S

short_s, #to_s

Methods inherited from Impl::ConnectorBase

#post, #post_local, #start

Constructor Details

#initialize(plan, name, here, dest = nil) ⇒ Spot

Returns a new instance of Spot.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/andromeda/spot.rb', line 31

def initialize(plan, name, here, dest = nil)
  raise ArgumentError, "#{plan} is not a Plan" unless plan.is_a? Plan
  raise ArgumentError, "#{name} is not a Symbol" unless name.is_a? Symbol
  unless plan.spot_meth_name?(name)
    raise ArgumentError, "#{name} is not a known method spot name of #{plan}"
  end
  unless dest.nil? || dest.is_a?(Symbol)
    raise ArgumentError, "#{dest} is neither nil nor a Symbol"
  end
  if !here || here.is_a?(Plan)
    @plan = plan
    @name = name
    @here = here
    @dest = dest
  else
    raise ArgumentError, "#{here} is neither nil nor a Plan"
  end
end

Instance Attribute Details

#herePlan? (readonly)



22
23
24
# File 'lib/andromeda/spot.rb', line 22

def here
  @here
end

#nameSymbol (readonly)



19
20
21
# File 'lib/andromeda/spot.rb', line 19

def name
  @name
end

#planPlan (readonly)



16
17
18
# File 'lib/andromeda/spot.rb', line 16

def plan
  @plan
end

Instance Method Details

#==(other) ⇒ Object

Spots compare attribute-wise and do not accept subclasses



57
58
59
60
61
# File 'lib/andromeda/spot.rb', line 57

def ==(other)
  return true if self.equal? other
  return false unless other.class.equal? Spot
  name.eq(other.name) && plan.eq(other.plan) && here.eq(other.here) && dest.eq(other.dest)
end

#>>(target) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/andromeda/spot.rb', line 115

def >>(target)
  return (plan >> target) unless dest_name
  unless plan.spot_attr_name?(dest_name)
    raise ArgumentError, "#{dest_name} is not an spot_attr_name"
  end
  plan.send :"#{dest_name}=", target.entry
  plan.public_spot(dest_name)
end

#call_local(key, val) ⇒ Any

Call the spot method associated with this spot with the provided key and val

Precondition is that here == plan, i.e. the caller already executes in the scope of this spot’s plan



101
102
103
# File 'lib/andromeda/spot.rb', line 101

def call_local(key, val)
  plan.call_local name, key, val
end

#clone_to_copy?Boolean



51
# File 'lib/andromeda/spot.rb', line 51

def clone_to_copy? ; false end

#cloneable?Boolean



50
# File 'lib/andromeda/spot.rb', line 50

def cloneable? ; true end

#destSpot



109
110
111
112
113
# File 'lib/andromeda/spot.rb', line 109

def dest
  if dest_name
    then plan.public_spot(dest_name)
    else plan.dest end
end

#dest_nameSymbol?



25
# File 'lib/andromeda/spot.rb', line 25

def dest_name ; @dest end

#entryself



106
# File 'lib/andromeda/spot.rb', line 106

def entry ; self end

#hashObject



63
# File 'lib/andromeda/spot.rb', line 63

def hash ; plan.hash ^ name.hash ^ here.hash ^ dest.hash end

#identical_copyObject



52
# File 'lib/andromeda/spot.rb', line 52

def identical_copy ; self end

#intern(new_calling_plan) ⇒ Spot



125
126
127
128
129
# File 'lib/andromeda/spot.rb', line 125

def intern(new_calling_plan)
  if here.equal? new_calling_plan
    then self
    else Spot.new plan, name, new_calling_plan, dest_name end
end

#post_to(track, data, tags_in = {}) ⇒ self

Post data with the associated tags_in to this’s spot’s plan’s method spot with name name and hint that the caller requested the spot activation to be executed on track tack



83
84
85
86
87
# File 'lib/andromeda/spot.rb', line 83

def post_to(track, data, tags_in = {})
  tags_in = (here.tags.identical_copy.update(tags_in) rescue tags_in) if here
  plan.post_data self, track, data, tags_in
  self
end

#to_short_sObject



65
66
67
68
69
70
71
72
# File 'lib/andromeda/spot.rb', line 65

def to_short_s
  dest_ = dest_name
  dest_ = if dest_ then " dest=:#{dest_name}" else '' end
  here_ = here
  if here_
    then " plan=#{plan} name=:#{name} here=#{here_}#{dest_}"
    else " plan=#{plan} name=:#{name}#{dest_}" end
end

#via(spot_name) ⇒ Spot

Returns a fresh copy of self for which dest_name == spot_name holds.

Raises:

  • (ArgumentError)


90
91
92
93
# File 'lib/andromeda/spot.rb', line 90

def via(spot_name)
  raise ArgumentError unless spot_name.nil? || spot_name.is_a?(Symbol)
  Spot.new plan, name, here, spot_name
end