Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Generate unique IDs for service locators, add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-shpak committed Nov 8, 2018
1 parent 698ee24 commit 61b6e53
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/net/winterly/dropwizard/hk2bundle/HK2Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> application configuration type that contains {@link io.dropwizard.db.PooledDataSourceFactory}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Jdbi> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Factory> activeDescriptor) {
Set<Type> contracts = activeDescriptor.getContractTypes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 61b6e53

Please sign in to comment.