Skip to content

Commit

Permalink
JAVAFICATION: Port Snapshot to Java
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed May 28, 2018
1 parent 7d6acf1 commit 1a88b9e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
1 change: 0 additions & 1 deletion logstash-core/lib/logstash/instrument/collector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require "logstash/instrument/snapshot"
require "logstash/instrument/metric_store"
require "concurrent/timer_task"
require "observer"
Expand Down
14 changes: 0 additions & 14 deletions logstash-core/lib/logstash/instrument/snapshot.rb

This file was deleted.

6 changes: 6 additions & 0 deletions logstash-core/src/main/java/org/logstash/RubyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.logstash.instrument.metrics.NamespacedMetricExt;
import org.logstash.instrument.metrics.NullMetricExt;
import org.logstash.instrument.metrics.NullNamespacedMetricExt;
import org.logstash.instrument.metrics.SnapshotExt;
import org.logstash.log.LoggableExt;
import org.logstash.log.LoggerExt;
import org.logstash.log.SlowLoggerExt;
Expand Down Expand Up @@ -124,6 +125,8 @@ public final class RubyUtil {

public static final RubyClass METRIC_NO_NAMESPACE_PROVIDED_CLASS;

public static final RubyClass METRIC_SNAPSHOT_CLASS;

public static final RubyClass TIMED_EXECUTION_CLASS;

public static final RubyClass NULL_TIMED_EXECUTION_CLASS;
Expand Down Expand Up @@ -183,6 +186,9 @@ public final class RubyUtil {
PLUGINS_MODULE = RUBY.defineModuleUnder("Plugins", LOGSTASH_MODULE);
final RubyModule instrumentModule =
RUBY.defineModuleUnder("Instrument", LOGSTASH_MODULE);
METRIC_SNAPSHOT_CLASS =
instrumentModule.defineClassUnder("Snapshot", RUBY.getObject(), SnapshotExt::new);
METRIC_SNAPSHOT_CLASS.defineAnnotatedMethods(SnapshotExt.class);
EXECUTION_CONTEXT_FACTORY_CLASS = PLUGINS_MODULE.defineClassUnder(
"ExecutionContextFactory", RUBY.getObject(),
PluginFactoryExt.ExecutionContext::new
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.logstash.instrument.metrics;

import org.jruby.Ruby;
import org.jruby.RubyBasicObject;
import org.jruby.RubyClass;
import org.jruby.RubyTime;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

@JRubyClass(name = "Snapshot")
public final class SnapshotExt extends RubyBasicObject {

private IRubyObject metricStore;

private RubyTime createdAt;

public SnapshotExt(final Ruby runtime, final RubyClass metaClass) {
super(runtime, metaClass);
}

@JRubyMethod(required = 1, optional = 1)
public SnapshotExt initialize(final ThreadContext context, final IRubyObject[] args) {
metricStore = args[0];
if (args.length == 2) {
createdAt = (RubyTime) args[1];
} else {
createdAt = (RubyTime) RubyTime.newInstance(context, context.runtime.getTime());
}
return this;
}

@JRubyMethod(name = "metric_store")
public IRubyObject metricStore() {
return metricStore;
}

@JRubyMethod(name = "created_at")
public RubyTime createdAt() {
return createdAt;
}
}

0 comments on commit 1a88b9e

Please sign in to comment.