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


Java Ticker类代码示例

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


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

示例1: invoke

import com.google.common.base.Ticker; //导入依赖的package包/类
public ListenableFuture<Object> invoke(Optional<String> addressSelectionContext, Map<String, String> headers, List<Object> parameters)
{
    if (!headerParameters.isEmpty()) {
        headers = new LinkedHashMap<>(headers);
        for (Entry<Integer, ThriftHeaderParameter> entry : headerParameters.entrySet()) {
            headers.put(entry.getValue().getName(), (String) parameters.get(entry.getKey()));
        }

        ImmutableList.Builder<Object> newParameters = ImmutableList.builder();
        for (int index = 0; index < parameters.size(); index++) {
            if (!headerParameters.containsKey(index)) {
                newParameters.add(parameters.get(index));
            }
        }
        parameters = newParameters.build();
    }
    return createDriftMethodInvocation(invoker, metadata, headers, parameters, retryPolicy, addressSelector, addressSelectionContext, stat, Ticker.systemTicker());
}
 
开发者ID:airlift,项目名称:drift,代码行数:19,代码来源:DriftMethodHandler.java

示例2: createDriftMethodInvocation

import com.google.common.base.Ticker; //导入依赖的package包/类
static <A extends Address> DriftMethodInvocation<A> createDriftMethodInvocation(
        MethodInvoker invoker,
        MethodMetadata metadata,
        Map<String, String> headers,
        List<Object> parameters,
        RetryPolicy retryPolicy,
        AddressSelector<A> addressSelector,
        Optional<String> addressSelectionContext,
        MethodInvocationStat stat,
        Ticker ticker)
{
    DriftMethodInvocation<A> invocation = new DriftMethodInvocation<>(
            invoker,
            metadata,
            headers,
            parameters,
            retryPolicy,
            addressSelector,
            addressSelectionContext,
            stat,
            ticker);
    // invocation can not be started from constructor, because it may start threads that can call back into the unpublished object
    invocation.nextAttempt();
    return invocation;
}
 
开发者ID:airlift,项目名称:drift,代码行数:26,代码来源:DriftMethodInvocation.java

示例3: createDriftMethodInvocation

import com.google.common.base.Ticker; //导入依赖的package包/类
private static DriftMethodInvocation<?> createDriftMethodInvocation(
        RetryPolicy retryPolicy,
        TestingMethodInvocationStat stat,
        MockMethodInvoker invoker,
        AddressSelector<?> addressSelector,
        Ticker ticker)
{
    return DriftMethodInvocation.createDriftMethodInvocation(
            invoker,
            METHOD_METADATA,
            ImmutableMap.of(),
            ImmutableList.of(),
            retryPolicy,
            addressSelector,
            Optional.empty(),
            stat,
            ticker);
}
 
开发者ID:airlift,项目名称:drift,代码行数:19,代码来源:TestDriftMethodInvocation.java

示例4: ManualSerializationProxy

