Class: FreeMessageQueue::FileQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/fmq/queues/file.rb

Overview

This queue returns everytime the same file. This is useful during debugging or to serve the admin page.

configuration sample:

queue-manager:
  auto-create-queues: true
  defined-queues:
    admin-page-index:
    path: /admin/index
    class: FreeMessageQueue::FileQueue
    file: admin-interface/index.html
    content-type: text/html

NOTE the put method is not implemented in this queue. It is a poll only queue.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileQueue

Returns a new instance of FileQueue.



41
42
43
44
45
# File 'lib/fmq/queues/file.rb', line 41

def initialize
  # there is always one message (the file) in the queue
  @bytes = -1
  @size = 1
end

Instance Attribute Details

#bytesObject (readonly)

Bytes are -1 at startup but fill after first poll. Size is allways 1 message



39
40
41
# File 'lib/fmq/queues/file.rb', line 39

def bytes
  @bytes
end

#managerObject

QueueManager refrence



36
37
38
# File 'lib/fmq/queues/file.rb', line 36

def manager
  @manager
end

#sizeObject (readonly)

Bytes are -1 at startup but fill after first poll. Size is allways 1 message



39
40
41
# File 'lib/fmq/queues/file.rb', line 39

def size
  @size
end

Instance Method Details

#content_type=(type) ⇒ Object

CONFIGURATION OPTION sets the content_type of the file. This option make sense if you want to test with the webbrowser.



69
70
71
# File 'lib/fmq/queues/file.rb', line 69

def content_type=(type)
  @content_type = type
end

#file=(path) ⇒ Object

CONFIGURATION OPTION sets the path to the file that should be read



62
63
64
# File 'lib/fmq/queues/file.rb', line 62

def file=(path)
  @file_path = path
end

#pollObject

Return the file and content type



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fmq/queues/file.rb', line 48

def poll()
  item = OpenStruct.new

  f = open(@file_path, "rb")
  item.data = f.read
  @bytes = item.data.size
  f.close
  
  item.content_type = @content_type
  item
end