diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/HK2BridgeFeature.java b/src/main/java/net/winterly/dropwizard/hk2bundle/HK2BridgeFeature.java index 6aa1222..037dccd 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/HK2BridgeFeature.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/HK2BridgeFeature.java @@ -8,6 +8,10 @@ import static org.glassfish.hk2.extras.ExtrasUtilities.bridgeServiceLocator; +/** + * Feature that creates bridge between provided {@link ServiceLocator} and {@link ServiceLocator} obtained from + * Jersey in both directions + */ public class HK2BridgeFeature implements Feature { @Inject diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/HK2Bundle.java b/src/main/java/net/winterly/dropwizard/hk2bundle/HK2Bundle.java index 6a192aa..59addac 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/HK2Bundle.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/HK2Bundle.java @@ -27,6 +27,11 @@ public class HK2Bundle implements Bundle { + /** + * Used to generate unique incremental IDs for ServiceLocator name + */ + private static int nameCounter = 0; + private final ServiceLocator serviceLocator; private Application application; @@ -85,12 +90,6 @@ public void run(Environment environment) { listServices(ServerLifecycleListener.class).forEach(lifecycle::addServerLifecycleListener); listServices(Task.class).forEach(admin::addTask); - // Set service locator as parent for Jersey's service locator - /* - environment.getApplicationContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); - environment.getAdminContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); - */ - // Re-inject application with registered objects serviceLocator.inject(application); @@ -113,7 +112,11 @@ private String getName(Object object) { return name; } - private static ServiceLocator defaultServiceLocator() { - return createAndPopulateServiceLocator(HK2Bundle.class.getSimpleName()); + private synchronized static ServiceLocator defaultServiceLocator() { + String locatorName = String.format("%s-%s", + HK2Bundle.class.getSimpleName(), + nameCounter++ + ); + return createAndPopulateServiceLocator(locatorName); } } diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java index 41323a4..ba2d6ac 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java @@ -13,7 +13,7 @@ import static java.util.Objects.requireNonNull; /** - * HK2 binder used to configure sql objects injection + * HK2 binder configuring and binding SQL Objects injection * * @param application configuration type that contains {@link io.dropwizard.db.PooledDataSourceFactory} */ diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java index 6dbe2cf..45890c0 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java @@ -11,6 +11,9 @@ import javax.inject.Inject; import javax.inject.Singleton; +/** + * HK2 Factory for {@link Jdbi} instance, uses dropwizard configuration and environment to create instance + */ @Singleton public class JDBIFactory implements Factory { diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java index 4a91166..a15f2de 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java @@ -40,6 +40,12 @@ public void dispose(Object instance) { } + /** + * Extract SQL Interface type from {@link ActiveDescriptor} and generic {@link Factory} type + * + * @param activeDescriptor self descriptor + * @return sql object type or throws exception + */ private Class extractDaoType(ActiveDescriptor activeDescriptor) { Set contracts = activeDescriptor.getContractTypes(); diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/spi/DropwizardBinder.java b/src/main/java/net/winterly/dropwizard/hk2bundle/spi/DropwizardBinder.java index 86ec461..ff47e1c 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/spi/DropwizardBinder.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/spi/DropwizardBinder.java @@ -15,6 +15,9 @@ import javax.inject.Singleton; +/** + * Dropwizard-specific {@link AbstractBinder} for classes and instances of managed types + */ @SuppressWarnings("unused") public abstract class DropwizardBinder extends AbstractBinder {