Class: VORuby::Simple::QueryExecutor
Overview
Executes a series of queries, each in its own thread. Typical use might be something like this:
# Convert the query results into an object representation.
objectifier = Proc.new { |query|
query.marshall().votable().votable()
}
# Prepare a SIAP query
nsa_siap = Simple::ImageAccess.new('http://archive.noao.edu/nvo/sim/voquery.php',
'23:00:00, 2:00:00', 7, nil, 30, 'rexml')
# Prepare a SSAP query
iso_ssap = Simple::SpectralAccess.new('http://pma.iso.vilspa.esa.es:8080/aio/jsp/siap.jsp',
‘53.084, -27.873’, 10, => ‘votable’, 30, ‘rexml’)
# Prepare a cone search query
mast_cone = Simple::ConeSearch.new('http://archive.stsci.edu/hst/search.php',
53.084, -27.873, 0.01, nil, 30, ‘rexml’)
# Execute the queries asynchronously.
Simple::QueryExecutor.new([nsa_siap, iso_ssap, mast_cone], objectifier).results().each do |query, votable|
# Just to prove things are working, output the list of field UCDs for each table.
puts "#{query.to_s()}..."
votable.fields().each do |field|
puts "#{field.id()}, #{field.name()}, #{field.ucd().value() if field.ucd() != nil}"
end
votable.rows().each do |row|
puts row
end
puts "\n"
end
Instance Attribute Summary collapse
-
#converter ⇒ Object
Returns the value of attribute converter.
-
#queries ⇒ Object
Returns the value of attribute queries.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#begin_queries ⇒ Object
Kick off each query into its own thread.
-
#initialize(queries = [], converter = Proc.new{|qo| qo}, abort_on_exception = false) ⇒ QueryExecutor
constructor
- queries:
-
A list of valid query objects.
Constructor Details
#initialize(queries = [], converter = Proc.new{|qo| qo}, abort_on_exception = false) ⇒ QueryExecutor
- queries:
-
A list of valid query objects. Good examples of these are:
-
Simple::SpectralAccess (Simple Spectral Access Protocol queries)
-
Simple::ImageAccess (Simple Image Access Protocol queries)
-
Simple::ConeSearch (Simple Cone Search queries)
-
- converter:
-
An anonymous subroutine that can be used to convert the result of a query into another form–often a VOTABLE::VOTable for our purposes. By default, it simply returns the completed query.
- abort_on_exeception:
-
A flag which indicates whether or not if one query fails, the other queries should abort, too.
Each query must also have a fetch method. One way to get this is to mixin the Simple::HTTPGetQuery module.
57 58 59 60 61 62 63 64 |
# File 'lib/voruby/simple/sap.rb', line 57 def initialize(queries=[], converter=Proc.new{|qo| qo}, abort_on_exception=false) @queries = queries @converter = converter Thread::abort_on_exception = abort_on_exception @results = {} begin_queries() end |
Instance Attribute Details
#converter ⇒ Object
Returns the value of attribute converter.
40 41 42 |
# File 'lib/voruby/simple/sap.rb', line 40 def converter @converter end |
#queries ⇒ Object
Returns the value of attribute queries.
40 41 42 |
# File 'lib/voruby/simple/sap.rb', line 40 def queries @queries end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
41 42 43 |
# File 'lib/voruby/simple/sap.rb', line 41 def results @results end |
Instance Method Details
#begin_queries ⇒ Object
Kick off each query into its own thread.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/voruby/simple/sap.rb', line 67 def begin_queries threads = [] # Place each query in its own thread. queries.each do |query| threads << Thread.new(query){ |the_query| the_query.fetch() # Convert the query into something (maybe itself). @results[the_query] = converter.call(the_query) } end # Make sure each thread finishes before the program # exits. threads.each{ |thread| thread.join() } end |