• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Timer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: shouldRefreshIsCorrect

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
@Test
public void shouldRefreshIsCorrect() {
  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now())
      .thenReturn(500l)
      .thenReturn(1000000l + 500l);
  
  AccessTokenTimer timer = new AccessTokenTimer(mockTimer);
  
  timer.setExpiresInMSSinceEpoch("1000000");
  
  assertFalse(timer.shouldRefresh());
  assertTrue(timer.shouldRefresh());
  
  verify(mockTimer, times(2)).now();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:17,代码来源:TestAccessTokenTimer.java


示例2: Groups

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public Groups(Configuration conf, final Timer timer) {
  impl = 
    ReflectionUtils.newInstance(
        conf.getClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, 
                      ShellBasedUnixGroupsMapping.class, 
                      GroupMappingServiceProvider.class), 
        conf);

  cacheTimeout = 
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS, 
        CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS_DEFAULT) * 1000;
  negativeCacheTimeout =
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_NEGATIVE_CACHE_SECS,
        CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_NEGATIVE_CACHE_SECS_DEFAULT) * 1000;
  warningDeltaMs =
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS,
      CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS_DEFAULT);
  parseStaticMapping(conf);

  this.timer = timer;
  this.cache = CacheBuilder.newBuilder()
    .refreshAfterWrite(cacheTimeout, TimeUnit.MILLISECONDS)
    .ticker(new TimerToTickerAdapter(timer))
    .expireAfterWrite(10 * cacheTimeout, TimeUnit.MILLISECONDS)
    .build(new GroupCacheLoader());

  if(negativeCacheTimeout > 0) {
    Cache<String, Boolean> tempMap = CacheBuilder.newBuilder()
      .expireAfterWrite(negativeCacheTimeout, TimeUnit.MILLISECONDS)
      .ticker(new TimerToTickerAdapter(timer))
      .build();
    negativeCache = Collections.newSetFromMap(tempMap.asMap());
  }

  if(LOG.isDebugEnabled())
    LOG.debug("Group mapping impl=" + impl.getClass().getName() + 
        "; cacheTimeout=" + cacheTimeout + "; warningDeltaMs=" +
        warningDeltaMs);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:40,代码来源:Groups.java


示例3: Groups

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public Groups(Configuration conf, final Timer timer) {
  impl = 
    ReflectionUtils.newInstance(
        conf.getClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, 
                      ShellBasedUnixGroupsMapping.class, 
                      GroupMappingServiceProvider.class), 
        conf);

  cacheTimeout = 
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS, 
        CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS_DEFAULT) * 1000;
  negativeCacheTimeout =
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_NEGATIVE_CACHE_SECS,
        CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_NEGATIVE_CACHE_SECS_DEFAULT) * 1000;
  warningDeltaMs =
    conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS,
      CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS_DEFAULT);
  staticUserToGroupsMap = parseStaticMapping(conf);

  this.timer = timer;
  this.cache = CacheBuilder.newBuilder()
    .refreshAfterWrite(cacheTimeout, TimeUnit.MILLISECONDS)
    .ticker(new TimerToTickerAdapter(timer))
    .expireAfterWrite(10 * cacheTimeout, TimeUnit.MILLISECONDS)
    .build(new GroupCacheLoader());

  if(negativeCacheTimeout > 0) {
    Cache<String, Boolean> tempMap = CacheBuilder.newBuilder()
      .expireAfterWrite(negativeCacheTimeout, TimeUnit.MILLISECONDS)
      .ticker(new TimerToTickerAdapter(timer))
      .build();
    negativeCache = Collections.newSetFromMap(tempMap.asMap());
  }

  if(LOG.isDebugEnabled())
    LOG.debug("Group mapping impl=" + impl.getClass().getName() + 
        "; cacheTimeout=" + cacheTimeout + "; warningDeltaMs=" +
        warningDeltaMs);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:Groups.java


示例4: expireConversionWorks

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
@Test
public void expireConversionWorks() {
  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now())
      .thenReturn(5l);
  
  AccessTokenTimer timer = new AccessTokenTimer(mockTimer);
  
  timer.setExpiresIn("3");
  assertEquals(3005, timer.getNextRefreshMSSinceEpoch());
  
  assertTrue(timer.shouldRefresh());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:14,代码来源:TestAccessTokenTimer.java


