class SwitchableApplicationListener<E extends ApplicationEvent>
                                                                                implements
                                                                                ApplicationListener<E> {

    protected static final String CONFIG_KEY_PREFIX = "sofa.boot.switch.listener.";

    @Override
    public void onApplicationEvent(E event) {<FILL_FUNCTION_BODY>}

    protected abstract void doOnApplicationEvent(E event);

    /**
     * sofa.boot.switch.listener
     *
     * @return switch key, must not be null.
     */
    protected abstract String switchKey();

    /**
     * Specify if the condition should match if the property is not set. Defaults to
     * {@code true}.
     *
     * @return if the condition should match if the property is missing
     */
    protected boolean matchIfMissing() {
        return true;
    }

    protected boolean isEnable(Environment environment) {
        String switchKey = switchKey();
        Assert.hasText(switchKey, "switch key must has text.");
        String realKey = CONFIG_KEY_PREFIX + switchKey + ".enabled";
        String switchStr = environment.getProperty(realKey);
        if (StringUtils.hasText(switchStr)) {
            return Boolean.parseBoolean(switchStr);
        } else {
            return matchIfMissing();
        }
    }
}

        ApplicationContext applicationContext = null;
        Environment environment = null;
        if (event instanceof ApplicationContextEvent applicationContextEvent) {
            applicationContext = applicationContextEvent.getApplicationContext();
        } else if (event instanceof ApplicationContextInitializedEvent applicationContextInitializedEvent) {
            applicationContext = applicationContextInitializedEvent.getApplicationContext();
        } else if (event instanceof ApplicationEnvironmentPreparedEvent environmentPreparedEvent) {
            environment = environmentPreparedEvent.getEnvironment();
        } else if (event instanceof ApplicationPreparedEvent applicationPreparedEvent) {
            applicationContext = applicationPreparedEvent.getApplicationContext();
        } else if (event instanceof ApplicationReadyEvent applicationReadyEvent) {
            applicationContext = applicationReadyEvent.getApplicationContext();
        } else if (event instanceof ApplicationStartedEvent applicationStartedEvent) {
            applicationContext = applicationStartedEvent.getApplicationContext();
        } else if (event instanceof ApplicationFailedEvent applicationFailedEvent) {
            applicationContext = applicationFailedEvent.getApplicationContext();
        }
        if (environment == null && applicationContext != null) {
            environment = applicationContext.getEnvironment();
        }
        if (environment != null) {
            if (isEnable(environment)) {
                doOnApplicationEvent(event);
            }
        } else {
            doOnApplicationEvent(event);
        }
    
<no_super_class>