class Aspera::Fasp::Manager
Base class for FASP transfer agents sub classes shall implement start_transfer and shutdown
Constants
- BooleanFields
- ExpectedMethod
- IntegerFields
fields description for JSON generation
- LISTENER_SESSION_ID_B
- LISTENER_SESSION_ID_S
Public Class Methods
new()
click to toggle source
# File lib/aspera/fasp/manager.rb, line 31 def initialize @listeners=[] end
validate_status_list(statuses)
click to toggle source
This checks the validity of the value returned by wait_for_transfers_completion it must be a list of :success or exception
# File lib/aspera/fasp/manager.rb, line 78 def self.validate_status_list(statuses) raise "internal error: bad statuses type: #{statuses.class}" unless statuses.is_a?(Array) raise "internal error: bad statuses content: #{statuses}" unless statuses.select{|i|!i.eql?(:success) and !i.is_a?(StandardError)}.empty? end
Public Instance Methods
add_listener(listener)
click to toggle source
listener receives events
# File lib/aspera/fasp/manager.rb, line 65 def add_listener(listener) raise "expect one of #{ExpectedMethod}" if ExpectedMethod.inject(0){|m,e|m+=listener.respond_to?("event_#{e}")?1:0;m}.eql?(0) @listeners.push(listener) self end
Private Instance Methods
enhanced_event_format(event)
click to toggle source
translates legacy event into enhanced (JSON) event
# File lib/aspera/fasp/manager.rb, line 15 def enhanced_event_format(event) return event.keys.inject({}) do |h,e| # capital_to_snake_case new_name=e. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). gsub(/([a-z\d])(usec)$/,'\1_\2'). downcase value=event[e] value=value.to_i if IntegerFields.include?(e) value=value.eql?('Yes') ? true : false if BooleanFields.include?(e) h[new_name]=value h end end
notify_begin(id,size)
click to toggle source
# File lib/aspera/fasp/manager.rb, line 48 def notify_begin(id,size) notify_listeners('emulated',{LISTENER_SESSION_ID_B=>id,'Type'=>'NOTIFICATION','PreTransferBytes'=>size}) end
notify_end(id)
click to toggle source
# File lib/aspera/fasp/manager.rb, line 56 def notify_end(id) notify_listeners('emulated',{LISTENER_SESSION_ID_B=>id,'Type'=>'DONE'}) end
notify_listeners(current_event_text,current_event_data)
click to toggle source
# File lib/aspera/fasp/manager.rb, line 35 def notify_listeners(current_event_text,current_event_data) Log.log.debug("send event to listeners") enhanced_event=nil @listeners.each do |listener| listener.send(:event_text,current_event_text) if listener.respond_to?(:event_text) listener.send(:event_struct,current_event_data) if listener.respond_to?(:event_struct) if listener.respond_to?(:event_enhanced) enhanced_event=enhanced_event_format(current_event_data) if enhanced_event.nil? listener.send(:event_enhanced,enhanced_event) end end end
notify_progress(id,size)
click to toggle source
# File lib/aspera/fasp/manager.rb, line 52 def notify_progress(id,size) notify_listeners('emulated',{LISTENER_SESSION_ID_B=>id,'Type'=>'STATS','Bytescont'=>size}) end