Search in sources :

Example 6 with Singleton

use of jakarta.inject.Singleton in project micronaut-camunda-bpm by camunda-community-hub.

the class ProcessEngineFactory method processEngine.

@Singleton
@Bean(preDestroy = "close")
public ProcessEngine processEngine(ProcessEngineConfiguration processEngineConfiguration, CamundaVersion camundaVersion, SynchronousTransactionManager<Connection> transactionManager, BasicJdbcConfiguration basicJdbcConfiguration, ParallelInitializationService parallelInitializationService) {
    if (camundaVersion.getVersion().isPresent()) {
        log.info("Camunda version: {}", camundaVersion.getVersion().get());
    } else {
        log.warn("The Camunda version cannot be determined. If you created a Fat/Uber/Shadow JAR then please consider using the Micronaut Application Plugin's 'dockerBuild' task to create a Docker image.");
    }
    log.info("Building process engine connected to {}", basicJdbcConfiguration.getUrl());
    Instant start = Instant.now();
    ProcessEngine processEngine = transactionManager.executeWrite(transactionStatus -> processEngineConfiguration.buildProcessEngine());
    log.info("Started process engine in {}ms", ChronoUnit.MILLIS.between(start, Instant.now()));
    log.debug("Starting Camunda related services...");
    parallelInitializationService.process(processEngine);
    log.debug("Camunda related services started in {}ms", ChronoUnit.MILLIS.between(start, Instant.now()));
    return processEngine;
}
Also used : Instant(java.time.Instant) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 7 with Singleton

use of jakarta.inject.Singleton in project glassfish-hk2 by eclipse-ee4j.

the class ServiceLocatorUtilitiesTest method testGetSingleton.

/**
 * Tests getSingleton
 */
@Test
public void testGetSingleton() {
    Singleton fromClass = HasScopes.class.getAnnotation(Singleton.class);
    Assert.assertNotNull(fromClass);
    Singleton fromUtility = ServiceLocatorUtilities.getSingletonAnnotation();
    Assert.assertNotNull(fromUtility);
    Assert.assertTrue(fromClass.equals(fromUtility));
    Assert.assertTrue(fromUtility.equals(fromClass));
}
Also used : Singleton(jakarta.inject.Singleton) Test(org.junit.Test)

Example 8 with Singleton

use of jakarta.inject.Singleton in project glassfish-hk2 by eclipse-ee4j.

the class Populator method populate.

/**
 * TODO:  This should be removed once we have &#64;Service all hooked up
 *
 * @param locator The locator to populate
 */
public static void populate(ServiceLocator locator) {
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    // The InjectionResolver we are showcasing
    config.bind(BuilderHelper.link(AlternateInjectResolver.class).to(InjectionResolver.class).in(Singleton.class.getName()).build());
    // The HttpEventReciever is in the default scope @PerLookup
    config.bind(BuilderHelper.link(HttpEventReceiver.class).build());
    // The HttpRequest is in the RequestScope
    config.bind(BuilderHelper.link(HttpRequest.class).in(RequestScope.class.getName()).build());
    // The HttpServer is a singleton
    config.bind(BuilderHelper.link(HttpServer.class).in(Singleton.class.getName()).build());
    // The RequestContext is the context implementation for RequestScope
    config.bind(BuilderHelper.link(RequestContext.class).to(Context.class).in(Singleton.class.getName()).build());
    // RequestProcessor processes a request from an HttpServer
    config.bind(BuilderHelper.link(RequestProcessor.class).build());
    // The logger is just another service to be injected
    config.bind(BuilderHelper.link(Logger.class).in(Singleton.class.getName()).build());
    // And commit
    config.commit();
}
Also used : HttpRequest(org.glassfish.examples.http.HttpRequest) RequestContext(org.glassfish.examples.http.RequestContext) Context(org.glassfish.hk2.api.Context) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) Singleton(jakarta.inject.Singleton) HttpServer(org.glassfish.examples.http.HttpServer) InjectionResolver(org.glassfish.hk2.api.InjectionResolver) Logger(org.glassfish.examples.http.Logger) RequestScope(org.glassfish.examples.http.RequestScope)

