Search in sources :

Example 11 with AbstractBinder

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);
            }
        });
    }
}
Also used : RealtimeFeed(com.graphhopper.gtfs.RealtimeFeed) Singleton(javax.inject.Singleton) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) HttpClient(org.apache.http.client.HttpClient) HttpClientBuilder(io.dropwizard.client.HttpClientBuilder)

Example 12 with AbstractBinder

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;
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) FileSystem(org.apache.hadoop.fs.FileSystem) SparkUtilityService(com.thinkbiganalytics.spark.service.SparkUtilityService) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) TransformService(com.thinkbiganalytics.spark.service.TransformService) SparkLocatorService(com.thinkbiganalytics.spark.service.SparkLocatorService) Bean(org.springframework.context.annotation.Bean)

Example 13 with AbstractBinder

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();
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) Container(org.glassfish.jersey.server.spi.Container) Filter(org.glassfish.hk2.api.Filter) DropwizardResourceConfig(io.dropwizard.jersey.DropwizardResourceConfig) Singleton(javax.inject.Singleton) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) List(java.util.List) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 14 with AbstractBinder

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));
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 15 with AbstractBinder

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;
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) FileSystem(org.apache.hadoop.fs.FileSystem) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) TransformService(com.thinkbiganalytics.spark.service.TransformService) SparkLocatorService(com.thinkbiganalytics.spark.service.SparkLocatorService) Bean(org.springframework.context.annotation.Bean)

Aggregations

AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)17 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 Test (org.junit.Test)4 Singleton (javax.inject.Singleton)3 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)3 SparkLocatorService (com.thinkbiganalytics.spark.service.SparkLocatorService)2 TransformService (com.thinkbiganalytics.spark.service.TransformService)2 ServletContext (javax.servlet.ServletContext)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)2 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)2 ServiceLocatorFactory (org.glassfish.hk2.api.ServiceLocatorFactory)2 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 RealtimeFeed (com.graphhopper.gtfs.RealtimeFeed)1 GraphHopperHealthCheck (com.graphhopper.http.health.GraphHopperHealthCheck)1 JTSTriangulator (com.graphhopper.isochrone.algorithm.JTSTriangulator)1 Triangulator (com.graphhopper.isochrone.algorithm.Triangulator)1 ProfileResolver (com.graphhopper.routing.ProfileResolver)1