From f4ce79adf4b011db9d96afdc560e355c49f57f5f Mon Sep 17 00:00:00 2001 From: anton Date: Sun, 16 Jun 2024 18:25:34 +0400 Subject: [PATCH] fixes --- build.gradle.kts | 2 +- .../io/art/core/graal/GraalCoreFeature.java | 9 +- .../core/graal/GraalNativeRegistrator.java | 32 ++-- .../io.art.core/native-image.properties | 3 +- gradle.properties | 38 ++--- metrics/build.gradle.kts | 41 ----- .../MetricModuleConfiguration.java | 56 ------- .../PrometheusRegistryConfigurator.java | 65 -------- .../constants/MetricsModuleConstants.java | 34 ---- .../DropwizardMetricRegistryFactory.java | 43 ----- .../io/art/metrics/module/MetricsModule.java | 48 ------ settings.gradle.kts | 1 - .../graal/feature/GraalNettyFeature.java | 1 - .../GraalNettySubstitutions.java | 147 ++---------------- .../io.art.transport/native-image.properties | 3 +- 15 files changed, 53 insertions(+), 470 deletions(-) delete mode 100644 metrics/build.gradle.kts delete mode 100644 metrics/src/main/java/io/art/metrics/configuration/MetricModuleConfiguration.java delete mode 100644 metrics/src/main/java/io/art/metrics/configurator/PrometheusRegistryConfigurator.java delete mode 100644 metrics/src/main/java/io/art/metrics/constants/MetricsModuleConstants.java delete mode 100644 metrics/src/main/java/io/art/metrics/factory/DropwizardMetricRegistryFactory.java delete mode 100644 metrics/src/main/java/io/art/metrics/module/MetricsModule.java diff --git a/build.gradle.kts b/build.gradle.kts index 4056eba22..9492809c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ plugins { group = "io.art.java" tasks.withType(type = Wrapper::class) { - gradleVersion = "7.2" + gradleVersion = "8.5" } generator { diff --git a/core/src/main/java/io/art/core/graal/GraalCoreFeature.java b/core/src/main/java/io/art/core/graal/GraalCoreFeature.java index db941a314..746f88d9f 100644 --- a/core/src/main/java/io/art/core/graal/GraalCoreFeature.java +++ b/core/src/main/java/io/art/core/graal/GraalCoreFeature.java @@ -1,11 +1,10 @@ package io.art.core.graal; -import com.oracle.svm.core.annotate.*; -import org.graalvm.nativeimage.hosted.*; -import static io.art.core.constants.GraalConstants.*; -import static io.art.core.graal.GraalNativeRegistrator.*; +import org.graalvm.nativeimage.hosted.Feature; + +import static io.art.core.constants.GraalConstants.GRAAL_NATIVE_CORE_CLASSES; +import static io.art.core.graal.GraalNativeRegistrator.registerForNativeUsage; -@AutomaticFeature public class GraalCoreFeature implements Feature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { diff --git a/core/src/main/java/io/art/core/graal/GraalNativeRegistrator.java b/core/src/main/java/io/art/core/graal/GraalNativeRegistrator.java index 61d46bf1c..086ab4cfe 100644 --- a/core/src/main/java/io/art/core/graal/GraalNativeRegistrator.java +++ b/core/src/main/java/io/art/core/graal/GraalNativeRegistrator.java @@ -1,17 +1,21 @@ package io.art.core.graal; -import com.oracle.svm.core.jdk.*; -import com.oracle.svm.core.jni.*; -import com.oracle.svm.hosted.*; -import com.oracle.svm.hosted.c.*; -import lombok.experimental.*; -import org.graalvm.nativeimage.hosted.Feature.*; -import org.graalvm.nativeimage.hosted.*; -import static com.oracle.svm.hosted.FeatureImpl.*; -import static io.art.core.checker.NullityChecker.*; -import static io.art.core.graal.GraalNativeLibraryConfiguration.Type.*; -import java.lang.reflect.*; -import java.util.*; +import com.oracle.svm.core.jdk.NativeLibrarySupport; +import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; +import com.oracle.svm.core.jni.JNIRuntimeAccess; +import com.oracle.svm.hosted.FeatureImpl; +import com.oracle.svm.hosted.c.NativeLibraries; +import io.art.core.checker.NullityChecker; +import lombok.experimental.UtilityClass; +import org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess; +import org.graalvm.nativeimage.hosted.RuntimeReflection; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; + +import static io.art.core.graal.GraalNativeLibraryConfiguration.Type.STATIC; @UtilityClass public class GraalNativeRegistrator { @@ -57,13 +61,13 @@ public static void registerForNativeUsage(Class owner) { public static void registerNativeLibraries(BeforeAnalysisAccess access, GraalNativeLibraryConfiguration... libraries) { NativeLibrarySupport nativeLibrarySupport = NativeLibrarySupport.singleton(); PlatformNativeLibrarySupport platformNativeLibrarySupport = PlatformNativeLibrarySupport.singleton(); - NativeLibraries nativeLibraries = ((BeforeAnalysisAccessImpl) access).getNativeLibraries(); + NativeLibraries nativeLibraries = ((FeatureImpl.BeforeAnalysisAccessImpl) access).getNativeLibraries(); Collection libraryPaths = nativeLibraries.getLibraryPaths(); for (GraalNativeLibraryConfiguration library : libraries) { libraryPaths.add(library.getLocation().resolve().toString()); if (library.isBuiltin() && library.getType() == STATIC) { nativeLibrarySupport.preregisterUninitializedBuiltinLibrary(library.getName()); - forEach(library.getBuiltinSymbolPrefixes(), platformNativeLibrarySupport::addBuiltinPkgNativePrefix); + NullityChecker.forEach(library.getBuiltinSymbolPrefixes(), platformNativeLibrarySupport::addBuiltinPkgNativePrefix); nativeLibraries.addStaticJniLibrary(library.getName()); continue; } diff --git a/core/src/main/resources/META-INF/native-image/io.art.core/native-image.properties b/core/src/main/resources/META-INF/native-image/io.art.core/native-image.properties index 70580a50b..94559109b 100644 --- a/core/src/main/resources/META-INF/native-image/io.art.core/native-image.properties +++ b/core/src/main/resources/META-INF/native-image/io.art.core/native-image.properties @@ -1,2 +1,3 @@ Args=-H:ReflectionConfigurationResources=${.}/reflection-config.json \ - --initialize-at-build-time=sun.instrument.InstrumentationImpl + --features\=io.art.core.graal.GraalCoreFeature \ + --initialize-at-build-time=sun.instrument.InstrumentationImpl diff --git a/gradle.properties b/gradle.properties index a741ec4d2..11c96c511 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,30 +21,22 @@ org.gradle.parallel=true org.gradle.jvmargs=-Xms1g -Xmx1g -XX:MetaspaceSize=1g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2 # External dependency versions -jacksonVersion=2.10.+ -lombokVersion=1.18.+ -sl4jVersion=1.7.+ +jacksonVersion=2.17.1 +lombokVersion=1.18.32 +sl4jVersion=1.7.9 guavaVersion=28.1-jre -reactorVersion=3.4.+ -reactorNettyVersion=1+ -rsocketVersion=1+ +reactorVersion=3.6.7 +reactorNettyVersion=1.1.20 +rsocketVersion=1.1.4 tarantoolCartridgeConnectorVersion=0.3.3 -messagePackVersion=0.8.+ -vavrVersion=0.10.+ -nettyVersion=4.1.69.Final -dropwizardVersion=1.3.+ -metricsDropwizVersion=4.0.+ -micrometerPrometheusVersion=1.+ -micrometerJvmExtrasVersion=0.1.4 -prometheusDropwizardSimpleClient=0.7+ -dropwizardMetricsVersion=4.0.+ -dropwizrdMetricsJvmVersion=4.1+ -prometheusSimpleClientVersion=0.9+ -graalVersion=21.3.0 +messagePackVersion=0.9.8 +vavrVersion=0.10.4 +nettyVersion=4.1.111.Final +graalVersion=24.0.1 jctoolsVersion=3.3.0 -lz4Version=1.7.+ -jetbrainsAnnotationsVersion=21.+ -junitVersion=5.+ -junitPlatformVersion=1.7.+ +lz4Version=1.8.0 +jetbrainsAnnotationsVersion=24.1.0 +junitVersion=5.10.2 +junitPlatformVersion=1.10.2 jmhVersion=0.6.4 -internalPluginVersion=main +internalPluginVersion=main \ No newline at end of file diff --git a/metrics/build.gradle.kts b/metrics/build.gradle.kts deleted file mode 100644 index 1bfee6687..000000000 --- a/metrics/build.gradle.kts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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. - */ - -dependencies { - val micrometerPrometheusVersion: String by project - val micrometerJvmExtrasVersion: String by project - val prometheusSimpleClientVersion: String by project - val dropwizrdMetricsJvmVersion: String by project - - implementation(project(":core")) - implementation(project(":meta")) - implementation(project(":logging")) - implementation(project(":server")) - - api("io.micrometer", "micrometer-registry-prometheus", micrometerPrometheusVersion) - - api("io.github.mweirauch", "micrometer-jvm-extras", micrometerJvmExtrasVersion) - .exclude("org.slf4j") - - api("io.prometheus", "simpleclient_dropwizard", prometheusSimpleClientVersion) - .exclude("org.slf4j") - - api("io.dropwizard.metrics", "metrics-jvm", dropwizrdMetricsJvmVersion) - .exclude("io.dropwizard.metrics", "metrics-core") - .exclude("org.slf4j") -} diff --git a/metrics/src/main/java/io/art/metrics/configuration/MetricModuleConfiguration.java b/metrics/src/main/java/io/art/metrics/configuration/MetricModuleConfiguration.java deleted file mode 100644 index e315aecbb..000000000 --- a/metrics/src/main/java/io/art/metrics/configuration/MetricModuleConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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.art.metrics.configuration; - -import com.codahale.metrics.*; -import io.github.mweirauch.micrometer.jvm.extras.*; -import io.micrometer.core.instrument.binder.*; -import io.micrometer.core.instrument.binder.jvm.*; -import io.micrometer.core.instrument.binder.system.*; -import io.micrometer.prometheus.*; -import lombok.*; -import io.art.core.module.*; -import static io.micrometer.prometheus.PrometheusConfig.*; -import static io.art.core.factory.CollectionsFactory.*; -import static io.art.metrics.factory.DropwizardMetricRegistryFactory.*; -import java.util.*; - -public interface MetricModuleConfiguration extends ModuleConfiguration { - Set getMeterBinders(); - - PrometheusMeterRegistry getPrometheusMeterRegistry(); - - MetricRegistry getDropwizardMetricRegistry(); - - MetricModuleDefaultConfiguration DEFAULT_CONFIGURATION = new MetricModuleDefaultConfiguration(); - - @Getter - class MetricModuleDefaultConfiguration implements MetricModuleConfiguration { - private final Set meterBinders = setOf(new ClassLoaderMetrics(), - new JvmMemoryMetrics(), - new JvmGcMetrics(), - new ProcessorMetrics(), - new JvmThreadMetrics(), - new ProcessMemoryMetrics(), - new ProcessThreadMetrics(), - new UptimeMetrics()); - private final PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(DEFAULT); - private final MetricRegistry dropwizardMetricRegistry = createDefaultDropwizardMetricRegistry(); - } -} diff --git a/metrics/src/main/java/io/art/metrics/configurator/PrometheusRegistryConfigurator.java b/metrics/src/main/java/io/art/metrics/configurator/PrometheusRegistryConfigurator.java deleted file mode 100644 index 8207a79f1..000000000 --- a/metrics/src/main/java/io/art/metrics/configurator/PrometheusRegistryConfigurator.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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.art.metrics.configurator; - -import com.codahale.metrics.*; -import io.micrometer.prometheus.*; -import io.prometheus.client.*; -import io.prometheus.client.dropwizard.*; -import lombok.experimental.*; -import static io.micrometer.prometheus.PrometheusConfig.*; -import static io.art.metrics.constants.MetricsModuleConstants.*; -import static io.art.metrics.module.MetricsModule.*; - -@UtilityClass -public class PrometheusRegistryConfigurator { - @SuppressWarnings("Duplicates") - public static PrometheusMeterRegistry prometheusRegistryForApplication(String applicationId) { - PrometheusMeterRegistry registry = new PrometheusMeterRegistry(DEFAULT); - CollectorRegistry prometheusRegistry = registry.getPrometheusRegistry(); - prometheusRegistry.register(new DropwizardExports(metricsModule().getDropwizardMetricRegistry())); - registry.config().commonTags(MODULE_TAG, applicationId); - return registry; - } - - @SuppressWarnings("Duplicates") - public static PrometheusMeterRegistry prometheusRegistryForApplication(String applicationId, PrometheusConfig config) { - PrometheusMeterRegistry registry = new PrometheusMeterRegistry(config); - registry.getPrometheusRegistry().register(new DropwizardExports(metricsModule().getDropwizardMetricRegistry())); - registry.config().commonTags(MODULE_TAG, applicationId); - return registry; - } - - @SuppressWarnings("Duplicates") - public static PrometheusMeterRegistry prometheusRegistryForApplication(String applicationId, MetricRegistry metricRegistry) { - PrometheusMeterRegistry registry = new PrometheusMeterRegistry(DEFAULT); - CollectorRegistry prometheusRegistry = registry.getPrometheusRegistry(); - prometheusRegistry.register(new DropwizardExports(metricRegistry)); - registry.config().commonTags(MODULE_TAG, applicationId); - return registry; - } - - @SuppressWarnings("Duplicates") - public static PrometheusMeterRegistry prometheusRegistryForApplication(String applicationId, MetricRegistry metricRegistry, PrometheusConfig config) { - PrometheusMeterRegistry registry = new PrometheusMeterRegistry(config); - registry.getPrometheusRegistry().register(new DropwizardExports(metricRegistry)); - registry.config().commonTags(MODULE_TAG, applicationId); - return registry; - } -} diff --git a/metrics/src/main/java/io/art/metrics/constants/MetricsModuleConstants.java b/metrics/src/main/java/io/art/metrics/constants/MetricsModuleConstants.java deleted file mode 100644 index 02cab8e89..000000000 --- a/metrics/src/main/java/io/art/metrics/constants/MetricsModuleConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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.art.metrics.constants; - -public interface MetricsModuleConstants { - String METRICS_MODULE_ID = "METRICS_MODULE"; - String METRICS_SERVICE_ID = "METRICS_SERVICE"; - String METRICS_METHOD_ID = "GET_METRICS"; - String METRICS_PATH = "/metrics"; - String MODULE_TAG = "module"; - String GC_METRICS = "gc"; - String THREADS_METRICS = "threads"; - String MEMORY_METRICS = "memory"; - String CIRCUIT_BREAKER_METRICS = "circuit_breaker"; - String RATE_LIMITER_METRICS = "rate_limiter"; - String RETRY_METRICS = "retry"; - int THREAD_METRICS_INTERVAL_GAUGE_SET = 10; -} diff --git a/metrics/src/main/java/io/art/metrics/factory/DropwizardMetricRegistryFactory.java b/metrics/src/main/java/io/art/metrics/factory/DropwizardMetricRegistryFactory.java deleted file mode 100644 index 4a0c99159..000000000 --- a/metrics/src/main/java/io/art/metrics/factory/DropwizardMetricRegistryFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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.art.metrics.factory; - -import com.codahale.metrics.*; -import com.codahale.metrics.jvm.*; -import lombok.experimental.*; -import static io.github.resilience4j.metrics.CircuitBreakerMetrics.*; -import static io.github.resilience4j.metrics.RateLimiterMetrics.*; -import static io.github.resilience4j.metrics.RetryMetrics.*; -import static java.util.concurrent.TimeUnit.*; -import static io.art.metrics.constants.MetricsModuleConstants.*; -import static io.art.server.module.ServerModule.*; - -@UtilityClass -public class DropwizardMetricRegistryFactory { - public static MetricRegistry createDefaultDropwizardMetricRegistry() { - MetricRegistry metricRegistry = new MetricRegistry(); - metricRegistry.register(GC_METRICS, new GarbageCollectorMetricSet()); - metricRegistry.register(THREADS_METRICS, new CachedThreadStatesGaugeSet(THREAD_METRICS_INTERVAL_GAUGE_SET, SECONDS)); - metricRegistry.register(MEMORY_METRICS, new MemoryUsageGaugeSet()); - metricRegistry.register(CIRCUIT_BREAKER_METRICS, ofCircuitBreakerRegistry(serverModule().getCircuitBreakerRegistry())); - metricRegistry.register(RATE_LIMITER_METRICS, ofRateLimiterRegistry(serverModule().getRateLimiterRegistry())); - metricRegistry.register(RETRY_METRICS, ofRetryRegistry(serverModule().getRetryRegistry())); - return metricRegistry; - } -} diff --git a/metrics/src/main/java/io/art/metrics/module/MetricsModule.java b/metrics/src/main/java/io/art/metrics/module/MetricsModule.java deleted file mode 100644 index 1bd6e6244..000000000 --- a/metrics/src/main/java/io/art/metrics/module/MetricsModule.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ART - * - * Copyright 2019-2022 ART - * - * 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 - * - * http://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.art.metrics.module; - -import lombok.*; -import io.art.core.module.Module; -import io.art.core.module.*; -import io.art.metrics.configuration.*; -import static lombok.AccessLevel.*; -import static io.art.core.context.Context.*; -import static io.art.metrics.configuration.MetricModuleConfiguration.*; -import static io.art.metrics.constants.MetricsModuleConstants.*; - -@Getter -public class MetricsModule implements Module { - @Getter(lazy = true, value = PRIVATE) - private static final MetricModuleConfiguration metricsModule = context().getModule(METRICS_MODULE_ID, MetricsModule::new); - private final String id = METRICS_MODULE_ID; - private final MetricModuleConfiguration defaultConfiguration = DEFAULT_CONFIGURATION; - - public static MetricModuleConfiguration metricsModule() { - if (contextIsNotReady()) { - return DEFAULT_CONFIGURATION; - } - return getMetricsModule(); - } - - @Override - public void onLoad() { - metricsModule().getMeterBinders().forEach(meter -> meter.bindTo(metricsModule().getPrometheusMeterRegistry())); - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index e86f1ceff..4d1861ceb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,7 +34,6 @@ include("http") include("tests") include("tarantool") include("storage") -//include("metrics") pluginManagement { val internalPluginVersion: String by settings diff --git a/transport/src/main/java/io/art/transport/graal/feature/GraalNettyFeature.java b/transport/src/main/java/io/art/transport/graal/feature/GraalNettyFeature.java index 7a68eab12..c58c0dd5f 100644 --- a/transport/src/main/java/io/art/transport/graal/feature/GraalNettyFeature.java +++ b/transport/src/main/java/io/art/transport/graal/feature/GraalNettyFeature.java @@ -13,7 +13,6 @@ import static java.lang.System.*; import java.util.*; -@AutomaticFeature public class GraalNettyFeature implements Feature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { diff --git a/transport/src/main/java/io/art/transport/graal/substitutions/GraalNettySubstitutions.java b/transport/src/main/java/io/art/transport/graal/substitutions/GraalNettySubstitutions.java index 1a31dc910..6dca2654e 100644 --- a/transport/src/main/java/io/art/transport/graal/substitutions/GraalNettySubstitutions.java +++ b/transport/src/main/java/io/art/transport/graal/substitutions/GraalNettySubstitutions.java @@ -15,6 +15,7 @@ import io.netty.util.*; import io.netty.util.internal.*; import org.graalvm.nativeimage.*; + import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind.*; import static io.art.core.caster.Caster.*; import static io.art.core.constants.CompilerSuppressingWarnings.*; @@ -28,6 +29,7 @@ import static java.text.MessageFormat.*; import static java.util.Collections.*; import static java.util.Objects.*; + import javax.net.ssl.*; import java.net.*; import java.nio.*; @@ -42,15 +44,11 @@ final class TargetNettySslProvider { @Substitute public static boolean isAlpnSupported(final SslProvider provider) { - switch (provider) { - case JDK: - return TargetNettySslJdkAlpnApplicationProtocolNegotiator.isAlpnSupported(); - case OPENSSL: - case OPENSSL_REFCNT: - return false; - default: - throw new UnsupportedOperationException(format(NETTY_SSL_PROVIDER_UNSUPPORTED_EXCEPTION, provider)); - } + return switch (provider) { + case JDK -> TargetNettySslJdkAlpnApplicationProtocolNegotiator.isAlpnSupported(); + case OPENSSL, OPENSSL_REFCNT -> false; + default -> throw new UnsupportedOperationException(format(NETTY_SSL_PROVIDER_UNSUPPORTED_EXCEPTION, provider)); + }; } } @@ -64,7 +62,7 @@ static boolean isAlpnSupported() { } @SuppressWarnings({UNUSED, DEPRECATION}) -@TargetClass(className = NETTY_JDK_ALPN_PROTOCOL_NEGOTIATOR_ALPN_WRAPPER_CLASS, onlyWith = JDK11OrLater.class) +@TargetClass(className = NETTY_JDK_ALPN_PROTOCOL_NEGOTIATOR_ALPN_WRAPPER_CLASS) final class TargetNettyJdkAlpnApplicationProtocolNegotiatorAlpnWrapperJava11 { @Substitute public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc, @@ -75,44 +73,7 @@ public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc, } @SuppressWarnings({UNUSED, DEPRECATION}) -@TargetClass(className = NETTY_JDK_ALPN_PROTOCOL_NEGOTIATOR_ALPN_WRAPPER_CLASS, onlyWith = JDK8OrEarlier.class) -final class TargetNettyJdkAlpnApplicationProtocolNegotiator_AlpnWrapperJava8 { - @Substitute - public SSLEngine wrapSslEngine(SSLEngine engine, ByteBufAllocator alloc, - JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) { - if (TargetNettyJettyAlpnSslEngine.isAvailable()) { - return isServer - ? cast(TargetNettyJettyAlpnSslEngine.newServerEngine(engine, applicationNegotiator)) - : cast(TargetNettyJettyAlpnSslEngine.newClientEngine(engine, applicationNegotiator)); - } - throw new InternalRuntimeException(format(NETTY_UNABLE_TO_WRAP_SSL_ENGINE_EXCEPTION, engine.getClass().getName())); - } - -} - -@SuppressWarnings({UNUSED, DEPRECATION}) -@TargetClass(className = NETTY_SSL_JETTY_ALPN_SSL_ENGINE_CLASS, onlyWith = JDK8OrEarlier.class) -final class TargetNettyJettyAlpnSslEngine { - @Substitute - static boolean isAvailable() { - return false; - } - - @Substitute - static TargetNettyJettyAlpnSslEngine newClientEngine(SSLEngine engine, - JdkApplicationProtocolNegotiator applicationNegotiator) { - return null; - } - - @Substitute - static TargetNettyJettyAlpnSslEngine newServerEngine(SSLEngine engine, - JdkApplicationProtocolNegotiator applicationNegotiator) { - return null; - } -} - -@SuppressWarnings({UNUSED, DEPRECATION}) -@TargetClass(className = NETTY_SSL_JDK_ALPN_SSL_ENGINE_CLASS, onlyWith = JDK11OrLater.class) +@TargetClass(className = NETTY_SSL_JDK_ALPN_SSL_ENGINE_CLASS) final class TargetNettyJdkAlpnSslEngine { @Alias TargetNettyJdkAlpnSslEngine(final SSLEngine engine, @@ -179,30 +140,13 @@ public static boolean isCipherSuiteAvailable(String cipherSuite) { } } -@SuppressWarnings(UNUSED) -final class TargetNettyJdkSslServerContext { - - @Alias - TargetNettyJdkSslServerContext(Provider provider, - X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory, - X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, - KeyManagerFactory keyManagerFactory, Iterable ciphers, CipherSuiteFilter cipherFilter, - ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout, - ClientAuth clientAuth, String[] protocols, boolean startTls, - String keyStore) throws SSLException { - } -} - @SuppressWarnings({UNUSED, DEPRECATION}) @TargetClass(value = JdkSslClientContext.class) final class TargetNettyJdkSslClientContext { @Alias - TargetNettyJdkSslClientContext(Provider sslContextProvider, X509Certificate[] trustCertCollection, - TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain, PrivateKey key, - String keyPassword, KeyManagerFactory keyManagerFactory, Iterable ciphers, - CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn, String[] protocols, - long sessionCacheSize, long sessionTimeout, String keyStoreType) throws SSLException { + TargetNettyJdkSslClientContext(Provider sslContextProvider, X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory, Iterable ciphers, CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn, String[] protocols, long sessionCacheSize, long sessionTimeout, SecureRandom secureRandom, String keyStoreType) throws SSLException { + } } @@ -219,54 +163,9 @@ static TargetNettySslEngineType forEngine(SSLEngine engine) { } } -@SuppressWarnings(UNUSED) -@TargetClass(value = SslContext.class) -final class TargetNettySslContext { - - @Substitute - @SafeVarargs - static SslContext newServerContextInternal(SslProvider provider, Provider sslContextProvider, - X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory, - X509Certificate[] keyCertChain, - PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory, Iterable ciphers, - CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout, - ClientAuth clientAuth, String[] protocols, boolean startTls, boolean enableOcsp, String keyStoreType, - Map.Entry, Object>... ctxOptions) throws SSLException { - if (enableOcsp) { - throw new IllegalArgumentException(format(NETTY_OSCP_EXCEPTION, provider)); - } - - return cast(new TargetNettyJdkSslServerContext(sslContextProvider, - trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword, - keyManagerFactory, ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout, - clientAuth, protocols, startTls, keyStoreType)); - } - - @Substitute - @SafeVarargs - static SslContext newClientContextInternal(SslProvider provider, Provider sslContextProvider, - X509Certificate[] trustCert, - TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, - KeyManagerFactory keyManagerFactory, Iterable ciphers, CipherSuiteFilter cipherFilter, - ApplicationProtocolConfig apn, String[] protocols, long sessionCacheSize, long sessionTimeout, - boolean enableOcsp, - String keyStoreType, Map.Entry, Object>... options) throws SSLException { - if (enableOcsp) { - throw new IllegalArgumentException(format(NETTY_OSCP_EXCEPTION, provider)); - } - - return cast(new TargetNettyJdkSslClientContext(sslContextProvider, - trustCert, trustManagerFactory, keyCertChain, key, keyPassword, - keyManagerFactory, ciphers, cipherFilter, apn, protocols, sessionCacheSize, - sessionTimeout, keyStoreType)); - } - -} - @SuppressWarnings(UNUSED) @TargetClass(className = NETTY_JDK_DEFAULT_APPLICATION_PROTOCOL_NEGOTIATOR_CLASS) final class TargetNettyJdkDefaultApplicationProtocolNegotiator { - @Alias public static TargetNettyJdkDefaultApplicationProtocolNegotiator INSTANCE; } @@ -349,30 +248,6 @@ final class NettySchedulerFutureTaskHolder { static final long START_TIME = System.nanoTime(); } -@SuppressWarnings(UNUSED) -@TargetClass(className = NETTY_SCHEDULER_FUTURE_TASK_CLASS) -final class TargetNettySchedulerFutureTask { - @Substitute - static long initialNanoTime() { - return NettySchedulerFutureTaskHolder.START_TIME; - } - - @Substitute - static long nanoTime() { - return System.nanoTime() - NettySchedulerFutureTaskHolder.START_TIME; - } - - @Alias - public long deadlineNanos() { - return 0; - } - - @Substitute - public long delayNanos(long currentTimeNanos) { - return Math.max(0, deadlineNanos() - (currentTimeNanos - NettySchedulerFutureTaskHolder.START_TIME)); - } -} - @SuppressWarnings(UNUSED) @TargetClass(className = NETTY_CHANNEL_HANDLER_MASK_CLASS) final class TargetNettyChannelHandlerMask { diff --git a/transport/src/main/resources/META-INF/native-image/io.art.transport/native-image.properties b/transport/src/main/resources/META-INF/native-image/io.art.transport/native-image.properties index 064f11132..e47e96c22 100644 --- a/transport/src/main/resources/META-INF/native-image/io.art.transport/native-image.properties +++ b/transport/src/main/resources/META-INF/native-image/io.art.transport/native-image.properties @@ -38,4 +38,5 @@ Args=-H:ResourceConfigurationResources=${.}/resources-config.json -H:ReflectionC --initialize-at-run-time=reactor.netty.DefaultLoopIOUring \ --initialize-at-run-time=reactor.netty.DefaultLoopKQueue \ --initialize-at-run-time=reactor.netty.DefaultLoopNativeDetector \ - --initialize-at-run-time=io.netty.handler.codec.compression.ZstdOptions + --initialize-at-run-time=io.netty.handler.codec.compression.ZstdOptions \ + --features=io.art.transport.graal.feature.GraalNettyFeature