本文整理汇总了Java中org.redisson.api.RAtomicLong类的典型用法代码示例。如果您正苦于以下问题:Java RAtomicLong类的具体用法?Java RAtomicLong怎么用?Java RAtomicLong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RAtomicLong类属于org.redisson.api包,在下文中一共展示了RAtomicLong类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
public static void main(String[] args) {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
RAtomicLong atomicLong = redisson.getAtomicLong("myLong");
atomicLong.getAndDecrement();
atomicLong.getAndIncrement();
atomicLong.addAndGet(10L);
atomicLong.compareAndSet(29, 412);
atomicLong.decrementAndGet();
atomicLong.incrementAndGet();
atomicLong.getAndAdd(302);
atomicLong.getAndDecrement();
atomicLong.getAndIncrement();
redisson.shutdown();
}
开发者ID:redisson,项目名称:redisson-examples,代码行数:21,代码来源:AtomicLongExamples.java
示例2: main
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Bench<RedissonClient> bench = new RedissonBench() {
@Override
public void executeOperation(String data, RedissonClient benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
RAtomicLong atomic = benchInstance.getAtomicLong("incr_" + threadNumber + "_" + iteration);
Timer.Context time = metrics.timer("list").time();
atomic.incrementAndGet();
time.stop();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:16,代码来源:AtomicLongIncBenchmark.java
示例3: decode
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException
{
Collection<String> shopifyApiCallLimitHeader = response.headers().get("HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT");
String[] callLimitValues = shopifyApiCallLimitHeader.iterator().next().split("/");
if(callLimitValues[0] != null && callLimitValues[0] != "")
{
Long createdCalls = Long.parseLong(callLimitValues[0]);
Long remainingCalls = _shopifyRedissonManager.calculateAvalableCredits(createdCalls);
RedissonClient redisson = _shopifyRedissonManager.getRedissonClient();
// Lock per shopify store. The lock is distributed, so it will work for multiple threads and applications.
RLock lock = redisson.getLock(_shopifyRedissonManager.getMyShopifyUrl());
RAtomicLong remainingCreditsAtomic = redisson.getAtomicLong(_shopifyRedissonManager.getRemainingCreditsKey());
RAtomicLong lastRequestTimeAtomic = redisson.getAtomicLong(_shopifyRedissonManager.getLastRequestTimeKey());
remainingCreditsAtomic.set(remainingCalls);
lastRequestTimeAtomic.set(System.currentTimeMillis());
lock.unlock();
}
return super.decode(response, type);
}
开发者ID:SevenSpikes,项目名称:shopify-api-java-wrapper,代码行数:30,代码来源:ShopifyJacksonDecoder.java
示例4: incrementInstanceCount
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public long incrementInstanceCount(String key) {
RAtomicLong instanceCount = redissonClient.getAtomicLong(createGlobalKey(key));
return instanceCount.getAndIncrement();
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:6,代码来源:DistributedInstanceManagerRedissonImpl.java
示例5: decrementInstanceCount
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public long decrementInstanceCount(String key) {
RAtomicLong instanceCount = redissonClient.getAtomicLong(createGlobalKey(key));
return (instanceCount.get() > 0) ? instanceCount.getAndDecrement() : 0;
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:6,代码来源:DistributedInstanceManagerRedissonImpl.java
示例6: getValue
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public long getValue(String key) {
RAtomicLong value = setExpiry(key);
return value.get();
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:6,代码来源:DistributedAtomicLongRedissonImpl.java
示例7: incrementAndGet
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public long incrementAndGet(String key) {
RAtomicLong value = setExpiry(key);
return value.getAndIncrement();
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:6,代码来源:DistributedAtomicLongRedissonImpl.java
示例8: decrementAndGet
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public long decrementAndGet(String key) {
RAtomicLong value = setExpiry(key);
return (value.get() > 0) ? value.getAndDecrement() : 0;
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:6,代码来源:DistributedAtomicLongRedissonImpl.java
示例9: RedissonCounter
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
public RedissonCounter(RAtomicLong rAtomicLong) {
this.atomicLong = rAtomicLong;
}
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:4,代码来源:RedissonCounter.java
示例10: apply
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
@Override
public void apply(RequestTemplate template)
{
Boolean tryGetCredit = true;
RedissonClient redisson = _shopifyRedissonManager.getRedissonClient();
while (tryGetCredit)
{
// Lock per shopify store. The lock is distributed, so it will work for multiple threads and applications.
RLock lock = redisson.getLock(_shopifyRedissonManager.getMyShopifyUrl());
RAtomicLong isDefaultRemainingCreditsValueSet = redisson.getAtomicLong(_shopifyRedissonManager.getIsDefaultRemainingCreditsValueSetKey());
RAtomicLong remainingCreditsAtomic = redisson.getAtomicLong(_shopifyRedissonManager.getRemainingCreditsKey());
if(isDefaultRemainingCreditsValueSet.get() == 0)
{
remainingCreditsAtomic.set(_shopifyRedissonManager.getCreditLimit());
isDefaultRemainingCreditsValueSet.set(1);
}
RAtomicLong lastRequestTimeAtomic = redisson.getAtomicLong(_shopifyRedissonManager.getLastRequestTimeKey());
Long remainingCredits = remainingCreditsAtomic.get();
if(remainingCredits > 0)
{
// These values are set here, because a request can be made while the current request is still in progress.
// We set the actual values inside the decoder (when the request is complete), but if we don't set them here
// as well a raised condition can occur.
remainingCreditsAtomic.set(remainingCredits - 1);
lastRequestTimeAtomic.set(System.currentTimeMillis());
tryGetCredit = false;
lock.unlock();
}
else
{
// Check if there were enough time since the last request time.
// If the latest request's remaining calls were 0 and no calls were made after that, the remaining credits
// will not be updated. This is why the last request time is used as well.
long availableCalls = (long)Math.floor((System.currentTimeMillis() - lastRequestTimeAtomic.get())/500);
if(availableCalls > 0)
{
remainingCreditsAtomic.set(availableCalls - 1);
lastRequestTimeAtomic.set(System.currentTimeMillis());
tryGetCredit = false;
lock.unlock();
}
else
{
lock.unlock();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("Error while waiting for available Shopify call credit. " + e.getMessage());
}
}
}
}
}
开发者ID:SevenSpikes,项目名称:shopify-api-java-wrapper,代码行数:68,代码来源:RequestLimitInterceptor.java
示例11: setExpiry
import org.redisson.api.RAtomicLong; //导入依赖的package包/类
/**
* Set the expiry if not already set and one required. If timeToLive is less
* than or equal to zero do not set expiry and allow to remain until
* explicitly deleted.
*
* @param key the name of distributed AtomicLong.
* @return RAtomicLong
*/
private RAtomicLong setExpiry(String key) {
RAtomicLong value = redissonClient.getAtomicLong(createGlobalKey(key));
if (value.remainTimeToLive() < 0 && timeToLive >= 0) {
value.expire(timeToLive, TimeUnit.SECONDS);
}
return value;
}
开发者ID:ONSdigital,项目名称:rm-common-service,代码行数:16,代码来源:DistributedAtomicLongRedissonImpl.java
注:本文中的org.redisson.api.RAtomicLong类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论