use of org.glassfish.hk2.utilities.binding.AbstractBinder in project graphhopper by graphhopper.
the class RealtimeBundle method run.
@Override
public void run(RealtimeBundleConfiguration configuration, Environment environment) {
if (configuration.gtfsrealtime().getFeeds().isEmpty()) {
environment.jersey().register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(EmptyRealtimeFeedFactory.class).to(RealtimeFeed.class).in(Singleton.class);
}
});
} else {
final HttpClient httpClient = new HttpClientBuilder(environment).using(configuration.gtfsrealtime().getHttpClientConfiguration()).build("gtfs-realtime-feed-loader");
environment.jersey().register(new AbstractBinder() {
@Override
protected void configure() {
bind(httpClient).to(HttpClient.class);
bind(configuration).to(RealtimeBundleConfiguration.class);
bindFactory(RealtimeFeedLoadingCache.class, Singleton.class).to(RealtimeFeed.class);
}
});
}
}
use of org.glassfish.hk2.utilities.binding.AbstractBinder in project kylo by Teradata.
the class KyloShellConfig method jerseyConfig.
/**
* Gets the resource configuration for setting up Jersey.
*
* @return the Jersey configuration
*/
@Bean
public ResourceConfig jerseyConfig(final TransformService transformService, final FileSystem fileSystem, final SparkLocatorService sparkLocatorService, final SparkUtilityService sparkUtilityService) {
Validate.notNull(fileSystem);
Validate.notNull(transformService);
Validate.notNull(sparkLocatorService);
Validate.notNull(sparkUtilityService);
final ResourceConfig config = new ResourceConfig(ApiListingResource.class, SwaggerSerializers.class);
config.packages("com.thinkbiganalytics.spark.rest");
config.register(new AbstractBinder() {
@Override
protected void configure() {
bind(fileSystem).to(FileSystem.class);
bind(transformService).to(TransformService.class);
bind(sparkLocatorService).to(SparkLocatorService.class);
bind(sparkUtilityService).to(SparkUtilityService.class);
}
});
return config;
}
use of org.glassfish.hk2.utilities.binding.AbstractBinder in project dropwizard-jobs by dropwizard-jobs.
the class Hk2JobsBundleTest method registerToContainer.
/**
* A test case for the {@link Hk2JobsBundle#run(JobConfiguration, Environment)} and
* {@link Hk2JobsBundle#getScheduler()}.
*/
@Test
public void registerToContainer() throws Exception {
final Filter searchCriteria = BuilderHelper.createContractFilter(Job.class.getName());
final Hk2JobsBundle jobsBundle = new Hk2JobsBundle(searchCriteria);
// initialization
final DropwizardResourceConfig resourceConfig = DropwizardResourceConfig.forTesting();
when(environment.jersey()).thenReturn(new JerseyEnvironment(null, resourceConfig));
jobsBundle.run(configuration, environment);
final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
final InjectionManager im = applicationHandler.getInjectionManager();
final ServiceLocator serviceLocator = im.getInstance(ServiceLocator.class);
ServiceLocatorUtilities.bind(serviceLocator, new AbstractBinder() {
@Override
protected void configure() {
bind(ApplicationStartTestJob.class).to(Job.class).in(Singleton.class);
bind(ApplicationStopTestJob.class).to(Job.class).in(Singleton.class);
bind(EveryTestJob.class).to(EveryTestJob.class);
}
});
final Container container = mock(Container.class);
when(container.getApplicationHandler()).thenReturn(applicationHandler);
when(container.getConfiguration()).thenReturn(resourceConfig);
// verify precondition
assertThat(jobsBundle.getScheduler()).isNull();
// startup container
applicationHandler.onStartup(container);
Thread.sleep(1000);
// verify at startup
@SuppressWarnings("unchecked") final List<AbstractJob> jobs = (List<AbstractJob>) serviceLocator.getAllServices(searchCriteria);
AbstractJob applicationStartTestJob = getJob(jobs, ApplicationStartTestJob.class);
AbstractJob applicationStopTestJob = getJob(jobs, ApplicationStopTestJob.class);
assertThat(jobs).hasSize(2);
assertThat(applicationStartTestJob.latch().getCount()).isEqualTo(0);
assertThat(applicationStopTestJob.latch().getCount()).isEqualTo(1);
assertThat(jobsBundle.getScheduler().isStarted()).isTrue();
// shutdown container
applicationHandler.onShutdown(container);
Thread.sleep(1000);
// verify at shutdown
assertThat(applicationStopTestJob.latch().getCount()).isEqualTo(0);
assertThat(jobsBundle.getScheduler().isShutdown()).isTrue();
}
use of org.glassfish.hk2.utilities.binding.AbstractBinder in project jersey by jersey.
the class InjectionManagerTest method testServiceLocatorParent.
@Test
public void testServiceLocatorParent() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(EnglishGreeting.class);
}
};
ServiceLocator parentLocator = ServiceLocatorUtilities.bind(binder);
InjectionManager injectionManager = new HK2InjectionManager();
injectionManager.initialize(parentLocator);
assertNotNull(injectionManager.getInstance(EnglishGreeting.class));
}
use of org.glassfish.hk2.utilities.binding.AbstractBinder in project kylo by Teradata.
the class SparkShellApp method jerseyConfig.
/**
* Gets the resource configuration for setting up Jersey.
*
* @return the Jersey configuration
*/
@Bean
public ResourceConfig jerseyConfig(final TransformService transformService, final FileSystem fileSystem, final SparkLocatorService sparkLocatorService) {
final ResourceConfig config = new ResourceConfig(ApiListingResource.class, SwaggerSerializers.class);
config.packages("com.thinkbiganalytics.spark.rest");
config.register(new AbstractBinder() {
@Override
protected void configure() {
bind(fileSystem).to(FileSystem.class);
bind(transformService).to(TransformService.class);
bind(sparkLocatorService).to(SparkLocatorService.class);
}
});
return config;
}
Aggregations