mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Remove double and triple blank lines
This commit is contained in:
@@ -51,7 +51,6 @@ import static net.openhft.chronicle.map.StatelessChronicleMap.EventId.*;
|
||||
*/
|
||||
class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Cloneable {
|
||||
|
||||
|
||||
public static final String START_OF = "Attempt to write ";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StatelessChronicleMap.class);
|
||||
public static final byte STATELESS_CLIENT_IDENTIFIER = (byte) -127;
|
||||
@@ -80,7 +79,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
|
||||
static enum EventId {
|
||||
HEARTBEAT,
|
||||
STATEFUL_UPDATE,
|
||||
@@ -136,7 +134,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
bytes = new ByteBufferBytes(buffer.slice());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Future<V> getLater(@NotNull final K key) {
|
||||
return lazyExecutorService().submit(new Callable<V>() {
|
||||
@@ -181,7 +178,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
private ExecutorService lazyExecutorService() {
|
||||
|
||||
if (executorService == null) {
|
||||
@@ -196,7 +192,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return executorService;
|
||||
}
|
||||
|
||||
|
||||
private SocketChannel lazyConnect(final long timeoutMs,
|
||||
final InetSocketAddress remoteAddress) throws IOException {
|
||||
|
||||
@@ -219,7 +214,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
result.connect(config.remoteAddress());
|
||||
result.socket().setTcpNoDelay(true);
|
||||
|
||||
|
||||
doHandShaking(result);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
@@ -234,7 +228,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* attempts a single connect without a timeout and eat any IOException used typically in the
|
||||
* constructor, its possible the server is not running with this instance is created, {@link
|
||||
@@ -265,7 +258,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* closes the existing connections and establishes a new closeables
|
||||
*/
|
||||
@@ -278,7 +270,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
closeables = new CloseablesManager();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initiates a very simple level of handshaking with the remote server, we send a special ID of
|
||||
* -127 ( when the server receives this it knows its dealing with a stateless client, receive
|
||||
@@ -348,7 +339,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return transactionID;
|
||||
}
|
||||
|
||||
|
||||
public synchronized V putIfAbsent(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
@@ -358,7 +348,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return readValue(sizeLocation, copies);
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean remove(Object key, Object value) {
|
||||
if (key == null)
|
||||
throw new NullPointerException();
|
||||
@@ -373,7 +362,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return blockingFetch(sizeLocation).readBoolean();
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean replace(K key, V oldValue, V newValue) {
|
||||
if (key == null || oldValue == null || newValue == null)
|
||||
throw new NullPointerException();
|
||||
@@ -387,7 +375,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return blockingFetch(sizeLocation).readBoolean();
|
||||
}
|
||||
|
||||
|
||||
public synchronized V replace(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
@@ -400,12 +387,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return readValue(sizeLocation, copies);
|
||||
}
|
||||
|
||||
|
||||
public synchronized int size() {
|
||||
return (int) longSize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* calling this method should be avoided at all cost, as the entire {@code object} is
|
||||
* serialized. This equals can be used to compare map that extends ChronicleMap. So two
|
||||
@@ -435,7 +420,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized int hashCode() {
|
||||
return blockingFetch(writeEventAnSkip(HASH_CODE)).readInt();
|
||||
@@ -446,12 +430,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
.class);
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean isEmpty() {
|
||||
return blockingFetch(writeEventAnSkip(IS_EMPTY)).readBoolean();
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean containsKey(Object key) {
|
||||
if (key == null)
|
||||
throw keyNotNullNPE();
|
||||
@@ -467,7 +449,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return new NullPointerException("key can not be null");
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean containsValue(Object value) {
|
||||
if (value == null)
|
||||
throw new NullPointerException();
|
||||
@@ -478,12 +459,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return blockingFetch(sizeLocation).readBoolean();
|
||||
}
|
||||
|
||||
|
||||
public synchronized long longSize() {
|
||||
return blockingFetch(writeEventAnSkip(LONG_SIZE)).readLong();
|
||||
}
|
||||
|
||||
|
||||
public synchronized V get(Object key) {
|
||||
final long sizeLocation = writeEventAnSkip(GET);
|
||||
ThreadLocalCopies copies = writeKey((K) key);
|
||||
@@ -498,7 +477,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
"clients");
|
||||
}
|
||||
|
||||
|
||||
public synchronized V acquireUsing(@NotNull K key, V usingValue) {
|
||||
throw new UnsupportedOperationException("acquireUsing() is not supported for stateless " +
|
||||
"clients");
|
||||
@@ -517,7 +495,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
public synchronized V remove(Object key) {
|
||||
|
||||
if (key == null)
|
||||
@@ -525,7 +502,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
final long sizeLocation = removeReturnsNull ? writeEvent(REMOVE_WITHOUT_ACC) : writeEventAnSkip(REMOVE);
|
||||
|
||||
|
||||
ThreadLocalCopies copies = writeKey((K) key);
|
||||
|
||||
if (removeReturnsNull) {
|
||||
@@ -536,7 +512,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return readValue(sizeLocation, copies);
|
||||
}
|
||||
|
||||
|
||||
public synchronized V put(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
@@ -555,7 +530,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
public synchronized <R> R mapForKey(K key, @NotNull Function<? super V, R> function) {
|
||||
final long sizeLocation = writeEventAnSkip(MAP_FOR_KEY);
|
||||
writeKey(key);
|
||||
@@ -575,7 +549,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return (R) reader.readObject();
|
||||
}
|
||||
|
||||
|
||||
private synchronized <R> void writeObject(@NotNull Object function) {
|
||||
long start = bytes.position();
|
||||
for (; ; ) {
|
||||
@@ -597,7 +570,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void putAll(Map<? extends K, ? extends V> map) {
|
||||
|
||||
final long sizeLocation = putReturnsNull ? writeEvent(PUT_ALL_WITHOUT_ACC) :
|
||||
@@ -612,7 +584,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
private synchronized void sendWithoutAcc(final Bytes bytes, long sizeLocation) {
|
||||
writeSizeAt(sizeLocation);
|
||||
long timeoutTime = config.timeoutMs() + System.currentTimeMillis();
|
||||
@@ -637,7 +608,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized void writeEntriesForPutAll(Map<? extends K, ? extends V> map) {
|
||||
|
||||
final int numberOfEntries = map.size();
|
||||
@@ -665,7 +635,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
// as the volume of data could cause us to have to resize our buffers
|
||||
resizeIfRequired(numberOfEntries, numberOfEntriesReadSoFar, start);
|
||||
|
||||
|
||||
final Class<?> keyClass = key.getClass();
|
||||
if (!kClass.isAssignableFrom(keyClass)) {
|
||||
throw new ClassCastException("key=" + key + " is of type=" + keyClass + " " +
|
||||
@@ -675,14 +644,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
writeKeyInLoop(key, keyWriter, copies);
|
||||
|
||||
|
||||
final Class<?> valueClass = value.getClass();
|
||||
if (!vClass.isAssignableFrom(valueClass))
|
||||
throw new ClassCastException("value=" + value + " is of type=" + valueClass +
|
||||
" and " +
|
||||
"should be of type=" + vClass);
|
||||
|
||||
|
||||
writeValueInLoop(value, valueWriter, copies);
|
||||
|
||||
final int len = (int) (bytes.position() - start);
|
||||
@@ -714,7 +681,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return (long) ((double) bytes.position() / percentageComplete);
|
||||
}
|
||||
|
||||
|
||||
private void resizeBuffer(int size, long start) {
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
@@ -755,14 +721,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
bytes.position(start);
|
||||
}
|
||||
|
||||
|
||||
public synchronized void clear() {
|
||||
|
||||
// get the data back from the server
|
||||
blockingFetch(writeEventAnSkip(CLEAR));
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public Collection<V> values() {
|
||||
final long sizeLocation = writeEventAnSkip(VALUES);
|
||||
@@ -797,7 +761,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public synchronized Set<Map.Entry<K, V>> entrySet() {
|
||||
final long sizeLocation = writeEventAnSkip(ENTRY_SET);
|
||||
@@ -835,7 +798,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
in = blockingFetchReadOnly(timeoutTime, transactionId);
|
||||
}
|
||||
|
||||
|
||||
return result.entrySet();
|
||||
}
|
||||
|
||||
@@ -848,7 +810,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public synchronized Set<K> keySet() {
|
||||
final long sizeLocation = writeEventAnSkip(KEY_SET);
|
||||
@@ -888,15 +849,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
buffer.clear();
|
||||
bytes.clear();
|
||||
|
||||
|
||||
bytes.write((byte) event.ordinal());
|
||||
long sizeLocation = markSizeLocation();
|
||||
|
||||
|
||||
return sizeLocation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* skips for the transactionid
|
||||
*
|
||||
@@ -912,7 +870,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return sizeLocation;
|
||||
}
|
||||
|
||||
|
||||
class Entry implements Map.Entry<K, V> {
|
||||
|
||||
final K key;
|
||||
@@ -982,7 +939,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Bytes blockingFetch0(long sizeLocation, final long transactionId, long startTime) {
|
||||
|
||||
try {
|
||||
@@ -997,7 +953,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Bytes blockingFetchThrowable(long sizeLocation, long timeOutMs, final long transactionId, final long startTime) throws IOException {
|
||||
|
||||
final long timeoutTime = startTime + timeOutMs;
|
||||
@@ -1043,7 +998,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Bytes blockingFetch(long timeoutTime, long transactionId) throws IOException {
|
||||
|
||||
// the number of bytes in the response
|
||||
@@ -1095,7 +1049,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
private Bytes receive(int requiredNumberOfBytes, long timeoutTime) throws IOException {
|
||||
|
||||
while (bytes.buffer().position() < requiredNumberOfBytes) {
|
||||
@@ -1128,7 +1081,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
|
||||
private void checkTimeout(long timeoutTime) {
|
||||
if (timeoutTime < System.currentTimeMillis())
|
||||
throw new RemoteCallTimeoutException();
|
||||
@@ -1143,20 +1095,17 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
bytes.position(pos);
|
||||
}
|
||||
|
||||
|
||||
private void writeSizeAt(long locationOfSize) {
|
||||
final long size = bytes.position() - locationOfSize;
|
||||
bytes.writeInt(locationOfSize, (int) size - SIZE_OF_SIZE);
|
||||
}
|
||||
|
||||
|
||||
private long markSizeLocation() {
|
||||
final long position = bytes.position();
|
||||
bytes.skip(SIZE_OF_SIZE);
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
private ThreadLocalCopies writeKey(K key) {
|
||||
return writeKey(key, null);
|
||||
}
|
||||
@@ -1221,7 +1170,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ThreadLocalCopies writeValueInLoop(V value, Object writer, ThreadLocalCopies copies) {
|
||||
long start = bytes.position();
|
||||
for (; ; ) {
|
||||
|
||||
Reference in New Issue
Block a user