Skip to content

Commit

Permalink
Introduce system property to disable JFR support #1767
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jun 9, 2021
1 parent 5306ee6 commit cacdfc6
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/main/java/io/lettuce/core/event/jfr/EventRecorderHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package io.lettuce.core.event.jfr;

import io.lettuce.core.internal.LettuceClassUtils;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/**
* Holder for {@link EventRecorder}.
Expand All @@ -25,8 +28,34 @@
*/
class EventRecorderHolder {

private static final boolean JFR_AVAILABLE = LettuceClassUtils.isPresent("jdk.jfr.Event");
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EventRecorderHolder.class);

static final EventRecorder EVENT_RECORDER = JFR_AVAILABLE ? new JfrEventRecorder() : NoOpEventRecorder.INSTANCE;
private static final String JFR_ENABLED_KEY = "io.lettuce.core.jfr";

private static final boolean JFR_ENABLED = Boolean.parseBoolean(SystemPropertyUtil.get(JFR_ENABLED_KEY, "true"));

static final EventRecorder EVENT_RECORDER;

static {

boolean available = LettuceClassUtils.isPresent("jdk.jfr.Event");
EventRecorder eventRecorder = NoOpEventRecorder.INSTANCE;

if (available) {

if (JFR_ENABLED) {
logger.debug("Starting with JFR support");
eventRecorder = new JfrEventRecorder();
} else {
logger.debug(
String.format("Starting without optional JFR support. JFR use is disabled via System properties (%s)",
JFR_ENABLED_KEY));
}
} else {
logger.debug("Starting without optional JFR support. JFR unavailable.");
}

EVENT_RECORDER = eventRecorder;
}

}

0 comments on commit cacdfc6

Please sign in to comment.