Class: Scheduler::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/ara/scheduler.rb

Instance Method Summary collapse

Constructor Details

#initialize(receiver_actor, message, initial_delay, delay, time_unit) ⇒ Action

:nodoc:



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ara/scheduler.rb', line 86

def initialize(receiver_actor, message, initial_delay, delay, time_unit) #:nodoc:
   @receiver_actor = receiver_actor
   @message = message
   @initial_delay = initial_delay
   @delay = delay
   @time_unit = time_unit

   @once = delay == nil
   @current_delay = @initial_delay

   @thread = nil
end

Instance Method Details

#pauseObject

Pause the action



121
122
123
124
# File 'lib/ara/scheduler.rb', line 121

def pause
   @thread.kill
   @thread = nil
end

#restartObject

Restart the action



127
128
129
130
# File 'lib/ara/scheduler.rb', line 127

def restart
   stop unless @thread.nil?
   start
end

#shutdownObject

Shutdown the action



133
134
135
136
# File 'lib/ara/scheduler.rb', line 133

def shutdown
   stop
   Scheduler.actions.remove(self)
end

#startObject

Start the action



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ara/scheduler.rb', line 100

def start
   return unless Scheduler.actions.include?(self)
   @thread = Thread.new {
      while(true) 
         run
         @current_delay = @delay
         if @current_delay.nil?
            break
         end
      end
      shutdown
   }
end

#stopObject

Stop the action



115
116
117
118
# File 'lib/ara/scheduler.rb', line 115

def stop
   @current_delay = @initial_delay
   pause
end