Class: Embulk::InputPlugin::JavaAdapter

Inherits:
Object
  • Object
show all
Includes:
Java::InputPlugin
Defined in:
embulk-core/src/main/ruby/embulk/input_plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(ruby_class) ⇒ JavaAdapter

Returns a new instance of JavaAdapter



52
53
54
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 52

def initialize(ruby_class)
  @ruby_class = ruby_class
end

Instance Method Details

#cleanup(java_task_source, java_schema, task_count, java_task_reports) ⇒ Object



85
86
87
88
89
90
91
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 85

def cleanup(java_task_source, java_schema, task_count, java_task_reports)
  task_source = DataSource.from_java(java_task_source)
  schema = Schema.from_java(java_schema)
  task_reports = java_task_reports.map {|c| DataSource.from_java(c) }
  @ruby_class.cleanup(task_source, schema, task_count, task_reports)
  return nil
end

#guess(java_config) ⇒ Object



93
94
95
96
97
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 93

def guess(java_config)
  config = DataSource.from_java(java_config)
  config_diff_hash = @ruby_class.guess(config)
  return DataSource.from_ruby_hash(config_diff_hash).to_java
end

#resume(java_task_source, java_schema, task_count, java_control) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 70

def resume(java_task_source, java_schema, task_count, java_control)
  task_source = DataSource.from_java(java_task_source)
  schema = Schema.from_java(java_schema)
  config_diff_hash = @ruby_class.resume(task_source, schema, task_count) do |task_source_hash,columns,task_count|
    java_task_source = DataSource.from_ruby_hash(task_source_hash).to_java
    java_schema = Schema.new(columns).to_java
    java_task_reports = java_control.run(java_task_source, java_schema, task_count)
    java_task_reports.map {|java_task_report|
      DataSource.from_java(java_task_report)
    }
  end
  # TODO check return type of #resume
  return DataSource.from_ruby_hash(config_diff_hash).to_java
end

#run(java_task_source, java_schema, processor_index, java_output) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 99

def run(java_task_source, java_schema, processor_index, java_output)
  task_source = DataSource.from_java(java_task_source)
  schema = Schema.from_java(java_schema)
  page_builder = @ruby_class.create_page_builder(task_source: task_source,
                                                 schema: schema,
                                                 processor_index: processor_index,
                                                 java_page_output: java_output)
  begin
    task_report_hash = @ruby_class.new(task_source, schema, processor_index, page_builder).run
    return DataSource.from_ruby_hash(task_report_hash).to_java
  ensure
    page_builder.close
  end
end

#transaction(java_config, java_control) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'embulk-core/src/main/ruby/embulk/input_plugin.rb', line 56

def transaction(java_config, java_control)
  config = DataSource.from_java(java_config)
  config_diff_hash = @ruby_class.transaction(config) do |task_source_hash,columns,task_count|
    java_task_source = DataSource.from_ruby_hash(task_source_hash).to_java
    java_schema = Schema.new(columns).to_java
    java_task_reports = java_control.run(java_task_source, java_schema, task_count)
    java_task_reports.map {|java_task_report|
      DataSource.from_java(java_task_report)
    }
  end
  # TODO check return type of #transaction
  return DataSource.from_ruby_hash(config_diff_hash).to_java
end