require 'flydata/source' require 'flydata/source/component' require 'flydata/source/errors' module Flydata module Source class Sync < Component def self.inherited(child_class) Source.register(child_class, self) end # Public Interface: Set up data source # # Called right after the source instance is created. Perform one-time setup # which is necessary to initialize the source for sync (and sync only) # # Raises exception when the source does not support sync def setup raise UnsupportedSourceError,"subclass must implement" end # Public Interface: Tells if the source support sync or not # # Returns true if the source supports sync. No otherwise. def supported? raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Table lists # # Returns lists of tables in a hash. The following lists will be returned # "tables" : An array of tables currently in sync # "new_tables" : An array of tables for which no generate_table_ddl has been run yet # "invalid_tables" : An array of tables that had an issue starting sync def table_lists raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Data Servers # # Returns a comma separated list of data servers to which the agent sends data def data_servers raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Forwarder # # Returns a forwarder type in string. Values are 'tcpforwarder' or 'sslforwarder'. def forwarder raise UnsupportedSourceError, "subclass must implement" end private def setup_table_prefs(prefs) if prefs['tables_append_only'] prefs['tables_append_only'] = prefs['tables_append_only'].split(/(?:\s*,\s*|\s+)/).uniq prefs['tables'] = (prefs['tables'].to_s.split(/(?:\s*,\s*|\s+)/) + prefs['tables_append_only']).uniq else prefs['tables'] = prefs['tables'].to_s.split(/(?:\s*,\s*|\s+)/).uniq end prefs['invalid_tables'] = prefs['invalid_tables'].kind_of?(String) ? prefs['invalid_tables'].split(/(?:\s*,\s*|\s+)/).uniq : [] prefs['new_tables'] = prefs['new_tables'].kind_of?(String) ? prefs['new_tables'].split(/(?:\s*,\s*|\s+)/).uniq : [] end end end end