本文整理汇总了Java中com.google.inject.Singleton类的典型用法代码示例。如果您正苦于以下问题:Java Singleton类的具体用法?Java Singleton怎么用?Java Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Singleton类属于com.google.inject包,在下文中一共展示了Singleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
protected void configure() {
bind(GraphStore.class).in(Singleton.class);
bind(Settings.class).in(Singleton.class);
bind(Query.class).in(Singleton.class);
bind(BookmarkStore.class).to(SimpleBookmarkStore.class).in(Singleton.class);
bind(GraphDimensionsCalculator.class).in(Singleton.class);
bind(GraphMovementCalculator.class).in(Singleton.class);
bind(GenomeNavigation.class).in(Singleton.class);
bind(GraphAnnotation.class).in(Singleton.class);
bind(GraphVisualizer.class).in(Singleton.class);
bind(MainController.class).in(Singleton.class);
bind(SequenceVisualizer.class).in(Singleton.class);
bind(StatusBar.class).in(Singleton.class);
}
示例2: getAdminSaltLoadingCache
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Named("passwordSaltCache")
@Singleton
public Cache<String, String> getAdminSaltLoadingCache(
CacheManager cacheManager,
PasswordCredentialsFacade passwordCredentialsFacade,
@Named("passwordSaltRedisDao") RedisDao<String, String> passwordSaltRedisDao,
@Named("passwordSaltCacheGroup") String passwordSaltCacheGroup) {
LoadingCacheRedisImpl<String, String> l2Cache = new LoadingCacheRedisImpl<>();
l2Cache.setRedisDao(passwordSaltRedisDao);
l2Cache.setCacheLoader((email) -> passwordCredentialsFacade.getSaltForEmail(email).toMaybe());
LoadingCacheGuavaImpl<String, String> l1Cache = new LoadingCacheGuavaImpl<>();
l1Cache.setGuavaCache(CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).build());
l1Cache.setCacheLoader((key) -> l2Cache.get(key));
cacheManager.registerCacheGroup(passwordSaltCacheGroup, l1Cache, l2Cache);
return l1Cache;
}
示例3: configure
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
protected void configure() {
bind(Configuration.class).toProvider(ConfigurationProvider.class).in(Singleton.class);
bind(TransportClient.class).toProvider(TransportClientProvider.class).in(Singleton.class);
bind(JsonFormat.Printer.class).toInstance(JsonFormat.printer());
bind(JsonFormat.Parser.class).toInstance(JsonFormat.parser());
}
示例4: buildTypeByApiVersion
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
public Map<ApiVersion, Function<BuildType, BuildTypeData>> buildTypeByApiVersion( ) {
return ImmutableMap.of(
ApiVersion.API_6_0,
btype -> new BuildTypeData( btype.getId( ), btype.getName( ), btype.getProjectId( ), btype.getProjectName( ) ),
ApiVersion.API_7_0,
btype -> new BuildTypeData( btype.getId( ), btype.getName( ), btype.getProjectId( ), btype.getProjectName( ) ),
ApiVersion.API_8_0,
btype -> new BuildTypeData( btype.getId( ), btype.getName( ), btype.getProjectId( ), btype.getProjectName( ) ),
ApiVersion.API_8_1,
btype -> new BuildTypeData( btype.getId( ), btype.getName( ), btype.getProjectId( ), btype.getProjectName( ) )
);
}
示例5: getLoadingCache
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Named("authenticatableCache")
@Singleton
public LoadingCache<AuthenticationCredentials, AuthenticatedEntity> getLoadingCache(
@Named("authenticatableRedisDao") RedisDao<AuthenticationCredentials, AuthenticatedEntity> authenticatableRedisDao,
AuthenticationFacade authenticationFacade,
CacheManager cacheManager,
@Named("authenticationCacheGroup") String authenticationCacheGroupName
) {
LoadingCacheRedisImpl<AuthenticationCredentials, AuthenticatedEntity> l2Cache = new LoadingCacheRedisImpl<>();
l2Cache.setRedisDao(authenticatableRedisDao);
l2Cache.setCacheLoader((key) -> authenticationFacade.determineDao(key).authenticate(key));
l2Cache.setName("AUTHENTICATION_REDIS_CACHE");
LoadingCacheGuavaImpl<AuthenticationCredentials, AuthenticatedEntity> l1Cache = new LoadingCacheGuavaImpl<>();
l1Cache.setGuavaCache(CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).build());
l1Cache.setCacheLoader((key) -> l2Cache.get(key));
l2Cache.setName("AUTHENTICATION_GUAVA_CACHE");
cacheManager.registerCacheGroup(authenticationCacheGroupName, l1Cache, l2Cache);
return l1Cache;
}
示例6: configure
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
protected void configure() {
bind(MotTestReadService.class).to(MotTestReadServiceDatabase.class);
bind(VehicleReadService.class).to(VehicleReadServiceDatabase.class);
bind(TradeReadService.class).to(TradeReadServiceDatabase.class);
bind(MotrReadService.class).to(MotrReadServiceDatabase.class);
bind(TradeReadDao.class).to(TradeReadDaoJdbc.class);
bind(MotTestReadDao.class).to(MotTestReadDaoJdbc.class);
bind(VehicleReadDao.class).to(VehicleReadDaoJdbc.class);
bind(ConnectionManager.class).in(Singleton.class);
DbConnectionInterceptor dbConnectionInterceptor = new DbConnectionInterceptor();
requestInjection(dbConnectionInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(ProvideDbConnection.class),
dbConnectionInterceptor);
}
示例7: getJdbcTemplate
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
public NamedParameterJdbcTemplate getJdbcTemplate(
@Named("jdbc.driver") String driver,
@Named("jdbc.username") String username,
@Named("jdbc.password") String password,
@Named("jdbc.url") String url,
@Named("jdbc.maxActive") Integer maxActive,
@Named("jdbc.maxIdle") Integer maxIdle,
@Named("jdbc.initialSize") Integer initialSize,
@Named("jdbc.validationQuery") String validationQuery) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setUrl(url);
dataSource.setMaxActive(maxActive);
dataSource.setMaxIdle(maxIdle);
dataSource.setInitialSize(initialSize);
dataSource.setValidationQuery(validationQuery);
return new NamedParameterJdbcTemplate(dataSource);
}
示例8: run
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
public void run(ApiConfig configuration, Environment environment) throws Exception {
LOGGER.info("api started up");
injector = guiceBundle.getInjector();
JerseyEnvironment jersey = environment.jersey();
register(environment.lifecycle(), REFLECTIONS.getSubTypesOf(Managed.class)); // registers NbdServer
// injector.getInstance(SessionFactory.class); //init DB
installCorsFilter(environment);
//init all Singletons semi-eagerly
REFLECTIONS.getTypesAnnotatedWith(Singleton.class).forEach(injector::getInstance);
final Set<Class<?>> resources = REFLECTIONS.getTypesAnnotatedWith(Path.class);
register(jersey, resources);
jersey.register(new LoggingExceptionMapper<Throwable>() {
@Override
protected String formatErrorMessage(long id, Throwable exception) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
return sw.toString();
}
});
jersey.register(new JsonProcessingExceptionMapper(true));
jersey.register(new EarlyEofExceptionMapper());
final TrivialAuthenticator instance = injector.getInstance(TrivialAuthenticator.class);
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<Principal>()
.setAuthenticator(instance)
.setAuthorizer((principal, role) -> false)
.buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
}
示例9: testInjectorsSharingSameSingleton
import com.google.inject.Singleton; //导入依赖的package包/类
/**
* Checks whether the same instance is provided by different injector instances when the class of the provided
* instance is annotated with {@code @Singleton}.
*/
@Test
public void testInjectorsSharingSameSingleton() throws Exception {
final Class<N4JSTypeSystem> testedType = N4JSTypeSystem.class;
final Singleton[] singletons = testedType.getAnnotationsByType(Singleton.class);
assertTrue(testedType.getSimpleName() + " is not annotated with " + Singleton.class.getName() + ".",
!Arrays2.isEmpty(singletons));
final String injectorId = N4JSActivator.ORG_ECLIPSE_N4JS_N4JS;
final Injector parentInjector = N4JSActivator.getInstance().getInjector(injectorId);
final MockUIPlugin mockBundle = new MockUIPlugin();
try {
mockBundle.start(/* context */ null);
assertTrue("Mock bundle is not running yet.", Bundle.ACTIVE == mockBundle.getBundle().getState());
final Injector childInjector = mockBundle.getN4JSChildInjector();
final N4JSTypeSystem instanceFromParent = parentInjector.getInstance(testedType);
final N4JSTypeSystem instanceFromChild = childInjector.getInstance(testedType);
assertTrue(
"Expected the same instance of " + testedType.getSimpleName() + " from parent and child injectors.",
instanceFromChild == instanceFromParent);
} finally {
mockBundle.stop(/* context */ null);
}
}
示例10: init
import com.google.inject.Singleton; //导入依赖的package包/类
private void init() {
bindDescriptors.add(new BindDescriptor<Scheduler>().bind(Scheduler.class)
.to(SchedulerMockImpl.class)
.in(Singleton.class));
bindDescriptors.add(new BindDescriptor<ConnectionModuleFactory>().bind(ConnectionModuleFactory.class)
.to(ConnectionModuleFactoryMock.class)
.in(Singleton.class));
bindDescriptors.add(new BindDescriptor<PanelCache>().bind(PanelCache.class));
bindDescriptors.add(new BindDescriptor<FeedbackParserFactory>().bind(FeedbackParserFactory.class)
.to(FeedbackParserFactoryMock.class));
}
示例11: getTouchRecognitionFactory
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
public TouchRecognitionFactory getTouchRecognitionFactory() {
TouchRecognitionFactory factory = mock(TouchRecognitionFactory.class);
when(factory.getTouchRecognition(Matchers.any(Widget.class), Matchers.anyBoolean())).thenReturn(spy(new HasTouchHandlersMock()));
return factory;
}
示例12: provideResourceTwo
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
ResourceTwo provideResourceTwo(
@ResourceTwoFeature BeadledomClient beadledomClient, ExampleClientConfig config) {
BeadledomWebTarget target = beadledomClient.target(config.uri());
return target.proxy(ResourceTwo.class);
}
示例13: provideResourceOne
import com.google.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
ResourceOne provideResourceOne(
@ResourceOneFeature BeadledomClient client, ExampleClientConfig config) {
BeadledomWebTarget target = client.target(config.uri());
return target.proxy(ResourceOne.class);
}
示例14: configureServlets
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
protected void configureServlets()
{
bind(MetricReporterService.class).in(Singleton.class);
bind(MonitorFilter.class).in(Scopes.SINGLETON);
filter("/*").through(MonitorFilter.class);
bind(DataPointsMonitor.class).in(Scopes.SINGLETON);
bind(new TypeLiteral<List<KairosMetricReporter>>(){}).toProvider(KairosMetricReporterListProvider.class);
}
示例15: configure
import com.google.inject.Singleton; //导入依赖的package包/类
@Override
protected void configure()
{
logger.info("Configuring module TelnetServerModule");
bind(TelnetServer.class).in(Singleton.class);
bind(PutCommand.class).in(Singleton.class);
bind(PutMillisecondCommand.class).in(Singleton.class);
bind(VersionCommand.class).in(Singleton.class);
bind(CommandProvider.class).to(GuiceCommandProvider.class);
}