Skip to content

Commit

Permalink
refactoring - combining Module and Provider for non-deprecated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Nov 25, 2023
1 parent f85d14c commit 2cddb34
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
24 changes: 21 additions & 3 deletions src/main/java/io/bootique/curator/CuratorModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,34 @@

package io.bootique.curator;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.log.BootLogger;
import io.bootique.shutdown.ShutdownManager;
import org.apache.curator.framework.CuratorFramework;

import javax.inject.Singleton;

public class CuratorModule extends ConfigModule {
public class CuratorModule implements BQModule, BQModuleProvider {

private static final String CONFIG_PREFIX = "curator";

@Override
public BuiltModule buildModule() {
return BuiltModule.of(new CuratorModule())
.provider(this)
.description("Integrates Apache Curator Zookeeper client")
.config(CONFIG_PREFIX, CuratorFrameworkFactory.class)
.build();
}

@Override
public void configure(Binder binder) {
}

@Provides
@Singleton
Expand All @@ -37,7 +55,7 @@ public CuratorFramework createCurator(
BootLogger bootLogger,
ShutdownManager shutdownManager) {

CuratorFramework client = config(CuratorFrameworkFactory.class, configFactory).createZkClient();
CuratorFramework client = configFactory.config(CuratorFrameworkFactory.class, CONFIG_PREFIX).createZkClient();

shutdownManager.addShutdownHook(() -> {
bootLogger.trace(() -> "shutting down Curator...");
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/io/bootique/curator/CuratorModuleProvider.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.curator.CuratorModuleProvider
io.bootique.curator.CuratorModule
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import io.bootique.junit5.BQModuleProviderChecker;
import org.junit.jupiter.api.Test;

public class CuratorModuleProviderTest {
public class CuratorModuleTest {

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(CuratorModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(CuratorModule.class);
}
}

0 comments on commit 2cddb34

Please sign in to comment.