Class: Backstage::Destination

Inherits:
Object
  • Object
show all
Includes:
HasMBean, Resource, Enumerable
Defined in:
lib/destinations/models/destination.rb

Direct Known Subclasses

Queue, Topic

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#association_chain, included, #resource, #to_hash

Methods included from HasMBean

#<=>, #full_name, included, #initialize, #mbean_info, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backstage::HasMBean

Instance Attribute Details

#enumerable_optionsObject

Returns the value of attribute enumerable_options.



25
26
27
# File 'lib/destinations/models/destination.rb', line 25

def enumerable_options
  @enumerable_options
end

Class Method Details

.display_name(name) ⇒ Object



75
76
77
78
79
80
# File 'lib/destinations/models/destination.rb', line 75

def self.display_name(name)
  display_name = name.gsub( /jms\..*?\./, '' )
  display_name = 'Backgroundable' if display_name =~ %r{/queues/.*/tasks/torquebox_backgroundable}
  display_name = "#{$1.classify}Task" if display_name =~ %r{/queues/torquebox/.*/tasks/(.*)$}
  display_name
end

.filterObject



27
28
29
# File 'lib/destinations/models/destination.rb', line 27

def self.filter
  "org.hornetq:address=\"#{jms_prefix}\",*,type=Queue"
end

.to_hash_attributesObject



31
32
33
# File 'lib/destinations/models/destination.rb', line 31

def self.to_hash_attributes
  super + [:display_name, :app, :app_name, :status, :message_count, :delivering_count, :scheduled_count, :messages_added, :consumer_count]
end

Instance Method Details

#appObject



82
83
84
# File 'lib/destinations/models/destination.rb', line 82

def app
  name =~ %r{/queues/torquebox/(.*?)/} ? App.find( "torquebox.apps:name=#{$1}" ) : nil
end

#app_nameObject



86
87
88
# File 'lib/destinations/models/destination.rb', line 86

def app_name
  name =~ %r{/queues/torquebox/(.*?)/} ? $1 : 'n/a'
end

#available_actionsObject



109
110
111
112
# File 'lib/destinations/models/destination.rb', line 109

def available_actions
  actions = status == 'Running' ? %w{ pause } : %w{ resume }
  actions << 'clear'
end

#browsable_message_countObject



35
36
37
# File 'lib/destinations/models/destination.rb', line 35

def browsable_message_count
  message_count - delivering_count
end

#clearObject



100
101
102
103
# File 'lib/destinations/models/destination.rb', line 100

def clear
  mbean.removeMessages('')
  self
end

#display_nameObject



65
66
67
# File 'lib/destinations/models/destination.rb', line 65

def display_name
  self.class.display_name( name )
end

#each(options = { }) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/destinations/models/destination.rb', line 45

def each(options = { })
  message_count = 0
  processed_messages = 0
  offset = options[:offset].to_i || 0
  limit = options[:limit] ? options[:limit].to_i : nil
  jms_destination.each do |message|
    message_count += 1
    if message_count > offset
      message = Message.new( message )
      message.parent = self
      yield message
      processed_messages += 1
    end
    return if limit and processed_messages > limit
  end
rescue Exception => ex
  Backstage.logger.warn "WARNING - failed to access messages for queue #{jndi_name}: #{ex}"
  Backstage.logger.warn ex
end

#jms_destinationObject



39
40
41
42
43
# File 'lib/destinations/models/destination.rb', line 39

def jms_destination
  @jms_destination ||= TorqueBox::Messaging::Queue.new( jndi_name )
  @jms_destination.enumerable_options = enumerable_options
  @jms_destination
end

#jndi_nameObject



69
70
71
72
73
# File 'lib/destinations/models/destination.rb', line 69

def jndi_name
  jndi_name = name.gsub( self.class.jms_prefix, '' )
  jndi_name = "/queue/#{jndi_name}" if %w{ DLQ ExpiryQueue }.include?( jndi_name )
  jndi_name
end

#pauseObject



90
91
92
93
# File 'lib/destinations/models/destination.rb', line 90

def pause
  super
  self
end

#resumeObject



95
96
97
98
# File 'lib/destinations/models/destination.rb', line 95

def resume
  super
  self
end

#statusObject



105
106
107
# File 'lib/destinations/models/destination.rb', line 105

def status
  mbean.paused ? 'Paused' : 'Running'
end