gpt4 book ai didi

org.infinispan.counter.api.WeakCounter.sync()方法的使用及代码示例

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

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

WeakCounter.sync介绍

[英]It returns a synchronous weak counter for this instance.
[中]

代码示例

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

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

代码示例来源: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().reset();
      } else {
        WeakCounter weakCounter = counterManager.getWeakCounter(counterName);
        weakCounter.sync().reset();
      }
    }
    return new ModelNode();
  }
}

代码示例来源: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.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();
  }
}

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

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) {
  final ModelNode result = new ModelNode();
  final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
  final String cacheContainerName = address.getElement(CACHE_CONTAINER_INDEX).getValue();
  final String counterType = address.getElement(COUNTER_INDEX).getKey();
  final String counterName = address.getElement(COUNTER_INDEX).getValue();
  final ServiceController<?> controller = context.getServiceRegistry(false)
      .getService(CacheContainerServiceName.CACHE_CONTAINER.getServiceName(cacheContainerName));
  Long value;
  if (controller != null) {
    DefaultCacheContainer cacheManager = (DefaultCacheContainer) controller.getValue();
    CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(cacheManager);
    if (ModelKeys.STRONG_COUNTER.equals(counterType)) {
      StrongCounter sc = counterManager.getStrongCounter(counterName);
      value = sc.sync().getValue();
    } else {
      WeakCounter wc = counterManager.getWeakCounter(counterName);
      value = wc.sync().getValue();
    }
    result.set(value);
  }
  context.getResult().set(result);
}

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

private void incrementCounter(CounterManager counterManager) {
  switch (type) {
   case UNBOUNDED_STRONG:
   case BOUNDED_STRONG:
     counterManager.getStrongCounter(name).sync().incrementAndGet();
     break;
   case WEAK:
     counterManager.getWeakCounter(name).sync().increment();
     break;
  }
}

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

@Test
public void testCounters() {
 CounterManager counterManager = RemoteCounterManagerFactory.asCounterManager(remoteCacheManager);
 counterManager.defineCounter("c1", CounterConfiguration.builder(CounterType.BOUNDED_STRONG)
    .upperBound(10)
    .initialValue(1)
    .build());
 counterManager.defineCounter("c2", CounterConfiguration.builder(CounterType.WEAK)
    .initialValue(5)
    .build());
 SyncStrongCounter c1 = counterManager.getStrongCounter("c1").sync();
 SyncWeakCounter c2 = counterManager.getWeakCounter("c2").sync();
 assertEquals(1, c1.getValue());
 assertEquals(5, c2.getValue());
}

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