Class: Dramatis::Runtime::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/dramatis/runtime/task.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: Continuation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor, dest, args, options) ⇒ Task

Returns a new instance of Task.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dramatis/runtime/task.rb', line 26

def initialize actor, dest, args, options
  @actor = actor
  @dest = dest
  @args = args.dup

  @call_thread = nil

  name = Dramatis::Runtime::Scheduler.actor
  actor = name.instance_eval { @actor }

  object_id = actor.object.object_id

  @args.each_with_index do |arg,i|
    if arg.object_id == object_id
      @args[i] = name
    end
  end

  if actor.call_threading?
    # warn "oct #{options[:call_thread]} act #{actor.call_thread}"
    raise "hell" if options[:call_thread] and
                     actor.call_thread and
                     options[:call_thread] != actor.call_thread
    @call_thread = actor.call_thread
    if @call_thread == nil
      @call_thread = self.to_s
    end
  end

  # warn "task #{self} #{args[0]} call thread [ #{@call_thread} ] #{options.to_a.join(' ')}"

  case options[:continuation]
  when :none
    @continuation = Continuation::None.new name, @call_thread
  when :rpc
    @continuation = Continuation::RPC.new name,
                                            @call_thread,
                                            options[:nonblocking]
  when :future
    @continuation = Continuation::Future.new name, @call_thread
  when Proc
    @continuation = Continuation::Proc.new name,  @call_thread, options[:continuation],
                                                                  options[:exception]
  else
    raise Dramatis::Internal.new( "invalid contiunation type" )
  end
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



10
11
12
# File 'lib/dramatis/runtime/task.rb', line 10

def actor
  @actor
end

#call_threadObject (readonly)

Returns the value of attribute call_thread.



24
25
26
# File 'lib/dramatis/runtime/task.rb', line 24

def call_thread
  @call_thread
end

Instance Method Details

#argumentsObject



20
21
22
# File 'lib/dramatis/runtime/task.rb', line 20

def arguments
  @args[1,@args.length]
end

#deliverObject



82
83
84
# File 'lib/dramatis/runtime/task.rb', line 82

def deliver
  @actor.deliver @dest, @args, @continuation, @call_thread
end

#exception(e) ⇒ Object



74
75
76
# File 'lib/dramatis/runtime/task.rb', line 74

def exception e
  @continuation.exception e
end

#methodObject



16
17
18
# File 'lib/dramatis/runtime/task.rb', line 16

def method
  @args[0]
end

#queuedObject



78
79
80
# File 'lib/dramatis/runtime/task.rb', line 78

def queued
  @continuation.queued
end

#typeObject



12
13
14
# File 'lib/dramatis/runtime/task.rb', line 12

def type
  @dest
end