当前位置: 首页>>代码示例>>Java>>正文


Java Singleton类代码示例

本文整理汇总了Java中javax.inject.Singleton的典型用法代码示例。如果您正苦于以下问题:Java Singleton类的具体用法?Java Singleton怎么用?Java Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Singleton类属于javax.inject包,在下文中一共展示了Singleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: provideNetworkInterceptor

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
@NetworkInterceptor
Interceptor provideNetworkInterceptor() {
    return new Interceptor() {
        @Override
        public Response intercept(@NonNull Chain chain) throws IOException {
            Response originalResponse = chain.proceed(chain.request());
            String cacheControl = originalResponse.header("Cache-Control");
            if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") ||
                    cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) {
                return originalResponse.newBuilder()
                        .removeHeader("Pragma")
                        .header("Cache-Control", "public, max-age=" + 86400)// cache and reuse for 1 day(86400 seconds)
                        .build();
            } else {
                return originalResponse;
            }
        }
    };
}
 
开发者ID:vicky7230,项目名称:Paprika,代码行数:22,代码来源:NetworkModule.java

示例2: provideBaseUrl

import javax.inject.Singleton; //导入依赖的package包/类
@Singleton
@Provides
HttpUrl provideBaseUrl() {
    if (mBaseUrl != null) {
        HttpUrl httpUrl = mBaseUrl.url();
        if (httpUrl != null) {
            return httpUrl;
        }
    }
    return mApiUrl == null ? HttpUrl.parse("https://api.github.com/") : mApiUrl;
}
 
开发者ID:yangxp108,项目名称:MVPArms_Fragment-fragment,代码行数:12,代码来源:GlobalConfigModule.java

