use of org.redisson.misc.HashValue in project redisson by redisson.
the class BaseTransactionalSet method scanIterator.
protected ScanResult<Object> scanIterator(String name, RedisClient client, long startPos, String pattern, int count) {
ScanResult<Object> res = scanIteratorSource(name, client, startPos, pattern, count);
Map<HashValue, Object> newstate = new HashMap<>(state);
for (Iterator<Object> iterator = res.getValues().iterator(); iterator.hasNext(); ) {
Object entry = iterator.next();
Object value = newstate.remove(toHash(entry));
if (value == NULL) {
iterator.remove();
}
}
if (startPos == 0) {
for (Entry<HashValue, Object> entry : newstate.entrySet()) {
if (entry.getValue() == NULL) {
continue;
}
res.getValues().add(entry.getValue());
}
}
return res;
}
use of org.redisson.misc.HashValue in project redisson by redisson.
the class BaseTransactionalSet method moveAsync.
public RFuture<Boolean> moveAsync(String destination, V value) {
RSet<V> destinationSet = new RedissonSet<V>(object.getCodec(), commandExecutor, destination, null);
RPromise<Boolean> result = new RedissonPromise<Boolean>();
RLock destinationLock = getLock(destinationSet, value);
RLock lock = getLock(set, value);
RedissonMultiLock multiLock = new RedissonMultiLock(destinationLock, lock);
long threadId = Thread.currentThread().getId();
multiLock.lockAsync(timeout, TimeUnit.MILLISECONDS).onComplete((res, e) -> {
if (e != null) {
multiLock.unlockAsync(threadId);
result.tryFailure(e);
return;
}
HashValue keyHash = toHash(value);
Object currentValue = state.get(keyHash);
if (currentValue != null) {
operations.add(createMoveOperation(destination, value, threadId));
if (currentValue == NULL) {
result.trySuccess(false);
} else {
state.put(keyHash, NULL);
result.trySuccess(true);
}
return;
}
set.containsAsync(value).onComplete((r, ex) -> {
if (ex != null) {
result.tryFailure(ex);
return;
}
operations.add(createMoveOperation(destination, value, threadId));
if (r) {
state.put(keyHash, NULL);
}
result.trySuccess(r);
});
});
return result;
}
use of org.redisson.misc.HashValue in project redisson by redisson.
the class BaseTransactionalMap method addAndGetOperationAsync.
protected RFuture<V> addAndGetOperationAsync(K key, Number value) {
RPromise<V> result = new RedissonPromise<V>();
long threadId = Thread.currentThread().getId();
executeLocked(result, key, new Runnable() {
@Override
public void run() {
HashValue keyHash = toKeyHash(key);
MapEntry entry = state.get(keyHash);
if (entry != null) {
BigDecimal currentValue = BigDecimal.ZERO;
if (entry != MapEntry.NULL) {
currentValue = (BigDecimal) entry.getValue();
}
BigDecimal res = currentValue.add(new BigDecimal(value.toString()));
operations.add(new MapAddAndGetOperation(map, key, value, transactionId, threadId));
state.put(keyHash, new MapEntry(key, res));
if (deleted != null) {
deleted = false;
}
NumberConvertor convertor = new NumberConvertor(value.getClass());
result.trySuccess((V) convertor.convert(res.toPlainString()));
return;
}
map.getAsync(key).onComplete((r, e) -> {
if (e != null) {
result.tryFailure(e);
return;
}
BigDecimal currentValue = new BigDecimal(r.toString());
BigDecimal res = currentValue.add(new BigDecimal(value.toString()));
operations.add(new MapAddAndGetOperation(map, key, value, transactionId, threadId));
state.put(keyHash, new MapEntry(key, res));
if (deleted != null) {
deleted = false;
}
NumberConvertor convertor = new NumberConvertor(value.getClass());
result.trySuccess((V) convertor.convert(res.toPlainString()));
});
}
});
return result;
}
use of org.redisson.misc.HashValue in project redisson by redisson.
the class BaseTransactionalMap method getOperationAsync.
protected RFuture<V> getOperationAsync(K key) {
HashValue keyHash = toKeyHash(key);
MapEntry entry = state.get(keyHash);
if (entry != null) {
if (entry == MapEntry.NULL) {
return RedissonPromise.newSucceededFuture(null);
} else {
return RedissonPromise.newSucceededFuture((V) entry.getValue());
}
}
return ((RedissonMap<K, V>) map).getOperationAsync(key);
}
use of org.redisson.misc.HashValue in project redisson by redisson.
the class BaseTransactionalSet method readAllAsync.
public RFuture<Set<V>> readAllAsync() {
RPromise<Set<V>> result = new RedissonPromise<>();
RFuture<Set<V>> future = readAllAsyncSource();
future.onComplete((res, e) -> {
if (e != null) {
result.tryFailure(e);
return;
}
Map<HashValue, Object> newstate = new HashMap<>(state);
for (Iterator<V> iterator = res.iterator(); iterator.hasNext(); ) {
V key = iterator.next();
Object value = newstate.remove(toHash(key));
if (value == NULL) {
iterator.remove();
}
}
for (Object value : newstate.values()) {
if (value == NULL) {
continue;
}
res.add((V) value);
}
result.trySuccess(res);
});
return result;
}
Aggregations