Skip to content

Commit

Permalink
Refactor according to feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Oct 9, 2023
1 parent 367bf8a commit cd170c1
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package co.elastic.apm.agent.bci;

import co.elastic.apm.agent.bci.bytebuddy.MatcherTimer;
import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.sdk.logging.Logger;
Expand All @@ -28,7 +28,7 @@
import java.util.ArrayList;
import java.util.Collections;

public class InstrumentationStatsLifecycleListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
public class InstrumentationStatsLifecycleListener extends AbstractLifecycleListener implements InitLifecycleListener {
private static final Logger logger = LoggerFactory.getLogger(InstrumentationStatsLifecycleListener.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;

import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.report.serialize.DslJsonSerializer;
Expand All @@ -44,7 +44,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ApmServerConfigurationSource extends AbstractConfigurationSource implements InitializableLifecycleListener {
public class ApmServerConfigurationSource extends AbstractConfigurationSource implements InitLifecycleListener {

// log correlation is enabled by default in Java agent, thus removing it from warnings
private static final Set<String> IGNORED_REMOTE_KEYS = Collections.singleton("enable_log_correlation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;

import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.configuration.TimeDuration;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
Expand All @@ -39,7 +39,7 @@
* under Apache license 2.0.
* </p>
*/
public class StartupInfo extends AbstractLifecycleListener implements InitializableLifecycleListener {
public class StartupInfo extends AbstractLifecycleListener implements InitLifecycleListener {

private static final Logger logger = LoggerFactory.getLogger(StartupInfo.class);
private final String elasticApmVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.LifecycleListener;

public interface InitializableLifecycleListener extends LifecycleListener {
public interface InitLifecycleListener extends LifecycleListener {

/**
* Callback for tracer initialization. As opposed to {@link LifecycleListener#start()}, which may
* be called in a delay, this callback is called at the bootstrap of the JVM, before anything else start.
* be called in a delay, this callback is called at the bootstrap of the JVM, before anything else starts.
* This may be useful for listeners that need to operate very early on, for example such that setup class loading
* requirement to support OSGi systems.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.configuration.ServerlessConfiguration;
import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.report.serialize.DslJsonDataWriter;
import co.elastic.apm.agent.tracer.reporting.DataWriter;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
Expand Down Expand Up @@ -680,9 +680,9 @@ public List<ActivationListener> getActivationListeners() {
void init(List<LifecycleListener> lifecycleListeners) {
this.lifecycleListeners.addAll(lifecycleListeners);
for (LifecycleListener lifecycleListener : lifecycleListeners) {
if (lifecycleListener instanceof InitializableLifecycleListener) {
if (lifecycleListener instanceof InitLifecycleListener) {
try {
((InitializableLifecycleListener) lifecycleListener).init(this);
((InitLifecycleListener) lifecycleListener).init(this);
} catch (Exception e) {
logger.error("Failed to init " + lifecycleListener.getClass().getName(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
package co.elastic.apm.agent.logging;

import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.tracer.LifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.report.Reporter;
import co.elastic.logging.log4j2.EcsLayout;
Expand Down Expand Up @@ -101,8 +100,8 @@ public void append(LogEvent event) {
sendLogEvent(event);
}

public InitializableLifecycleListener getInitListener() {
class InitListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
public InitLifecycleListener getInitListener() {
class InitListener extends AbstractLifecycleListener implements InitLifecycleListener {
@Override
public void init(ElasticApmTracer tracer) {
initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.getReporter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.agent.MockReporter;
import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.configuration.SpyConfiguration;
import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.objectpool.TestObjectPoolFactory;
import net.bytebuddy.agent.ByteBuddyAgent;
Expand Down Expand Up @@ -141,7 +141,7 @@ void testStartDisabled() throws Exception {
ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("enabled", "false"));
final AtomicBoolean initialized = new AtomicBoolean();
final AtomicBoolean started = new AtomicBoolean();
class TestListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
class TestListener extends AbstractLifecycleListener implements InitLifecycleListener {
@Override
public void init(ElasticApmTracer tracer) {
initialized.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* {@code src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener}.
* </p>
* <p>
* Implementations may have a constructor with a {@link co.elastic.apm.agent.tracer.Tracer} argument
* Implementations may have a constructor with a {@link Tracer} argument
* </p>
* <p>
* Listeners are instantiated before the {@link GlobalTracer} is initiated. To get hold of an instance,
Expand All @@ -38,12 +38,12 @@
public interface LifecycleListener {

/**
* Callback for when the {@link co.elastic.apm.agent.tracer.Tracer} starts.
* Callback for when the {@link Tracer} starts.
*/
void start() throws Exception;

/**
* Callback for when {@link co.elastic.apm.agent.tracer.Tracer} has been paused.
* Callback for when {@link Tracer} has been paused.
* <p>
* Typically, this method is used to reduce overhead on the application to a minimum. This can be done by cleaning
* up resources like object pools, as well as by avoiding tracing-related overhead.
Expand Down

0 comments on commit cd170c1

Please sign in to comment.