Example 9 with Singleton

use of jakarta.inject.Singleton in project micronaut-views by micronaut-projects.

the class PebbleEngineFactory method create.

/**
 * @return The Pebble Engine
 */
@Singleton
public PebbleEngine create() {
    Builder builder = new PebbleEngine.Builder().cacheActive(configuration.isCacheActive()).newLineTrimming(configuration.isNewLineTrimming()).autoEscaping(configuration.isAutoEscaping()).defaultEscapingStrategy(configuration.getDefaultEscapingStrategy()).strictVariables(configuration.isStrictVariables()).greedyMatchMethod(configuration.isGreedyMatchMethod()).allowOverrideCoreOperators(configuration.isAllowOverrideCoreOperators()).literalDecimalTreatedAsInteger(configuration.isLiteralDecimalsAsIntegers()).literalNumbersAsBigDecimals(configuration.isLiteralNumbersAsBigDecimals());
    if (executorService != null) {
        builder.executorService(executorService);
    }
    builder.loader(loader.orElseGet(() -> new PebbleLoader(viewsConfiguration, configuration)));
    syntax.ifPresent(bean -> builder.syntax(bean));
    methodAccessValidator.ifPresent(bean -> builder.methodAccessValidator(bean));
    extensions.forEach(bean -> builder.extension(bean));
    return builder.build();
}
Also used : Builder(com.mitchellbosecke.pebble.PebbleEngine.Builder) Builder(com.mitchellbosecke.pebble.PebbleEngine.Builder) PebbleEngine(com.mitchellbosecke.pebble.PebbleEngine) Singleton(jakarta.inject.Singleton)

Example 10 with Singleton

use of jakarta.inject.Singleton in project micronaut-views by micronaut-projects.

the class ThymeleafFactory method templateResolver.

/**
 * Constructs the template resolver bean.
 *
 * @param viewsConfiguration The views configuration
 * @param rendererConfiguration The renderer configuration
 * @return The template resolver
 */
@Singleton
public AbstractConfigurableTemplateResolver templateResolver(ViewsConfiguration viewsConfiguration, ThymeleafViewsRendererConfiguration rendererConfiguration) {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setPrefix(viewsConfiguration.getFolder());
    templateResolver.setCharacterEncoding(rendererConfiguration.getCharacterEncoding());
    templateResolver.setTemplateMode(rendererConfiguration.getTemplateMode());
    templateResolver.setSuffix(rendererConfiguration.getSuffix());
    templateResolver.setForceSuffix(rendererConfiguration.getForceSuffix());
    templateResolver.setForceTemplateMode(rendererConfiguration.getForceTemplateMode());
    templateResolver.setCacheTTLMs(rendererConfiguration.getCacheTTLMs());
    templateResolver.setCheckExistence(rendererConfiguration.getCheckExistence());
    templateResolver.setCacheable(rendererConfiguration.getCacheable());
    return templateResolver;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) Singleton(jakarta.inject.Singleton)

Aggregations

Singleton (jakarta.inject.Singleton)26 Bean (io.micronaut.context.annotation.Bean)7 Factory (io.micronaut.context.annotation.Factory)6 Properties (java.util.Properties)6 GraphQLSchema (graphql.schema.GraphQLSchema)5 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 GraphQL (graphql.GraphQL)4 RuntimeWiring (graphql.schema.idl.RuntimeWiring)4 SchemaGenerator (graphql.schema.idl.SchemaGenerator)4 SchemaParser (graphql.schema.idl.SchemaParser)4 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)4 ResourceResolver (io.micronaut.core.io.ResourceResolver)4 Named (jakarta.inject.Named)4 Test (org.junit.Test)3 ConfiguredStreamBuilder (io.micronaut.configuration.kafka.streams.ConfiguredStreamBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Arrays (java.util.Arrays)2 Locale (java.util.Locale)2 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)2