lib/message_driver/broker.rb in message-driver-0.6.1 vs lib/message_driver/broker.rb in message-driver-0.7.0

- old
+ new

@@ -16,11 +16,11 @@ # @overload configure(name, options) # @param name [Symbol] when configuring multiple brokers, this symbol will differentiate between brokers # @param options [Hash] options to be passed to the adapter class def configure(name = DEFAULT_BROKER_NAME, options) if brokers.keys.include? name - fail BrokerAlreadyConfigured, "there is already a broker named #{name} configured" + raise BrokerAlreadyConfigured, "there is already a broker named #{name} configured" end brokers[name] = new(name, options) end # @overload broker @@ -29,12 +29,12 @@ # @return [Broker] the specified broker # @raise [BrokerNotConfigured] if a broker by that name has not yet been configured def broker(name = DEFAULT_BROKER_NAME) result = brokers[name] if result.nil? - fail BrokerNotConfigured, - "There is no broker named #{name} configured. The configured brokers are #{brokers.keys}" + raise BrokerNotConfigured, + "There is no broker named #{name} configured. The configured brokers are #{brokers.keys}" end result end # Yields the specified broker so that destinations and consumers can be defined on it. @@ -56,21 +56,17 @@ end # stops all the brokers # @see #stop def stop_all - each_broker do |brk| - brk.stop - end + each_broker(&:stop) end # restarts all the brokers # @see #restart def restart_all - each_broker do |brk| - brk.restart - end + each_broker(&:restart) end # Resets all the brokers for testing purposes. # @see Adapter::Base#reset_after_tests def reset_after_tests @@ -88,10 +84,11 @@ rescue => e Logging.logger.warn Logging.message_with_exception("error stopping broker #{brk.name}", e) end end brokers.clear + clients.clear end private def brokers @@ -155,59 +152,59 @@ dest = dynamic_destination(dest_name, dest_options, message_props) @destinations[key] = dest end def consumer(key, &block) - fail MessageDriver::Error, 'you must provide a block' unless block_given? + raise MessageDriver::Error, 'you must provide a block' unless block_given? @consumers[key] = block end # Find a previously declared Destination # @param destination_name [Symbol] the name of the destination # @return [Destination::Base] the requested destination # @raise [MessageDriver::NoSuchDestinationError] if there is no destination with that name def find_destination(destination_name) destination = @destinations[destination_name] if destination.nil? - fail MessageDriver::NoSuchDestinationError, "no destination #{destination_name} has been configured" + raise MessageDriver::NoSuchDestinationError, "no destination #{destination_name} has been configured" end destination end def find_consumer(consumer_name) consumer = @consumers[consumer_name] - fail MessageDriver::NoSuchConsumerError, "no consumer #{consumer_name} has been configured" if consumer.nil? + raise MessageDriver::NoSuchConsumerError, "no consumer #{consumer_name} has been configured" if consumer.nil? consumer end private def resolve_adapter(adapter, options) case adapter when nil - fail 'you must specify an adapter' + raise 'you must specify an adapter' when Symbol, String resolve_adapter(find_adapter_class(adapter), options) when Class resolve_adapter(adapter.new(self, options), options) when MessageDriver::Adapters::Base adapter else - fail "adapter must be a MessageDriver::Adapters::Base, but this object is a #{adapter.class}" + raise "adapter must be a MessageDriver::Adapters::Base, but this object is a #{adapter.class}" end end def find_adapter_class(adapter_name) require "message_driver/adapters/#{adapter_name}_adapter" adapter_method = "#{adapter_name}_adapter" unless respond_to?(adapter_method) - fail ['the adapter', - adapter_name, - 'must provide', - "MessageDriver::Broker##{adapter_method}", - 'that returns the adapter class'].join(' ') + raise ['the adapter', + adapter_name, + 'must provide', + "MessageDriver::Broker##{adapter_method}", + 'that returns the adapter class'].join(' ') end send(adapter_method) end end