/*
 * Copyright 2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.lettuce.core.event.jfr;

import io.lettuce.core.internal.LettuceClassUtils;

/**
 * Holder for {@link EventRecorder}.
 *
 * @author Mark Paluch
 * @since 6.1
 */
class EventRecorderHolder {

    private static final boolean JFR_AVAILABLE = LettuceClassUtils.isPresent("jdk.jfr.Event");

    static final EventRecorder EVENT_RECORDER = JFR_AVAILABLE ? new JfrEventRecorder() : NoOpEventRecorder.INSTANCE;

}

@@ -701,169 +701,680 @@
 ls;%0A
-%0A/**%0A * Holder for %7B@link EventRecorder%7D.%0A *%0A * @author Mark Paluch%0A * @since 6.1%0A */%0Aclass EventRecorderHolder %7B%0A%0A    private static final boolean JFR_AVAILABLE
+import io.netty.util.internal.SystemPropertyUtil;%0Aimport io.netty.util.internal.logging.InternalLogger;%0Aimport io.netty.util.internal.logging.InternalLoggerFactory;%0A%0A/**%0A * Holder for %7B@link EventRecorder%7D.%0A *%0A * @author Mark Paluch%0A * @since 6.1%0A */%0Aclass EventRecorderHolder %7B%0A%0A    private static final InternalLogger logger = InternalLoggerFactory.getInstance(EventRecorderHolder.class);%0A%0A    private static final String JFR_ENABLED_KEY = %22io.lettuce.core.jfr%22;%0A%0A    private static final boolean JFR_ENABLED = Boolean.parseBoolean(SystemPropertyUtil.get(JFR_ENABLED_KEY, %22true%22));%0A%0A    static final EventRecorder EVENT_RECORDER;%0A%0A    static %7B%0A%0A        boolean available
  = L
@@ -1422,125 +1422,648 @@
 %22);%0A
-%0A
+  
     
-static final EventRecorder EVENT_RECORDER = JFR_AVAILABLE ? new JfrEventRecorder() : NoOpEventRecorder.INSTANCE;
+  EventRecorder eventRecorder = NoOpEventRecorder.INSTANCE;%0A%0A        if (available) %7B%0A%0A            if (JFR_ENABLED) %7B%0A                logger.debug(%22Starting with JFR support%22);%0A                eventRecorder = new JfrEventRecorder();%0A            %7D else %7B%0A                logger.debug(%0A                        String.format(%22Starting without optional JFR support. JFR use is disabled via System properties (%25s)%22,%0A                                JFR_ENABLED_KEY));%0A            %7D%0A        %7D else %7B%0A            logger.debug(%22Starting without optional JFR support. JFR unavailable.%22);%0A        %7D%0A%0A        EVENT_RECORDER = eventRecorder;%0A    %7D
 %0A%0A%7D%0A

Introduce system property to disable JFR support #1767