示例3: provideOkHttpClient

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
static OkHttpClient provideOkHttpClient() {
  return new OkHttpClient.Builder()
      .readTimeout(DEFAULT_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS)
      .connectTimeout(DEFAULT_CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
      .addNetworkInterceptor(new StethoInterceptor())
      .build();
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:10,代码来源:DebugNetworkModule.java

示例4: createDeployment

import javax.inject.Singleton; //导入依赖的package包/类
@Deployment
public static WebArchive createDeployment() {
    String url = SimpleGetApi.class.getName() + "/mp-rest/url=http://localhost:8080";
    String scope = SimpleGetApi.class.getName() + "/mp-rest/scope=" + Singleton.class.getName();
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
        .addClasses(SimpleGetApi.class, MySingletonApi.class)
        .addAsManifestResource(new StringAsset(url + "\n" + scope), "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return ShrinkWrap.create(WebArchive.class)
        .addAsLibrary(jar)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:13,代码来源:HasSingletonScopeTest.java

示例5: provideCache

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
public Cache provideCache(@Named("cacheDir") File cacheDir, @Named("cacheSize") long cacheSize) {

    Cache cache = null;

    try {
        cache = new Cache(new File(cacheDir.getPath(), "http-cache"), cacheSize);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return cache;
}
 
开发者ID:Ryuuke,项目名称:LeagueOfAndroid,代码行数:15,代码来源:ClientModule.java

示例6: proRxErrorHandler

import javax.inject.Singleton; //导入依赖的package包/类
/**
 * 提供处理 RxJava 错误的管理器
 *
 * @return
 */
@Singleton
@Provides
RxErrorHandler proRxErrorHandler(Application application, ResponseErrorListener listener) {
    return RxErrorHandler
            .builder()
            .with(application)
            .responseErrorListener(listener)
            .build();
}
 
开发者ID:Zweihui,项目名称:Aurora,代码行数:15,代码来源:ClientModule.java

示例7: provideRxCacheDirectory

import javax.inject.Singleton; //导入依赖的package包/类
/**
 * 需要单独给RxCache提供缓存路径
 * 提供RxCache缓存地址
 */
@Singleton
@Provides
@Named("RxCacheDirectory")
File provideRxCacheDirectory(File cacheDir) {
    File cacheDirectory = new File(cacheDir, "RxCache");
    return DataHelper.makeDirs(cacheDirectory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ClientModule.java

示例8: providesGsonConverterFactory

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
public Converter.Factory providesGsonConverterFactory() {
    Gson gson = new GsonBuilder()
            .registerTypeAdapterFactory(AutoValuesGsonAdapterFactory.create())
            .create();
    return GsonConverterFactory.create(gson);
}
 
开发者ID:ecarrara-araujo,项目名称:yabaking,代码行数:9,代码来源:NetworkingModule.java

示例9: dataSource

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
static DataSource dataSource(DatabaseConfig config) {
  HikariConfig hikari = new HikariConfig();
  hikari.setJdbcUrl(config.getJdbcUrl());
  hikari.setUsername(config.getUsername());
  hikari.setPassword(config.getPassword());
  hikari.addDataSourceProperty("cachePrepStmts", "true");
  hikari.addDataSourceProperty(
      "statementInterceptors", "brave.mysql.TracingStatementInterceptor");
  hikari.addDataSourceProperty("useUnicode", "yes");
  hikari.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
  return new HikariDataSource(hikari);
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:15,代码来源:DatabaseModule.java

示例10: providePoller

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
Poller providePoller(@IoExecutor Executor ioExecutor,
		@Scheduler ScheduledExecutorService scheduler,
		ConnectionManager connectionManager,
		ConnectionRegistry connectionRegistry, PluginManager pluginManager,
		SecureRandom random, Clock clock, EventBus eventBus) {
	Poller poller = new Poller(ioExecutor, scheduler, connectionManager,
			connectionRegistry, pluginManager, random, clock);
	eventBus.addListener(poller);
	return poller;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:13,代码来源:PluginModule.java

示例11: client

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
OkHttpClient client() {
    return new OkHttpClient.Builder()
            .cache(new Cache(app.getCacheDir(), 1024L * 20))
            .followRedirects(true)
            .retryOnConnectionFailure(true)
            .build();
}
 
开发者ID:noties,项目名称:Markwon,代码行数:10,代码来源:AppModule.java

示例12: provideServerAPI

import javax.inject.Singleton; //导入依赖的package包/类
@Singleton
@Provides
ServerAPI provideServerAPI() {
    return new RestAdapter.Builder()
        .setEndpoint(ServerAPI.ENDPOINT)
        .setLogLevel(RestAdapter.LogLevel.FULL)
        .setLog(new RestAdapter.Log() {
            @Override
            public void log(String message) {
                v("Retrofit", message);
            }
        })
        .build().create(ServerAPI.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:AppModule.java

示例13: proxyModule

import javax.inject.Singleton; //导入依赖的package包/类
public static <T> Module proxyModule(Class<T> proxyInterface) {

		return new AbstractModule() {
			@Override
			protected void configure() {
				Provider<Queries> provider = getProvider(Queries.class);

				Multibinder<QueriesSource> sourcesBinder = Multibinder.newSetBinder(binder(), QueriesSource.class);
				sourcesBinder.addBinding().toInstance(QueriesSource.ofClass(proxyInterface));

				bind(proxyInterface).toProvider(new ProxyInterfaceProvider<T>(provider, proxyInterface))
						.in(Singleton.class);
			}
		};
	}
 
开发者ID:jaregu,项目名称:queries,代码行数:16,代码来源:QueriesGuiceSupport.java

示例14: provideOkHttpClient

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
OkHttpClient provideOkHttpClient() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .connectTimeout(Config.CONNECT_TIMEOUT, SECONDS)
            .writeTimeout(Config.WRITE_TIMEOUT, SECONDS)
            .readTimeout(Config.READ_TIMEOUT, SECONDS);
    if (BuildConfig.DEBUG) {
        builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
    }
    return builder.build();
}
 
开发者ID:VDenis,项目名称:YandexTranslator,代码行数:13,代码来源:ModelModule.java

示例15: provideObjectMapper

import javax.inject.Singleton; //导入依赖的package包/类
@Provides
@Singleton
ObjectMapper provideObjectMapper() {
  ObjectMapper objectMapper = new ObjectMapper();

  objectMapper.setPropertyNamingStrategy(
      PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
  objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  return objectMapper;
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:14,代码来源:FauxModule.java


注:本文中的javax.inject.Singleton类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。