Class: At_email::Threads::Thread_Queue

Inherits:
Core::Default show all
Defined in:
lib/at_email/threads/thread_queue.rb

Constant Summary collapse

CLASS_DISPLAY_NAME =
'Thread Queue'

Instance Attribute Summary collapse

Attributes inherited from Core::Default

#properties

Instance Method Summary collapse

Methods inherited from Core::Default

#get, #get_formatted, #get_state, #set_state

Constructor Details

#initializeThread_Queue

Returns a new instance of Thread_Queue.



10
11
12
13
14
15
16
17
18
# File 'lib/at_email/threads/thread_queue.rb', line 10

def initialize
  super
  if !@properties
    return false
  end
  @threads = {}
  @properties['Display Name'] = CLASS_DISPLAY_NAME
  @properties['Max Threads'] = 2
end

Instance Attribute Details

#threadsObject

Returns the value of attribute threads.



8
9
10
# File 'lib/at_email/threads/thread_queue.rb', line 8

def threads
  @threads
end

Instance Method Details

#activateObject



20
21
22
23
# File 'lib/at_email/threads/thread_queue.rb', line 20

def activate
  @properties['Activation Time'] = Time.now
  @properties['State'] = 'Active'
end

#queue_thread(code) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/at_email/threads/thread_queue.rb', line 25

def queue_thread(code)
  thread_object = At_email::Tasks::TaskThread.new
  thread_id = thread_object['ID']
  @threads[thread_id] = thread_object
  @threads[thread_id].queue(code)
  return thread_id
end

#start_thread(thread_id) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/at_email/threads/thread_queue.rb', line 33

def start_thread(thread_id)
  if get_state() === 'Active'
    @threads[thread_id].start
  else
    formatted_property = get_formatted('State')
    log_string = 'Thread cannot be started as this thread queue is not active - ' + formatted_property
    log_event('W', log_string)
  end
end

#stop_thread(thread_id) ⇒ Object



43
44
45
# File 'lib/at_email/threads/thread_queue.rb', line 43

def stop_thread(thread_id)
  @threads[thread_id].stop
end