Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use static resource binding instead of runtime reflection based binding #307

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions gateway-ha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,6 @@
<version>${dep.jeasy.version}</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
55 changes: 20 additions & 35 deletions gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.gateway.baseapp;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MoreCollectors;
import com.google.inject.Guice;
import com.google.inject.Injector;
Expand All @@ -30,15 +31,16 @@
import io.trino.gateway.ha.log.GatewayRequestLogFactory;
import io.trino.gateway.ha.module.RouterBaseModule;
import io.trino.gateway.ha.module.StochasticRoutingManagerProvider;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.ext.Provider;
import io.trino.gateway.ha.resource.EntityEditorResource;
import io.trino.gateway.ha.resource.GatewayResource;
import io.trino.gateway.ha.resource.GatewayViewResource;
import io.trino.gateway.ha.resource.GatewayWebAppResource;
import io.trino.gateway.ha.resource.HaGatewayResource;
import io.trino.gateway.ha.resource.LoginResource;
import io.trino.gateway.ha.resource.PublicResource;
import io.trino.gateway.ha.resource.TrinoResource;
import io.trino.gateway.ha.security.AuthorizedExceptionMapper;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -61,8 +63,6 @@ public abstract class BaseApp<T extends AppConfiguration>
extends Application<T>
{
private static final Logger logger = Logger.get(BaseApp.class);

private final Reflections reflections;
private final ImmutableList.Builder<Module> appModules = ImmutableList.builder();

private AppModule newModule(String clazz, T configuration, Environment environment)
Expand Down Expand Up @@ -94,29 +94,6 @@ private void validateModules(List<AppModule> modules, T configuration, Environme
}
}

protected BaseApp(String... basePackages)
{
final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
final FilterBuilder filterBuilder = new FilterBuilder();

if (basePackages.length == 0) {
basePackages = new String[] {};
}

logger.info("op=create auto_scan_packages=%s", basePackages);

for (String basePkg : basePackages) {
confBuilder.addUrls(ClasspathHelper.forPackage(basePkg));
filterBuilder.include(FilterBuilder.prefix(basePkg));
}

confBuilder
.filterInputsBy(filterBuilder)
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());

this.reflections = new Reflections(confBuilder);
}

@Override // Using Airlift logger
protected void bootstrapLogging() {}

Expand Down Expand Up @@ -206,7 +183,7 @@ protected List<Managed> addManagedApps(

private void registerProviders(Environment environment, Injector injector)
{
final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Provider.class);
final Set<Class<?>> classes = ImmutableSet.of(AuthorizedExceptionMapper.class);
classes.forEach(
c -> {
environment.jersey().register(injector.getInstance(c));
Expand All @@ -216,7 +193,15 @@ private void registerProviders(Environment environment, Injector injector)

private void registerResources(Environment environment, Injector injector)
{
final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Path.class);
final Set<Class<?>> classes = ImmutableSet.of(
EntityEditorResource.class,
GatewayResource.class,
GatewayViewResource.class,
GatewayWebAppResource.class,
HaGatewayResource.class,
LoginResource.class,
PublicResource.class,
TrinoResource.class);
classes.forEach(
c -> {
environment.jersey().register(injector.getInstance(c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
public class HaGatewayLauncher
extends BaseApp<HaGatewayConfiguration>
{
public HaGatewayLauncher(String... basePackages)
{
super(basePackages);
}

@Override
public void initialize(Bootstrap<HaGatewayConfiguration> bootstrap)
{
Expand All @@ -51,8 +46,6 @@ public static void main(String[] args)
Logging logging = Logging.initialize();
logging.configure(configuration);

/* base package is scanned for any Resource class to be loaded by default. */
String basePackage = "io.trino";
new HaGatewayLauncher(basePackage).run(args);
new HaGatewayLauncher().run(args);
}
}
Loading