Code formatted according to checkstyle rules

pull/1923/head
Nikita Koksharov 6 years ago
parent 901a5a797b
commit 016d3395f1

@ -72,7 +72,7 @@
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName">
<property name="format" value="^([A-Z_][A-Z0-9]*(_[A-Z0-9]+)*|_log)$"/>
<property name="format" value="^log(ger)?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
@ -169,7 +169,9 @@
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="NestedIfDepth"/>
<module name="NestedIfDepth">
<property name="max" value="2"/>
</module>
<module name="NestedTryDepth"/>
<module name="SuperClone"/>
<module name="IllegalCatch">
@ -186,8 +188,9 @@
<module name="FinalClass"/>
<!--module name="HideUtilityClassConstructor"/-->
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<module name="VisibilityModifier">
<property name="packageAllowed" value="true"/>
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->

@ -360,7 +360,7 @@
</execution>
</executions>
<configuration>
<includes>**/org/redisson/api/**/*.java</includes>
<includes>**/org/redisson/api/**/*.java,**/org/redisson/cache/**/*.java</includes>
<consoleOutput>true</consoleOutput>
<enableRSS>false</enableRSS>
<configLocation>/checkstyle.xml</configLocation>

@ -300,7 +300,7 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
abstract class MapIterator<M> implements Iterator<M> {
final Iterator<Map.Entry<K, CachedValue<K, V>>> keyIterator = map.entrySet().iterator();
private final Iterator<Map.Entry<K, CachedValue<K, V>>> keyIterator = map.entrySet().iterator();
Map.Entry<K, CachedValue<K, V>> mapEntry;
@ -416,12 +416,12 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
}
final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
final class EntrySet extends AbstractSet<Map.Entry<K, V>> {
public final Iterator<Map.Entry<K,V>> iterator() {
return new MapIterator<Map.Entry<K,V>>() {
public Iterator<Map.Entry<K, V>> iterator() {
return new MapIterator<Map.Entry<K, V>>() {
@Override
public Map.Entry<K,V> next() {
public Map.Entry<K, V> next() {
if (mapEntry == null) {
throw new NoSuchElementException();
}
@ -442,18 +442,18 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
};
}
public final boolean contains(Object o) {
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey();
V value = get(key);
return value != null && value.equals(e);
}
public final boolean remove(Object o) {
public boolean remove(Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey();
Object value = e.getValue();
return AbstractCacheMap.this.map.remove(key, value);
@ -461,11 +461,11 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
return false;
}
public final int size() {
public int size() {
return AbstractCacheMap.this.size();
}
public final void clear() {
public void clear() {
AbstractCacheMap.this.clear();
}

@ -59,8 +59,8 @@ public class LFUCacheMap<K, V> extends AbstractCacheMap<K, V> {
public static class LFUCachedValue extends StdCachedValue {
Long id;
long accessCount;
private final Long id;
private long accessCount;
public LFUCachedValue(long id, Object key, Object value, long ttl, long maxIdleTime) {
super(key, value, ttl, maxIdleTime);
@ -87,13 +87,13 @@ public class LFUCacheMap<K, V> extends AbstractCacheMap<K, V> {
@Override
protected void onValueCreate(CachedValue value) {
MapKey key = toKey((LFUCachedValue)value);
accessMap.put(key, (LFUCachedValue)value);
MapKey key = toKey((LFUCachedValue) value);
accessMap.put(key, (LFUCachedValue) value);
}
@Override
protected void onValueRead(CachedValue value) {
addAccessCount((LFUCachedValue)value, 1);
addAccessCount((LFUCachedValue) value, 1);
}
private MapKey toKey(LFUCachedValue value) {
@ -103,7 +103,7 @@ public class LFUCacheMap<K, V> extends AbstractCacheMap<K, V> {
@Override
protected void onValueRemove(CachedValue value) {
synchronized (value) {
MapKey key = toKey((LFUCachedValue)value);
MapKey key = toKey((LFUCachedValue) value);
accessMap.remove(key);
}
}

@ -22,7 +22,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
/**
@ -77,7 +76,7 @@ public class LRUCacheMap<K, V> extends AbstractCacheMap<K, V> {
protected void onMapFull() {
int startIndex = -1;
while (true) {
int queueIndex = (int)Math.abs(index.incrementAndGet() % queues.size());
int queueIndex = (int) Math.abs(index.incrementAndGet() % queues.size());
if (queueIndex == startIndex) {
return;
}

@ -111,38 +111,7 @@ public abstract class LocalCacheListener {
// check if instance has already been used
&& lastInvalidate > 0) {
if (System.currentTimeMillis() - lastInvalidate > cacheUpdateLogTime) {
cache.clear();
return;
}
object.isExistsAsync().onComplete((res, e) -> {
if (e != null) {
log.error("Can't check existance", e);
return;
}
if (!res) {
cache.clear();
return;
}
RScoredSortedSet<byte[]> logs = new RedissonScoredSortedSet<byte[]>(ByteArrayCodec.INSTANCE, commandExecutor, getUpdatesLogName(), null);
logs.valueRangeAsync(lastInvalidate, true, Double.POSITIVE_INFINITY, true)
.onComplete((r, ex) -> {
if (ex != null) {
log.error("Can't load update log", ex);
return;
}
for (byte[] entry : r) {
byte[] keyHash = Arrays.copyOf(entry, 16);
CacheKey key = new CacheKey(keyHash);
cache.remove(key);
}
});
});
loadAfterReconnection();
}
}
});
@ -181,7 +150,7 @@ public abstract class LocalCacheListener {
}
if (msg instanceof LocalCachedMapInvalidate) {
LocalCachedMapInvalidate invalidateMsg = (LocalCachedMapInvalidate)msg;
LocalCachedMapInvalidate invalidateMsg = (LocalCachedMapInvalidate) msg;
if (!Arrays.equals(invalidateMsg.getExcludedId(), instanceId)) {
for (byte[] keyHash : invalidateMsg.getKeyHashes()) {
CacheKey key = new CacheKey(keyHash);
@ -282,4 +251,38 @@ public abstract class LocalCacheListener {
return RedissonObject.prefixName("redisson__cache_updates_log", name);
}
private void loadAfterReconnection() {
if (System.currentTimeMillis() - lastInvalidate > cacheUpdateLogTime) {
cache.clear();
return;
}
object.isExistsAsync().onComplete((res, e) -> {
if (e != null) {
log.error("Can't check existance", e);
return;
}
if (!res) {
cache.clear();
return;
}
RScoredSortedSet<byte[]> logs = new RedissonScoredSortedSet<byte[]>(ByteArrayCodec.INSTANCE, commandExecutor, getUpdatesLogName(), null);
logs.valueRangeAsync(lastInvalidate, true, Double.POSITIVE_INFINITY, true)
.onComplete((r, ex) -> {
if (ex != null) {
log.error("Can't load update log", ex);
return;
}
for (byte[] entry : r) {
byte[] keyHash = Arrays.copyOf(entry, 16);
CacheKey key = new CacheKey(keyHash);
cache.remove(key);
}
});
});
}
}

@ -55,7 +55,9 @@ public class LocalCacheView<K, V> {
@Override
public Iterator<K> iterator() {
return new Iterator<K>() {
Iterator<CacheValue> iter = cache.values().iterator();
private Iterator<CacheValue> iter = cache.values().iterator();
@Override
public boolean hasNext() {
return iter.hasNext();
@ -106,7 +108,9 @@ public class LocalCacheView<K, V> {
@Override
public Iterator<V> iterator() {
return new Iterator<V>() {
Iterator<CacheValue> iter = cache.values().iterator();
private Iterator<CacheValue> iter = cache.values().iterator();
@Override
public boolean hasNext() {
return iter.hasNext();
@ -146,21 +150,23 @@ public class LocalCacheView<K, V> {
return new LocalEntrySet();
}
final class LocalEntrySet extends AbstractSet<Map.Entry<K,V>> {
final class LocalEntrySet extends AbstractSet<Map.Entry<K, V>> {
@Override
public Iterator<Map.Entry<K,V>> iterator() {
return new Iterator<Map.Entry<K,V>>() {
Iterator<CacheValue> iter = cache.values().iterator();
public Iterator<Map.Entry<K, V>> iterator() {
return new Iterator<Map.Entry<K, V>>() {
private Iterator<CacheValue> iter = cache.values().iterator();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public Map.Entry<K,V> next() {
public Map.Entry<K, V> next() {
CacheValue e = iter.next();
return new AbstractMap.SimpleEntry<K, V>((K)e.getKey(), (V)e.getValue());
return new AbstractMap.SimpleEntry<K, V>((K) e.getKey(), (V) e.getValue());
}
@Override
@ -174,7 +180,7 @@ public class LocalCacheView<K, V> {
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
CacheKey cacheKey = toCacheKey(e.getKey());
CacheValue entry = cache.get(cacheKey);
return entry != null && entry.getValue().equals(e.getValue());
@ -183,7 +189,7 @@ public class LocalCacheView<K, V> {
@Override
public boolean remove(Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
CacheKey cacheKey = toCacheKey(e.getKey());
return cache.remove(cacheKey) != null;
}
@ -206,7 +212,7 @@ public class LocalCacheView<K, V> {
return new LocalMap();
}
final class LocalMap extends AbstractMap<K,V> {
final class LocalMap extends AbstractMap<K, V> {
@Override
public V get(Object key) {

@ -21,14 +21,14 @@ package org.redisson.cache;
public class StdCachedValue<K, V> implements CachedValue<K, V> {
protected final K key;
protected final V value;
private final K key;
private final V value;
long ttl;
long maxIdleTime;
private long ttl;
private long maxIdleTime;
long creationTime;
long lastAccess;
private long creationTime;
private long lastAccess;
public StdCachedValue(K key, V value, long ttl, long maxIdleTime) {
this.value = value;

Loading…
Cancel
Save