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. --> <!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html --> <!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"> <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>
<module name="LocalFinalVariableName"/> <module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/> <module name="LocalVariableName"/>
@ -169,7 +169,9 @@
<module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/> <module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/> <module name="StringLiteralEquality"/>
<module name="NestedIfDepth"/> <module name="NestedIfDepth">
<property name="max" value="2"/>
</module>
<module name="NestedTryDepth"/> <module name="NestedTryDepth"/>
<module name="SuperClone"/> <module name="SuperClone"/>
<module name="IllegalCatch"> <module name="IllegalCatch">
@ -186,8 +188,9 @@
<module name="FinalClass"/> <module name="FinalClass"/>
<!--module name="HideUtilityClassConstructor"/--> <!--module name="HideUtilityClassConstructor"/-->
<module name="InterfaceIsType"/> <module name="InterfaceIsType"/>
<module name="VisibilityModifier"/> <module name="VisibilityModifier">
<property name="packageAllowed" value="true"/>
</module>
<!-- Miscellaneous other checks. --> <!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html --> <!-- See http://checkstyle.sf.net/config_misc.html -->

@ -360,7 +360,7 @@
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<includes>**/org/redisson/api/**/*.java</includes> <includes>**/org/redisson/api/**/*.java,**/org/redisson/cache/**/*.java</includes>
<consoleOutput>true</consoleOutput> <consoleOutput>true</consoleOutput>
<enableRSS>false</enableRSS> <enableRSS>false</enableRSS>
<configLocation>/checkstyle.xml</configLocation> <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> { 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; 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() { public Iterator<Map.Entry<K, V>> iterator() {
return new MapIterator<Map.Entry<K,V>>() { return new MapIterator<Map.Entry<K, V>>() {
@Override @Override
public Map.Entry<K,V> next() { public Map.Entry<K, V> next() {
if (mapEntry == null) { if (mapEntry == null) {
throw new NoSuchElementException(); 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)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey(); Object key = e.getKey();
V value = get(key); V value = get(key);
return value != null && value.equals(e); return value != null && value.equals(e);
} }
public final boolean remove(Object o) { public boolean remove(Object o) {
if (o instanceof Map.Entry) { if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey(); Object key = e.getKey();
Object value = e.getValue(); Object value = e.getValue();
return AbstractCacheMap.this.map.remove(key, value); return AbstractCacheMap.this.map.remove(key, value);
@ -461,11 +461,11 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
return false; return false;
} }
public final int size() { public int size() {
return AbstractCacheMap.this.size(); return AbstractCacheMap.this.size();
} }
public final void clear() { public void clear() {
AbstractCacheMap.this.clear(); AbstractCacheMap.this.clear();
} }

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

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

@ -111,38 +111,7 @@ public abstract class LocalCacheListener {
// check if instance has already been used // check if instance has already been used
&& lastInvalidate > 0) { && lastInvalidate > 0) {
if (System.currentTimeMillis() - lastInvalidate > cacheUpdateLogTime) { loadAfterReconnection();
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);
}
});
});
} }
} }
}); });
@ -181,7 +150,7 @@ public abstract class LocalCacheListener {
} }
if (msg instanceof LocalCachedMapInvalidate) { if (msg instanceof LocalCachedMapInvalidate) {
LocalCachedMapInvalidate invalidateMsg = (LocalCachedMapInvalidate)msg; LocalCachedMapInvalidate invalidateMsg = (LocalCachedMapInvalidate) msg;
if (!Arrays.equals(invalidateMsg.getExcludedId(), instanceId)) { if (!Arrays.equals(invalidateMsg.getExcludedId(), instanceId)) {
for (byte[] keyHash : invalidateMsg.getKeyHashes()) { for (byte[] keyHash : invalidateMsg.getKeyHashes()) {
CacheKey key = new CacheKey(keyHash); CacheKey key = new CacheKey(keyHash);
@ -282,4 +251,38 @@ public abstract class LocalCacheListener {
return RedissonObject.prefixName("redisson__cache_updates_log", name); 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 @Override
public Iterator<K> iterator() { public Iterator<K> iterator() {
return new Iterator<K>() { return new Iterator<K>() {
Iterator<CacheValue> iter = cache.values().iterator();
private Iterator<CacheValue> iter = cache.values().iterator();
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return iter.hasNext(); return iter.hasNext();
@ -106,7 +108,9 @@ public class LocalCacheView<K, V> {
@Override @Override
public Iterator<V> iterator() { public Iterator<V> iterator() {
return new Iterator<V>() { return new Iterator<V>() {
Iterator<CacheValue> iter = cache.values().iterator();
private Iterator<CacheValue> iter = cache.values().iterator();
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return iter.hasNext(); return iter.hasNext();
@ -146,21 +150,23 @@ public class LocalCacheView<K, V> {
return new LocalEntrySet(); return new LocalEntrySet();
} }
final class LocalEntrySet extends AbstractSet<Map.Entry<K,V>> { final class LocalEntrySet extends AbstractSet<Map.Entry<K, V>> {
@Override @Override
public Iterator<Map.Entry<K,V>> iterator() { public Iterator<Map.Entry<K, V>> iterator() {
return new Iterator<Map.Entry<K,V>>() { return new Iterator<Map.Entry<K, V>>() {
Iterator<CacheValue> iter = cache.values().iterator();
private Iterator<CacheValue> iter = cache.values().iterator();
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return iter.hasNext(); return iter.hasNext();
} }
@Override @Override
public Map.Entry<K,V> next() { public Map.Entry<K, V> next() {
CacheValue e = iter.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 @Override
@ -174,7 +180,7 @@ public class LocalCacheView<K, V> {
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
CacheKey cacheKey = toCacheKey(e.getKey()); CacheKey cacheKey = toCacheKey(e.getKey());
CacheValue entry = cache.get(cacheKey); CacheValue entry = cache.get(cacheKey);
return entry != null && entry.getValue().equals(e.getValue()); return entry != null && entry.getValue().equals(e.getValue());
@ -183,7 +189,7 @@ public class LocalCacheView<K, V> {
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
if (o instanceof Map.Entry) { if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
CacheKey cacheKey = toCacheKey(e.getKey()); CacheKey cacheKey = toCacheKey(e.getKey());
return cache.remove(cacheKey) != null; return cache.remove(cacheKey) != null;
} }
@ -206,7 +212,7 @@ public class LocalCacheView<K, V> {
return new LocalMap(); return new LocalMap();
} }
final class LocalMap extends AbstractMap<K,V> { final class LocalMap extends AbstractMap<K, V> {
@Override @Override
public V get(Object key) { public V get(Object key) {

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

Loading…
Cancel
Save