Skip to content

Commit

Permalink
Align closingBinder API with Guice
Browse files Browse the repository at this point in the history
Accept `Key`.
  • Loading branch information
findepi committed Apr 10, 2024
1 parent 6afe0d8 commit 1c8eadf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
Expand Down Expand Up @@ -365,10 +366,10 @@ List<OutputStatsEstimatorFactory> getCompositeOutputDataSizeEstimatorDelegateFac

// cleanup
closingBinder(binder)
.registerExecutor(ExecutorService.class, ForStatementResource.class)
.registerExecutor(ScheduledExecutorService.class, ForStatementResource.class)
.registerExecutor(ExecutorService.class, ForQueryExecution.class)
.registerExecutor(ScheduledExecutorService.class, ForScheduler.class);
.registerExecutor(Key.get(ExecutorService.class, ForStatementResource.class))
.registerExecutor(Key.get(ScheduledExecutorService.class, ForStatementResource.class))
.registerExecutor(Key.get(ExecutorService.class, ForQueryExecution.class))
.registerExecutor(Key.get(ScheduledExecutorService.class, ForScheduler.class));
}

// working around circular dependency Metadata <-> PlannerContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
Expand Down Expand Up @@ -496,9 +497,9 @@ protected void setup(Binder binder)

// cleanup
closingBinder(binder)
.registerExecutor(ScheduledExecutorService.class, ForExchange.class)
.registerExecutor(ExecutorService.class, ForAsyncHttp.class)
.registerExecutor(ScheduledExecutorService.class, ForAsyncHttp.class);
.registerExecutor(Key.get(ScheduledExecutorService.class, ForExchange.class))
.registerExecutor(Key.get(ExecutorService.class, ForAsyncHttp.class))
.registerExecutor(Key.get(ScheduledExecutorService.class, ForAsyncHttp.class));
}

private static class RegisterFunctionBundles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.transaction;

import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Singleton;
Expand All @@ -37,8 +38,8 @@ public void configure(Binder binder)
{
configBinder(binder).bindConfig(TransactionManagerConfig.class);
closingBinder(binder)
.registerExecutor(ExecutorService.class, ForTransactionManager.class)
.registerExecutor(ScheduledExecutorService.class, ForTransactionManager.class);
.registerExecutor(Key.get(ExecutorService.class, ForTransactionManager.class))
.registerExecutor(Key.get(ScheduledExecutorService.class, ForTransactionManager.class));
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.Closeable;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Set;
Expand All @@ -35,6 +34,7 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.util.Objects.requireNonNull;

public class ClosingBinder
{
Expand All @@ -55,25 +55,23 @@ private ClosingBinder(Binder binder)

public ClosingBinder registerExecutor(Class<? extends ExecutorService> type)
{
executors.addBinding().to(type);
return this;
return registerExecutor(Key.get(type));
}

public ClosingBinder registerExecutor(Class<? extends ExecutorService> type, Class<? extends Annotation> annotation)
public ClosingBinder registerExecutor(Key<? extends ExecutorService> key)
{
executors.addBinding().to(Key.get(type, annotation));
executors.addBinding().to(requireNonNull(key, "key is null"));
return this;
}

public ClosingBinder registerCloseable(Class<? extends Closeable> type)
{
closeables.addBinding().to(type);
return this;
return registerCloseable(Key.get(type));
}

public ClosingBinder registerCloseable(Class<? extends Closeable> type, Class<? extends Annotation> annotation)
public ClosingBinder registerCloseable(Key<? extends Closeable> key)
{
closeables.addBinding().to(Key.get(type, annotation));
closeables.addBinding().to(key);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void setup(Binder binder)
newSetBinder(binder, JdbcQueryEventListener.class);

closingBinder(binder)
.registerExecutor(ExecutorService.class, ForRecordCursor.class);
.registerExecutor(Key.get(ExecutorService.class, ForRecordCursor.class));
}

public static Multibinder<SessionPropertiesProvider> sessionPropertiesProviderBinder(Binder binder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void setup(Binder binder)
binder.bind(Key.get(boolean.class, AllowHiveTableRename.class)).toInstance(true);

closingBinder(binder)
.registerExecutor(ExecutorService.class, ThriftHiveWriteStatisticsExecutor.class);
.registerExecutor(Key.get(ExecutorService.class, ThriftHiveWriteStatisticsExecutor.class));
}

private static class ThriftHiveMetastoreStatisticExecutorProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void setup(Binder binder)
install(new DecimalModule());

closingBinder(binder)
.registerExecutor(ExecutorService.class, ForRecordCursor.class);
.registerExecutor(Key.get(ExecutorService.class, ForRecordCursor.class));
}

private void checkConfiguration(String connectionUrl)
Expand Down

0 comments on commit 1c8eadf

Please sign in to comment.