import com.google.common.base.Ticker; //导入依赖的package包/类
private ManualSerializationProxy(
    Strength keyStrength,
    Strength valueStrength,
    Equivalence<Object> keyEquivalence,
    Equivalence<Object> valueEquivalence,
    long expireAfterWriteNanos,
    long expireAfterAccessNanos,
    long maxWeight,
    Weigher<K, V> weigher,
    int concurrencyLevel,
    RemovalListener<? super K, ? super V> removalListener,
    Ticker ticker,
    CacheLoader<? super K, V> loader) {
  this.keyStrength = keyStrength;
  this.valueStrength = valueStrength;
  this.keyEquivalence = keyEquivalence;
  this.valueEquivalence = valueEquivalence;
  this.expireAfterWriteNanos = expireAfterWriteNanos;
  this.expireAfterAccessNanos = expireAfterAccessNanos;
  this.maxWeight = maxWeight;
  this.weigher = weigher;
  this.concurrencyLevel = concurrencyLevel;
  this.removalListener = removalListener;
  this.ticker = (ticker == Ticker.systemTicker() || ticker == NULL_TICKER) ? null : ticker;
  this.loader = loader;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:LocalCache.java

示例5: LocalCache

import com.google.common.base.Ticker; //导入依赖的package包/类
LocalCache(CacheBuilder<? super K, ? super V> builder, CacheLoader<? super K, V> loader) {
  this.loader = loader;
  this.removalListener = builder.removalListener;
  this.expireAfterAccess = builder.expireAfterAccessNanos;
  this.expireAfterWrite = builder.expireAfterWriteNanos;
  this.statsCounter = builder.getStatsCounterSupplier().get();

  /* Implements size-capped LinkedHashMap */
  final long maximumSize = builder.maximumSize;
  this.cachingHashMap = new CapacityEnforcingLinkedHashMap<K, V>(
      builder.getInitialCapacity(),
      0.75f,
      (builder.maximumSize != UNSET_INT),
      builder.maximumSize,
      statsCounter,
      removalListener);

  this.ticker = firstNonNull(builder.ticker, Ticker.systemTicker());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:LocalCache.java

示例6: testHandleForwardedRemoteReadRequest

import com.google.common.base.Ticker; //导入依赖的package包/类
@Test
public void testHandleForwardedRemoteReadRequest() throws Exception {
    final TestProbe probe = createProbe();
    final ReadTransactionRequest request =
            new ReadTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, true);
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    setupExecuteInActor();

    transaction.handleReplayedRemoteRequest(request, callback, Ticker.systemTicker().read());
    final ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(callback).accept(captor.capture());
    final Response<?, ?> value = captor.getValue();
    Assert.assertTrue(value instanceof ReadTransactionSuccess);
    final ReadTransactionSuccess success = (ReadTransactionSuccess) value;
    Assert.assertTrue(success.getData().isPresent());
    Assert.assertEquals(DATA_1, success.getData().get());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:LocalProxyTransactionTest.java

示例7: testHandleForwardedRemoteExistsRequest

import com.google.common.base.Ticker; //导入依赖的package包/类
@Test
public void testHandleForwardedRemoteExistsRequest() throws Exception {
    final TestProbe probe = createProbe();
    final ExistsTransactionRequest request =
            new ExistsTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, true);
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    setupExecuteInActor();

    transaction.handleReplayedRemoteRequest(request, callback, Ticker.systemTicker().read());
    final ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(callback).accept(captor.capture());
    final Response<?, ?> value = captor.getValue();
    Assert.assertTrue(value instanceof ExistsTransactionSuccess);
    final ExistsTransactionSuccess success = (ExistsTransactionSuccess) value;
    Assert.assertTrue(success.getExists());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:LocalProxyTransactionTest.java

示例8: applyModifyTransactionRequest

import com.google.common.base.Ticker; //导入依赖的package包/类
private void applyModifyTransactionRequest(final boolean coordinated) {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder =
            new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    final TransactionModification write = new TransactionWrite(PATH_1, DATA_1);
    final TransactionModification merge = new TransactionMerge(PATH_2, DATA_2);
    final TransactionModification delete = new TransactionDelete(PATH_3);
    builder.addModification(write);
    builder.addModification(merge);
    builder.addModification(delete);
    builder.setSequence(0L);
    builder.setCommit(coordinated);
    final ModifyTransactionRequest request = builder.build();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    transaction.replayModifyTransactionRequest(request, callback, Ticker.systemTicker().read());
    verify(modification).write(PATH_1, DATA_1);
    verify(modification).merge(PATH_2, DATA_2);
    verify(modification).delete(PATH_3);
    final CommitLocalTransactionRequest commitRequest =
            getTester().expectTransactionRequest(CommitLocalTransactionRequest.class);
    Assert.assertEquals(modification, commitRequest.getModification());
    Assert.assertEquals(coordinated, commitRequest.isCoordinated());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:LocalReadWriteProxyTransactionTest.java

示例9: Client

import com.google.common.base.Ticker; //导入依赖的package包/类
public Client(String serviceName, CheckAggregationOptions checkOptions,
    ReportAggregationOptions reportOptions, QuotaAggregationOptions quotaOptions,
    ServiceControl transport, ThreadFactory threads,
    SchedulerFactory schedulers, int statsLogFrequency, @Nullable Ticker ticker) {
  ticker = ticker == null ? Ticker.systemTicker() : ticker;
  this.checkAggregator = new CheckRequestAggregator(serviceName, checkOptions, null, ticker);
  this.reportAggregator = new ReportRequestAggregator(serviceName, reportOptions, null, ticker);
  this.quotaAggregator = new QuotaRequestAggregator(serviceName, quotaOptions, ticker);
  this.serviceName = serviceName;
  this.ticker = ticker;
  this.transport = transport;
  this.threads = threads;
  this.schedulers = schedulers;
  this.scheduler  = null; // the scheduler is assigned when start is invoked
  this.schedulerThread = null;
  this.statsLogFrequency = statsLogFrequency;
  this.statistics = new Statistics();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:19,代码来源:Client.java

示例10: createCache

import com.google.common.base.Ticker; //导入依赖的package包/类
/**
 * Creates a {@link Cache} configured by this instance.
 *
 * @param <T>
 *            the type of the value stored in the Cache
 * @param out
 *            a concurrent {@code Deque} to which the cached values are
 *            added as they are removed from the cache
 * @param ticker
 *            the time source used to determine expiration
 * @return a {@link Cache} corresponding to this instance's values or
 *         {@code null} unless {@code #numEntries} is positive.
 */
@Nullable
public <T> Cache<String, T> createCache(final ConcurrentLinkedDeque<T> out, Ticker ticker) {
  Preconditions.checkNotNull(out, "The out deque cannot be null");
  Preconditions.checkNotNull(ticker, "The ticker cannot be null");
  if (numEntries <= 0) {
    return null;
  }
  final RemovalListener<String, T> listener = new RemovalListener<String, T>() {
    @Override
    public void onRemoval(RemovalNotification<String, T> notification) {
      out.addFirst(notification.getValue());
    }
  };
  CacheBuilder<String, T> b = CacheBuilder.newBuilder().maximumSize(numEntries).ticker(ticker)
      .removalListener(listener);
  if (expirationMillis >= 0) {
    b.expireAfterWrite(expirationMillis, TimeUnit.MILLISECONDS);
  }
  return b.build();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:34,代码来源:CheckAggregationOptions.java

示例11: createCache

import com.google.common.base.Ticker; //导入依赖的package包/类
/**
 * Creates a {@link Cache} configured by this instance.
 *
 * @param <T>
 *            the type of the value stored in the Cache
 * @param out
 *            a concurrent {@code Deque} to which cached values are added as
 *            they are removed from the cache
 * @param ticker
 *            the time source used to determine expiration
 * @return a {@link Cache} corresponding to this instance's values or
 *         {@code null} unless {@code #numEntries} is positive.
 */
@Nullable
public <T> Cache<String, T> createCache(final ConcurrentLinkedDeque<T> out, Ticker ticker) {
  Preconditions.checkNotNull(out, "The out deque cannot be null");
  Preconditions.checkNotNull(ticker, "The ticker cannot be null");
  if (numEntries <= 0) {
    return null;
  }
  final RemovalListener<String, T> listener = new RemovalListener<String, T>() {
    @Override
    public void onRemoval(RemovalNotification<String, T> notification) {
      out.addFirst(notification.getValue());
    }
  };
  CacheBuilder<String, T> b = CacheBuilder.newBuilder().maximumSize(numEntries).ticker(ticker)
      .removalListener(listener);
  if (flushCacheEntryIntervalMillis >= 0) {
    b.expireAfterWrite(flushCacheEntryIntervalMillis, TimeUnit.MILLISECONDS);
  }
  return b.build();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:34,代码来源:ReportAggregationOptions.java

示例12: setUp

import com.google.common.base.Ticker; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  testTicker = new FakeTicker();
  checkStub = mock(Check.class);
  reportStub = mock(Report.class);
  services = mock(Services.class);
  transport = mock(ServiceControl.class);
  threads = mock(ThreadFactory.class);
  aThread = mock(Thread.class);
  schedulers = mock(Client.SchedulerFactory.class);
  checkOptions = new CheckAggregationOptions();
  reportOptions = new ReportAggregationOptions();
  quotaOptions = new QuotaAggregationOptions();

  client =
      new Client(TEST_SERVICE_NAME, checkOptions, reportOptions, quotaOptions, transport, threads,
          schedulers, 1 /* ensure stats dumping code is touched */, testTicker);
  when(threads.newThread(any(Runnable.class))).thenReturn(aThread);
  when(schedulers.create(any(Ticker.class))).thenReturn(new Client.Scheduler(testTicker));
  when(transport.services()).thenReturn(services);
  when(services.check(eq(TEST_SERVICE_NAME), any(CheckRequest.class))).thenReturn(checkStub);
  when(services.report(eq(TEST_SERVICE_NAME), any(ReportRequest.class))).thenReturn(reportStub);
  when(checkStub.execute()).thenReturn(CheckResponse.newBuilder().build());
  when(reportStub.execute()).thenReturn(ReportResponse.newBuilder().build());
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:26,代码来源:ClientTest.java

示例13: testLoadingCacheExpireAfterWrite

import com.google.common.base.Ticker; //导入依赖的package包/类
@Test
public void testLoadingCacheExpireAfterWrite() throws Exception {
    TradeAccountRemovalListener removalListener = new TradeAccountRemovalListener();
    LoadingCache<String, TradeAccount> tradeAccountCache = CacheBuilder.newBuilder()
            .expireAfterWrite(5L, TimeUnit.MILLISECONDS)
            .maximumSize(5000L)
            .removalListener(removalListener)
            .ticker(Ticker.systemTicker())
            .build(new CacheLoader<String, TradeAccount>() {
                @Override
                public TradeAccount load(String key) throws Exception {
                    return tradeAccountService.getTradeAccountById(key);
                }
            });

    //223,"Rogers, Jim",250000.12
    TradeAccount tradeAccount = tradeAccountCache.get("223");
    assertThat(tradeAccount.getBalance(), is(250000.12));
    Thread.sleep(10L);
    tradeAccountCache.get("223");
    assertThat(removalListener.getRemovalCause(), is(RemovalCause.EXPIRED));
    assertThat(removalListener.getRemovedValue(), is(tradeAccount));
}
 
开发者ID:wsldl123292,项目名称:testeverything,代码行数:24,代码来源:RemovalListenerTest.java

示例14: testRefreshingCacheValues

import com.google.common.base.Ticker; //导入依赖的package包/类
@Test
public void testRefreshingCacheValues() throws Exception {
    TradeAccountRemovalListener removalListener = new TradeAccountRemovalListener();
    LoadingCache<String, TradeAccount> tradeAccountCache = CacheBuilder.newBuilder()
            .concurrencyLevel(10)
            .refreshAfterWrite(5L, TimeUnit.MILLISECONDS)
            .removalListener(removalListener)
            .ticker(Ticker.systemTicker())
            .recordStats()
            .build(new CacheLoader<String, TradeAccount>() {
                @Override
                public TradeAccount load(String key) throws Exception {
                    return tradeAccountService.getTradeAccountById(key);
                }
            });

    //223,"Rogers, Jim",250000.12
    TradeAccount tradeAccount = tradeAccountCache.get("223");
    assertThat(tradeAccount.getBalance(), is(250000.12));
    Thread.sleep(10L);
    tradeAccountCache.get("223");
    CacheStats stats = tradeAccountCache.stats();
    assertThat(stats.loadSuccessCount(),is(2l));
    assertThat(removalListener.getRemovalCause(), is(RemovalCause.REPLACED));
    assertThat(removalListener.getRemovedValue(), is(tradeAccount));
}
 
开发者ID:wsldl123292,项目名称:testeverything,代码行数:27,代码来源:RemovalListenerTest.java

示例15: ManualSerializationProxy

import com.google.common.base.Ticker; //导入依赖的package包/类
private ManualSerializationProxy(
    Strength keyStrength, Strength valueStrength,
    Equivalence<Object> keyEquivalence, Equivalence<Object> valueEquivalence,
    long expireAfterWriteNanos, long expireAfterAccessNanos, long maxWeight,
    Weigher<K, V> weigher, int concurrencyLevel,
    RemovalListener<? super K, ? super V> removalListener,
    Ticker ticker, CacheLoader<? super K, V> loader) {
  this.keyStrength = keyStrength;
  this.valueStrength = valueStrength;
  this.keyEquivalence = keyEquivalence;
  this.valueEquivalence = valueEquivalence;
  this.expireAfterWriteNanos = expireAfterWriteNanos;
  this.expireAfterAccessNanos = expireAfterAccessNanos;
  this.maxWeight = maxWeight;
  this.weigher = weigher;
  this.concurrencyLevel = concurrencyLevel;
  this.removalListener = removalListener;
  this.ticker = (ticker == Ticker.systemTicker() || ticker == NULL_TICKER)
      ? null : ticker;
  this.loader = loader;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:22,代码来源:LocalCache.java


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