Module: LogStash::Filters::ElasticIntegration::EventApiBridge

Defined in:
lib/logstash/filters/elastic_integration/event_api_bridge.rb

Overview

This module contains methods for bridging the gap between the Ruby-API [LogStash::Event] and its Java-API [co.elastic.logstash.api.Event] counterpart, producing bidirectional zero-copy views of one API for use with the other API.

Instance Method Summary collapse

Instance Method Details

#java_events_as_ruby(java_events) ⇒ Array[LogStash::Event]

Converts a collection of Java-API events into a collection of Ruby-API events.

Parameters:

  • java_events (Array[co.elastic.logstash.api.Event])

Returns:

  • (Array[LogStash::Event])


35
36
37
38
39
# File 'lib/logstash/filters/elastic_integration/event_api_bridge.rb', line 35

def java_events_as_ruby(java_events)
  java_events.map do |java_event|
    mutable_ruby_view_of_java_event(java_event)
  end
end

#mutable_java_view_of_ruby_event(ruby_api_event) ⇒ co.elastic.logstash.api.Event

Returns the Java-API event that backs the provided Ruby-API event. Mutations to the Java-API event are reflected by the Ruby-API event.

Parameters:

  • ruby_api_event (LogStash::Event)

Returns:

  • (co.elastic.logstash.api.Event)


47
48
49
# File 'lib/logstash/filters/elastic_integration/event_api_bridge.rb', line 47

def mutable_java_view_of_ruby_event(ruby_api_event)
  ruby_api_event.to_java
end

#mutable_ruby_view_of_java_event(java_api_event) ⇒ LogStash::Event

Returns a Ruby-API event that is backed by the provided Java-API event. Mutations to the Ruby-API event directly modify the underlying Java-API event.

Parameters:

  • java_api_event (co.elastic.logstash.api.Event)

Returns:

  • (LogStash::Event)


63
64
65
# File 'lib/logstash/filters/elastic_integration/event_api_bridge.rb', line 63

def mutable_ruby_view_of_java_event(java_api_event)
  org.logstash.ext.JrubyEventExtLibrary::RubyEvent.newRubyEvent(RUBY_RUNTIME, java_api_event)
end

#ruby_events_as_java(ruby_events) ⇒ Array[co.elastic.logstash.api.Event]

Converts a collection of Ruby-API events into a collection of Java-API events.

Parameters:

  • ruby_events (Array[LogStash::Event])

Returns:

  • (Array[co.elastic.logstash.api.Event])


23
24
25
26
27
# File 'lib/logstash/filters/elastic_integration/event_api_bridge.rb', line 23

def ruby_events_as_java(ruby_events)
  ruby_events.map do |ruby_event|
    mutable_java_view_of_ruby_event(ruby_event)
  end
end