gpt4 book ai didi

org.infinispan.counter.api.WeakCounter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-27 11:47:05 28 4
gpt4 key购买 nike

本文整理了Java中org.infinispan.counter.api.WeakCounter类的一些代码示例,展示了WeakCounter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeakCounter类的具体详情如下:
包路径:org.infinispan.counter.api.WeakCounter
类名称:WeakCounter

WeakCounter介绍

[英]A weak consistent counter interface.

This interface represents a weak counter in the way that the write operations does not return a consistent results. In this way, all the writes return a CompletableFuture.

Note: the reset operation is not atomic.
[中]弱一致计数器接口。
此接口表示一个弱计数器,因为写入操作不会返回一致的结果。通过这种方式,所有写入都会返回一个完整的未来。
注意:重置操作不是原子操作。

代码示例

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* Increments the counter.
*/
default CompletableFuture<Void> increment() {
 return add(1L);
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* @see WeakCounter#getValue()
*/
@Override
public long getValue() {
 return counter.getValue();
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* @see WeakCounter#reset()
*/
@Override
public void reset() {
 awaitCounterOperation(counter.reset());
}

代码示例来源:origin: infinispan/infinispan-simple-tutorials

counter3.add(5).thenAccept(aVoid -> System.out.println("Adding 5 to counter-3 completed!")).get();
System.out.println("Counter-3 value is " + counter3.getValue());

代码示例来源:origin: org.infinispan/infinispan-clustered-counter

public WeakTestCounter(WeakCounter counter) {
 this.counter = counter;
 this.syncCounter = counter.sync();
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

@Override
public <L extends CounterListener> Handle<L> addListenerTo(WeakCounter counter, L logger) {
 return counter.addListener(logger);
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

@Override
  void assertCounterNameAndConfiguration(String counterName, CounterConfiguration configuration) {
   allCounterManagerSupplier.get().forEach(counterManager -> {
     WeakCounter counter = counterManager.getWeakCounter(counterName);
     assertEquals(counterName, counter.getName());
     assertEquals(configuration, counter.getConfiguration());
   });
  }
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* @see WeakCounter#remove()
*/
@Override
public void remove() {
 awaitCounterOperation(counter.remove());
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* @see WeakCounter#getConfiguration()
*/
@Override
public CounterConfiguration getConfiguration() {
 return counter.getConfiguration();
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* @see WeakCounter#getName()
*/
@Override
public String getName() {
 return counter.getName();
}

代码示例来源:origin: infinispan/infinispan-simple-tutorials

counter3.add(5).thenAccept(aVoid -> System.out.println("Adding 5 to counter-3 completed!")).get();
System.out.println("Counter-3 value is " + counter3.getValue());

代码示例来源:origin: org.infinispan.server/infinispan-server-infinispan

@Override
  protected ModelNode invoke(CounterManager counterManager, ModelNode operation) {
    final String counterName = counterName(operation);
    final String counterType = counterType(operation);
    if (counterManager.isDefined(counterName)) {
      boolean isStrongCounter = ModelKeys.STRONG_COUNTER.equals(counterType);
      if (isStrongCounter) {
        StrongCounter strongCounter = counterManager.getStrongCounter(counterName);
        strongCounter.sync().incrementAndGet();
      } else {
        WeakCounter weakCounter = counterManager.getWeakCounter(counterName);
        weakCounter.sync().increment();
      }
    }
    return new ModelNode();
  }
}

代码示例来源:origin: org.infinispan/infinispan-clustered-counter

@Override
public <T extends CounterListener> Handle<T> addListener(T listener) {
 return counter.addListener(listener);
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

@Override
void remove(WeakCounter counter) {
 awaitCounterOperation(counter.remove());
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

@Override
public void testGetCounterNames(Method method) {
 //we need to cleanup other tests counters from the caches.
 clearCaches();
 final Random random = generateRandom();
 final String counterNamePrefix = method.getName();
 final CounterManager counterManager = getTestedCounterManager();
 final int numCounters = random.nextInt(10) + 1;
 final List<CounterConfiguration> configList = new ArrayList<>(numCounters);
 final Set<String> counterSet = new HashSet<>();
 //adds some randomness to the test by adding 1 to 10 counters
 for (int i = 0; i < numCounters; ++i) {
   CounterConfiguration config = builder(CounterType.valueOf(random.nextInt(3))).initialValue(random.nextLong())
      .build();
   assertTrue(counterManager.defineCounter(counterNamePrefix + i, config));
   configList.add(config);
   counterSet.add(counterNamePrefix + i);
 }
 Set<String> counterNames = new HashSet<>(counterManager.getCounterNames());
 assertEquals(counterSet, counterNames);
 for (int i = 0; i < numCounters; ++i) {
   final String counterName = counterNamePrefix + i;
   assertTrue(counterNames.contains(counterName));
   CounterConfiguration config = configList.get(i);
   CounterConfiguration storedConfig = config.type() == CounterType.WEAK ?
                     counterManager.getWeakCounter(counterName).getConfiguration() :
                     counterManager.getStrongCounter(counterName).getConfiguration();
   assertEquals(config, storedConfig);
 }
}

代码示例来源:origin: org.infinispan/infinispan-clustered-counter

public void testSingleConcurrencyLevel() throws ExecutionException, InterruptedException {
 final CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(manager(0));
 final String counterName = "c1-counter";
 counterManager.defineCounter(counterName,
    CounterConfiguration.builder(CounterType.WEAK).concurrencyLevel(1).build());
 WeakCounter wc = counterManager.getWeakCounter(counterName);
 wc.add(2).get();
 assertEquals(2, wc.getValue());
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* Decrements the counter.
*/
default CompletableFuture<Void> decrement() {
 return add(-1L);
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

private void handleGetWeak(HotRodHeader header, WeakCounter counter) {
 longResultHandler(header, counter.getValue(), null);
}

代码示例来源:origin: org.infinispan/infinispan-server-hotrod

private void handleResetWeak(HotRodHeader header, WeakCounter counter) {
 counter.reset().whenComplete((value, throwable) -> voidResultHandler(header, throwable));
}

代码示例来源:origin: org.infinispan.server/infinispan-server-infinispan

@Override
  protected ModelNode invoke(CounterManager counterManager, ModelNode operation) {
    final String counterName = counterName(operation);
    final String counterType = counterType(operation);
    if (counterManager.isDefined(counterName)) {
      boolean isStrongCounter = ModelKeys.STRONG_COUNTER.equals(counterType);
      if (isStrongCounter) {
        StrongCounter strongCounter = counterManager.getStrongCounter(counterName);
        strongCounter.sync().decrementAndGet();
      } else {
        WeakCounter weakCounter = counterManager.getWeakCounter(counterName);
        weakCounter.sync().decrement();
      }
    }
    return new ModelNode();
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com