Class: Arachni::Support::Database::Queue

Inherits:
Base show all
Defined in:
lib/arachni/support/database/queue.rb

Overview

Flat-file Queue implementation

Behaves pretty much like a Ruby Queue however it transparently serializes and saves its values to the file-system under the OS’s temp directory.

It’s pretty useful when you want to reduce memory footprint without having to refactor any code since it behaves just like Ruby’s implementation.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Queue

Returns a new instance of Queue.

See Also:

  • Database::Base#initialize


32
33
34
35
36
# File 'lib/arachni/support/database/queue.rb', line 32

def initialize( *args )
    super( *args )
    @q     = ::Queue.new
    @mutex = Mutex.new
end

Instance Method Details

#<<(obj) ⇒ Object Also known as: push, enq

Parameters:

  • obj (Object)

    Object to add to the queue.



39
40
41
# File 'lib/arachni/support/database/queue.rb', line 39

def <<( obj )
    synchronize { @q << dump( obj ) }
end

#clearObject

Removes all objects from the queue.



65
66
67
68
69
70
71
# File 'lib/arachni/support/database/queue.rb', line 65

def clear
    while !@q.empty?
        path = @q.pop
        next if !path
        delete_file path
    end
end

#empty?Bool

Returns ‘true` if the queue if empty, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if the queue if empty, `false` otherwise.



60
61
62
# File 'lib/arachni/support/database/queue.rb', line 60

def empty?
    @q.empty?
end

#popObject Also known as: deq, shift

Returns Removes an object from the queue and returns it.

Returns:

  • (Object)

    Removes an object from the queue and returns it.



46
47
48
# File 'lib/arachni/support/database/queue.rb', line 46

def pop
    synchronize { load_and_delete_file @q.pop }
end

#sizeInteger Also known as: length

Returns Size of the queue, the number of objects it currently holds.

Returns:

  • (Integer)

    Size of the queue, the number of objects it currently holds.



54
55
56
# File 'lib/arachni/support/database/queue.rb', line 54

def size
    @q.size
end