Class: RServiceBus::SubscriptionStorage_File

Inherits:
SubscriptionStorage show all
Defined in:
lib/rservicebus/SubscriptionStorage/File.rb

Overview

Implementation of Subscription Storage to Redis

Instance Method Summary collapse

Constructor Details

#initialize(appName, uri) ⇒ SubscriptionStorage_File

Constructor

Parameters:

  • appName (String)

    Name of the application, which is used as a Namespace

  • uri (String)

    a location for the resource to which we will attach, eg redis://127.0.0.1/foo



12
13
14
# File 'lib/rservicebus/SubscriptionStorage/File.rb', line 12

def initialize( appName, uri )
	super(appName, uri)
end

Instance Method Details

#add(eventName, queueName) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rservicebus/SubscriptionStorage/File.rb', line 23

def add( eventName, queueName )
       if File.exists?( @uri.path ) then
           subscriptions = YAML::load( File.open( @uri.path ) )
       else
		subscriptions = Hash.new
       end
           
       subscriptions[eventName] = Array.new if subscriptions[eventName].nil?
	
	subscriptions[eventName] << queueName
	subscriptions[eventName] = subscriptions[eventName].uniq

       File.open( @uri.path, 'w') { |f| f.write( YAML::dump(subscriptions ) ) }

	return subscriptions
end

#getAllObject



16
17
18
19
20
21
# File 'lib/rservicebus/SubscriptionStorage/File.rb', line 16

def getAll
	RServiceBus.log 'Load subscriptions'
       return Hash.new unless File.exists?( @uri.path )
       
       return YAML::load( File.open( @uri.path ) )
end

#remove(eventName, queueName) ⇒ Object



40
41
42
# File 'lib/rservicebus/SubscriptionStorage/File.rb', line 40

def remove( eventName, queueName )
	raise 'Method, remove, needs to be implemented for this subscription storage'
end