示例5: TimerToTickerAdapter

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public TimerToTickerAdapter(Timer timer) {
  this.timer = timer;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:4,代码来源:Groups.java


示例6: ConfRefreshTokenBasedAccessTokenProvider

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public ConfRefreshTokenBasedAccessTokenProvider(Timer timer) {
  this.accessTokenTimer = new AccessTokenTimer(timer);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:ConfRefreshTokenBasedAccessTokenProvider.java


示例7: ConfCredentialBasedAccessTokenProvider

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public ConfCredentialBasedAccessTokenProvider(Timer timer) {
  super(timer);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:ConfCredentialBasedAccessTokenProvider.java


示例8: CredentialBasedAccessTokenProvider

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
CredentialBasedAccessTokenProvider(Timer timer) {
  this.timer = new AccessTokenTimer(timer);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:CredentialBasedAccessTokenProvider.java


示例9: AccessTokenTimer

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public AccessTokenTimer() {
  this(new Timer());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:AccessTokenTimer.java


示例10: convertExpiresIn

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
/**
 * The expires_in param from OAuth is in seconds-from-now.  Convert to
 * milliseconds-from-epoch
 */
static Long convertExpiresIn(Timer timer, String expiresInSecs) {
  long expiresSecs = Long.parseLong(expiresInSecs);
  long expiresMs = expiresSecs * 1000;
  return timer.now() + expiresMs;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:10,代码来源:AccessTokenTimer.java


示例11: refreshUrlIsCorrect

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
@Test
public void refreshUrlIsCorrect() throws IOException {
  final int PORT = 7552;
  final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";

  long tokenExpires = 0;

  Configuration conf = buildConf("refresh token key",
      Long.toString(tokenExpires),
      "joebob",
      REFRESH_ADDRESS);

  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now()).thenReturn(tokenExpires + 1000l);

  AccessTokenProvider tokenProvider =
      new ConfRefreshTokenBasedAccessTokenProvider(mockTimer);
  tokenProvider.setConf(conf);

  // Build mock server to receive refresh request

  ClientAndServer mockServer  = startClientAndServer(PORT);

  HttpRequest expectedRequest = request()
      .withMethod("POST")
      .withPath("/refresh")
      // Note, OkHttp does not sort the param values, so we need to
      // do it ourselves via the ordering provided to ParameterBody...
      .withBody(
          ParameterBody.params(
              Parameter.param(CLIENT_ID, "joebob"),
              Parameter.param(GRANT_TYPE, REFRESH_TOKEN),
              Parameter.param(REFRESH_TOKEN, "refresh token key")));

  MockServerClient mockServerClient = new MockServerClient("localhost", PORT);

  // https://tools.ietf.org/html/rfc6749#section-5.1
  Map<String, Object> map = new TreeMap<>();

  map.put(EXPIRES_IN, "0987654321");
  map.put(TOKEN_TYPE, BEARER);
  map.put(ACCESS_TOKEN, "new access token");

  ObjectMapper mapper = new ObjectMapper();
  
  HttpResponse resp = response()
      .withStatusCode(HttpStatus.SC_OK)
      .withHeaders(
          CONTENT_TYPE_APPLICATION_JSON
      )
      .withBody(mapper.writeValueAsString(map));

  mockServerClient
      .when(expectedRequest, exactly(1))
      .respond(resp);

  assertEquals("new access token", tokenProvider.getAccessToken());

  mockServerClient.verify(expectedRequest);

  mockServerClient.clear(expectedRequest);
  mockServer.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:64,代码来源:TestRefreshTokenTimeBasedTokenRefresher.java


示例12: refreshUrlIsCorrect

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
@Test
public void refreshUrlIsCorrect() throws IOException {
  final int PORT = ServerSocketUtil.getPort(0, 20);
  final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";

  long tokenExpires = 0;

  Configuration conf = buildConf("myreallycoolcredential",
      Long.toString(tokenExpires),
      CLIENT_ID_FOR_TESTING,
      REFRESH_ADDRESS);

  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now()).thenReturn(tokenExpires + 1000l);

  AccessTokenProvider credProvider =
      new ConfCredentialBasedAccessTokenProvider(mockTimer);
  credProvider.setConf(conf);
  
  // Build mock server to receive refresh request
  ClientAndServer mockServer  = startClientAndServer(PORT);

  HttpRequest expectedRequest = request()
      .withMethod("POST")
      .withPath("/refresh")
      .withBody( 
      // Note, OkHttp does not sort the param values, so we need to do
      // it ourselves via the ordering provided to ParameterBody...
          ParameterBody.params(
              Parameter.param(CLIENT_SECRET, "myreallycoolcredential"),
              Parameter.param(GRANT_TYPE, CLIENT_CREDENTIALS),
              Parameter.param(CLIENT_ID, CLIENT_ID_FOR_TESTING)
              ));

  MockServerClient mockServerClient = new MockServerClient("localhost", PORT);

  // https://tools.ietf.org/html/rfc6749#section-5.1
  Map<String, Object> map = new TreeMap<>();
  
  map.put(EXPIRES_IN, "0987654321");
  map.put(TOKEN_TYPE, "bearer");
  map.put(ACCESS_TOKEN, "new access token");

  ObjectMapper mapper = new ObjectMapper();
  
  HttpResponse resp = response()
      .withStatusCode(HttpStatus.SC_OK)
      .withHeaders(
          CONTENT_TYPE_APPLICATION_JSON
      )
      .withBody(mapper.writeValueAsString(map));

  mockServerClient
      .when(expectedRequest, exactly(1))
      .respond(resp);

  assertEquals("new access token", credProvider.getAccessToken());

  mockServerClient.verify(expectedRequest);

  mockServerClient.clear(expectedRequest);
  mockServer.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:64,代码来源:TestClientCredentialTimeBasedTokenRefresher.java


示例13: Groups

import org.apache.hadoop.util.Timer; //导入依赖的package包/类
public Groups(Configuration conf) {
  this(conf, new Timer());
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:4,代码来源:Groups.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SVGLength类代码示例发布时间:2022-05-22
下一篇:
Java TelescopeLayout类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap