Class: Synchronize

Inherits:
Object
  • Object
show all
Defined in:
lib/smsruby/adm_connection.rb

Overview

The Synchronize class contains all required variables to handle synchronization between producer - consumers and to protect critical resourses from concurrent access.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSynchronize

initialize all variables for the class



520
521
522
523
524
525
526
527
528
529
530
# File 'lib/smsruby/adm_connection.rb', line 520

def initialize
  @mutex = Mutex.new
  @mutexp=Mutex.new
  @mutexe=Mutex.new
  @empty = ConditionVariable.new
  @emptye = ConditionVariable.new
  @full = ConditionVariable.new
  @queue = Queue.new
  @eq = Queue.new
  @max = 10
end

Instance Attribute Details

#emptyObject

Represent the condition variable for handling an empty queue “queue”



505
506
507
# File 'lib/smsruby/adm_connection.rb', line 505

def empty
  @empty
end

#emptyeObject

Represent the condition variable for handling an empty queue “eq”



507
508
509
# File 'lib/smsruby/adm_connection.rb', line 507

def emptye
  @emptye
end

#eqObject

Reference a queue that contains destination numbers to wich the SMS messages couldn’t be send



513
514
515
# File 'lib/smsruby/adm_connection.rb', line 513

def eq
  @eq
end

#fullObject

Represent the condition variable for handling a full queue “queue”



509
510
511
# File 'lib/smsruby/adm_connection.rb', line 509

def full
  @full
end

#maxObject

Represent the max number of items that queue can retain



515
516
517
# File 'lib/smsruby/adm_connection.rb', line 515

def max
  @max
end

#mutexObject

Handle mutual exclution for queue



499
500
501
# File 'lib/smsruby/adm_connection.rb', line 499

def mutex
  @mutex
end

#mutexeObject

Handle mutual exclution for eq



503
504
505
# File 'lib/smsruby/adm_connection.rb', line 503

def mutexe
  @mutexe
end

#mutexpObject

Handle mutual exclution for the produced variable (protect the variable)



501
502
503
# File 'lib/smsruby/adm_connection.rb', line 501

def mutexp
  @mutexp
end

#queueObject

Reference a queue that contains all produced items by the producer



511
512
513
# File 'lib/smsruby/adm_connection.rb', line 511

def queue
  @queue
end

Instance Method Details

#countObject

Get the number of items for the queue “queue”



535
536
537
# File 'lib/smsruby/adm_connection.rb', line 535

def count
  @queue.size
end