Class: Arachni::Database::Queue

Inherits:
Base show all
Defined in:
lib/arachni/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:

Version:

  • 0.1

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Queue

Returns a new instance of Queue.

See Also:



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

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

Instance Method Details

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

Adds an object to the queue.

Parameters:



49
50
51
# File 'lib/arachni/database/queue.rb', line 49

def <<( obj )
    @q << dump( obj )
end

#clearObject

Removes all objects from the Queue.



88
89
90
91
92
93
94
# File 'lib/arachni/database/queue.rb', line 88

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

#empty?Bool

True if the Queue if empty, false otherwise.

Returns:

  • (Bool)


81
82
83
# File 'lib/arachni/database/queue.rb', line 81

def empty?
    @q.empty?
end

#popObject Also known as: deq, shift

Removes an object from the Queue and returns it.

Returns:



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

def pop
    return load_and_delete_file( @q.pop )
end

#sizeInteger Also known as: length

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

Returns:

  • (Integer)


71
72
73
# File 'lib/arachni/database/queue.rb', line 71

def size
    @q.size
end