Skip to content

Commit 83b6bd9

Browse files
andythsuebyhr
authored andcommitted
Let Guice manage dependencies in router modules
1 parent d654094 commit 83b6bd9

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/module/QueryCountBasedRouterProvider.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@
1313
*/
1414
package io.trino.gateway.ha.module;
1515

16-
import com.google.inject.Provides;
16+
import com.google.inject.Scopes;
1717
import io.trino.gateway.ha.config.HaGatewayConfiguration;
1818
import io.trino.gateway.ha.router.QueryCountBasedRouter;
1919
import io.trino.gateway.ha.router.RoutingManager;
2020

2121
public class QueryCountBasedRouterProvider
2222
extends RouterBaseModule
2323
{
24-
private final QueryCountBasedRouter routingManager;
25-
2624
public QueryCountBasedRouterProvider(HaGatewayConfiguration configuration)
2725
{
2826
super(configuration);
29-
routingManager = new QueryCountBasedRouter(gatewayBackendManager, queryHistoryManager);
3027
}
3128

32-
@Provides
33-
public RoutingManager getRoutingManager()
29+
@Override
30+
public void configure()
3431
{
35-
return this.routingManager;
32+
bind(RoutingManager.class).to(QueryCountBasedRouter.class).in(Scopes.SINGLETON);
3633
}
3734
}

gateway-ha/src/main/java/io/trino/gateway/ha/module/StochasticRoutingManagerProvider.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,22 @@
1313
*/
1414
package io.trino.gateway.ha.module;
1515

16-
import com.google.inject.Provides;
16+
import com.google.inject.Scopes;
1717
import io.trino.gateway.ha.config.HaGatewayConfiguration;
1818
import io.trino.gateway.ha.router.RoutingManager;
1919
import io.trino.gateway.ha.router.StochasticRoutingManager;
2020

2121
public class StochasticRoutingManagerProvider
2222
extends RouterBaseModule
2323
{
24-
private final StochasticRoutingManager routingManager;
25-
2624
public StochasticRoutingManagerProvider(HaGatewayConfiguration configuration)
2725
{
2826
super(configuration);
29-
routingManager = new StochasticRoutingManager(gatewayBackendManager, queryHistoryManager);
30-
}
31-
32-
@Provides
33-
public StochasticRoutingManager getHaRoutingManager()
34-
{
35-
return this.routingManager;
3627
}
3728

38-
@Provides
39-
public RoutingManager getRoutingManager()
29+
@Override
30+
public void configure()
4031
{
41-
return getHaRoutingManager();
32+
bind(RoutingManager.class).to(StochasticRoutingManager.class).in(Scopes.SINGLETON);
4233
}
4334
}

gateway-ha/src/main/java/io/trino/gateway/ha/router/QueryCountBasedRouter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.common.annotations.VisibleForTesting;
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.errorprone.annotations.concurrent.GuardedBy;
20+
import com.google.inject.Inject;
2021
import io.airlift.log.Logger;
2122
import io.trino.gateway.ha.clustermonitor.ClusterStats;
2223
import io.trino.gateway.ha.clustermonitor.TrinoStatus;
@@ -134,6 +135,7 @@ public void userQueuedCount(Map<String, Integer> userQueuedCount)
134135
}
135136
}
136137

138+
@Inject
137139
public QueryCountBasedRouter(
138140
GatewayBackendManager gatewayBackendManager,
139141
QueryHistoryManager queryHistoryManager)

gateway-ha/src/main/java/io/trino/gateway/ha/router/StochasticRoutingManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.trino.gateway.ha.router;
1515

1616
import com.google.common.base.Strings;
17+
import com.google.inject.Inject;
1718
import io.airlift.log.Logger;
1819

1920
public class StochasticRoutingManager
@@ -22,6 +23,7 @@ public class StochasticRoutingManager
2223
private static final Logger log = Logger.get(StochasticRoutingManager.class);
2324
private final QueryHistoryManager queryHistoryManager;
2425

26+
@Inject
2527
public StochasticRoutingManager(
2628
GatewayBackendManager gatewayBackendManager, QueryHistoryManager queryHistoryManager)
2729
{

0 commit comments

Comments
 (0)