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.

Parameters:

  • plan (Plan)

    Plan to which this spot will deliver data events

  • name (Symbol)

    Name of spot attribute in plan that corresponds to this spot

  • here (Plan, nil)

    Plan of calling Spot if any, nil otherwise

  • dest (Symbol, nil) (defaults to: nil)

    destination name use to obtain return value for >>

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)

Returns Plan of calling spot if any, nil otherwise.

Returns:

  • (Plan, nil)

    Plan of calling spot if any, nil otherwise



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

def here
  @here
end

#nameSymbol (readonly)

Returns Name of spot attribute in plan that corresponds to this spot.

Returns:

  • (Symbol)

    Name of spot attribute in plan that corresponds to this spot



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

def name
  @name
end

#planPlan (readonly)

Returns Plan to which this spot will deliver data events.

Returns:

  • (Plan)

    Plan to which this spot will deliver data events



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

Returns:

  • (Any)

    plan.call_local name, key, val



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

Returns:

  • (Boolean)


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

def clone_to_copy? ; false end

#cloneable?Boolean

Returns:

  • (Boolean)


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

def cloneable? ; true end

#destSpot

Returns plan.public_spot(dest_name) if that exists, plan.dest otherwise.

Returns:

  • (Spot)

    plan.public_spot(dest_name) if that exists, plan.dest otherwise



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?

Returns Spot’s destination name, or nil for plan.dest, returned by >>.

Returns:

  • (Symbol, nil)

    Spot’s destination name, or nil for plan.dest, returned by >>



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

def dest_name ; @dest end

#entryself

Returns for compatibility with plan’s API.

Returns:

  • (self)

    for compatibility with plan’s API



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

Returns this spot or a modified copy of it such that here == new_calling_plan holds.

Returns:

  • (Spot)

    this spot or a modified copy of it such that here == new_calling_plan holds



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

Parameters:

  • track (Track)

    requested target track

  • data (Any)

    any data event

  • tags (Hash)

    to be passed along

Returns:

  • (self)


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.

Returns:

  • (Spot)

    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