diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 42a06aa7d..714a7c708 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -33,7 +33,7 @@ public interface ChronicleHash extends Closeable { * i. e. if it is created by {@link ChronicleHashBuilder#create()} call. * * @return the file this {@link ChronicleMap} or {@link ChronicleSet} is mapped to, - * or {@code null} if it is not mapped to any file + * or {@code null} if it is not mapped to any file * @see ChronicleHashBuilder#createPersistedTo(java.io.File) */ File file(); @@ -44,15 +44,15 @@ public interface ChronicleHash extends Closeable { * and there are other instances mapping the same data on the server across JVMs, the memory * won't be actually freed on operation system level. I. e. this method call doesn't affect * other {@link ChronicleMap} or {@link ChronicleSet} instances mapping the same data. - * + *

*

If you won't call this method, memory would be held at least until next garbage * collection. This could be a problem if, for example, you target rare garbage collections, * but load and drop {@code ChronicleHash}es regularly. - * + *

*

* TODO what about commit guarantees, when ChronicleMap is used with memory-mapped files, if * {@code ChronicleMap}/{@code ChronicleSet} closed/not? - * + *

*

After this method call behaviour of all methods of {@code ChronicleMap} * or {@code ChronicleSet} is undefined. Any method call on the map might throw * any exception, or even JVM crash. Shortly speaking, don't call use map closing. diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java index ed959510b..f93a56d67 100755 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java @@ -46,12 +46,12 @@ import java.util.concurrent.TimeUnit; * This interface defines the meaning of configurations, common to {@link * ChronicleMapBuilder} and {@link ChronicleSetBuilder}, i. * e. Chronicle hash container configurations. - * + *

*

{@code ChronicleHashBuilder} is mutable. Configuration methods mutate the builder and return * the builder itself back to support chaining pattern, rather than the builder copies with * the corresponding configuration changed. To make an independent configuration, {@linkplain * #clone} the builder. - * + *

*

There are some "low-level" configurations in this builder, * that require deep understanding of the Chronicle implementation design to be properly used. * Know what you do. These configurations are picked up strictly as-is, without extra round-ups, @@ -88,21 +88,21 @@ public interface ChronicleHashBuilder *

{@code ChronicleHashBuilder} implementation heuristically chooses * {@linkplain #actualChunkSize(int) the actual chunk size} based on this configuration, that, * however, might result to quite high internal fragmentation, i. e. losses because only * integral number of chunks could be allocated for the entry. If you want to avoid this, you * should manually configure the actual chunk size in addition to this average key size * configuration, which is anyway needed. - * + *

*

If key is a boxed primitive type or {@link Byteable} subclass, i. e. if key size is known * statically, it is automatically accounted and shouldn't be specified by user. * * @param averageKeySize the average number of bytes, taken by serialized form of keys * @return this builder back - * @throws IllegalStateException if key size is known statically and shouldn't be configured - * by user + * @throws IllegalStateException if key size is known statically and shouldn't be configured + * by user * @throws IllegalArgumentException if the given {@code keySize} is non-positive * @see #constantKeySizeBySample(Object) * @see #actualChunkSize(int) @@ -113,10 +113,10 @@ public interface ChronicleHashBuilder *

If keys are of boxed primitive type or {@link Byteable} subclass, i. e. if key size is * known statically, it is automatically accounted and this method shouldn't be called. - * + *

*

If key size varies, method {@link #averageKeySize(double)} should be called instead of * this one. * @@ -129,7 +129,7 @@ public interface ChronicleHashBuilder *

{@link ChronicleMap} and {@link ChronicleSet} store their data off-heap, so it is required * to serialize key (and values, in {@code ChronicleMap} case) (unless they are direct {@link * Byteable} instances). Serialized key bytes (+ serialized value bytes, in {@code ChronicleMap} @@ -139,16 +139,16 @@ public interface ChronicleHashBuilder *

To minimize memory overuse and improve speed, you should pay decent attention to this * configuration. Alternatively, you can just trust the heuristics and doesn't configure * the chunk size. - * + *

*

Specify chunk size so that most entries would take from 5 to several dozens of chunks. * However, remember that operations with entries that span several chunks are a bit slower, * than with entries which take a single chunk. Particularly avoid entries to take more than * 64 chunks. - * + *

*

Example: if values in your {@code ChronicleMap} are adjacency lists of some social graph, * where nodes are represented as {@code long} ids, and adjacency lists are serialized in * efficient manner, for example as {@code long[]} arrays. Typical number of connections is @@ -160,7 +160,7 @@ public interface ChronicleHashBuilder - * + *

*

This is a low-level configuration. The configured number * of bytes is strictly used as-is, without anything like round-up to the multiple of 8 or * 16, or any other adjustment. @@ -185,7 +185,7 @@ public interface ChronicleHashBuildermight be thrown, because currently {@link ChronicleMap} and {@link ChronicleSet} * don't support resizing. - * + *

*

You shouldn't put additional margin over the actual maximum number of entries. * This bad practice was popularized by {@link HashMap#HashMap(int)} and {@link * HashSet#HashSet(int)} constructors, which accept capacity, that should be multiplied * by load factor to obtain the actual maximum expected number of entries. * {@code ChronicleMap} and {@code ChronicleSet} don't have a notion of load factor. - * + *

*

Default maximum entries is 2^20 (~ 1 million). * * @param entries maximum size of the maps or sets, created by this builder @@ -214,11 +214,11 @@ public interface ChronicleHashBuilder *

This is a low-level configuration. * * @param entriesPerSegment the actual maximum number entries per segment in the - * hash containers, created by this builder + * hash containers, created by this builder * @return this builder back * @see #entries(long) * @see #actualSegments(int) @@ -242,7 +242,7 @@ public interface ChronicleHashBuilder *

This is a low-level configuration. The configured number * is used as-is, without anything like round-up to the closest power of 2. * @@ -262,7 +262,7 @@ public interface ChronicleHashBuilder *

Default lock time out is 2 seconds. * * @param lockTimeOut new lock timeout for segments of containers created by this builder, in @@ -279,7 +279,7 @@ public interface ChronicleHashBuilder *

Default time provider is {@link TimeProvider#SYSTEM}. * * @param timeProvider a new time provider for replication needs @@ -293,7 +293,7 @@ public interface ChronicleHashBuilder *

Default {@code BytesMarshallerFactory} is an instance of {@link * VanillaBytesMarshallerFactory}. This is a convenience configuration method, it has no effect * on the resulting hash containers, if {@linkplain #keyMarshaller(BytesMarshaller) custom data @@ -315,7 +315,7 @@ public interface ChronicleHashBuilder *

Default serializer is {@link BytesMarshallableSerializer}, configured with the specified * or default {@link #bytesMarshallerFactory(BytesMarshallerFactory) BytesMarshallerFactory}. * @@ -343,10 +343,10 @@ public interface ChronicleHashBuilderthe * section about serialization in ChronicleMap manual for more information. - * + *

*

Configuring marshalling this way results to a little bit more compact in-memory layout of * the map, comparing to a single interface configuration: {@link #keyMarshaller(BytesMarshaller)}. - * + *

*

Passing {@link BytesInterop} (which is a subinterface of {@link BytesWriter}) as the first * argument is supported, and even more advantageous from performance perspective. * @@ -360,7 +360,7 @@ public interface ChronicleHashBuilder *

Default key size marshaller is so-called {@linkplain SizeMarshallers#stopBit() stop bit * encoding marshalling}. If {@linkplain #constantKeySizeBySample(Object) constant key size} is * configured, or defaulted if the key type is always constant and {@code ChronicleHashBuilder} @@ -381,7 +381,7 @@ public interface ChronicleHashBuilder *

Default key deserialization factory is {@link NewInstanceObjectFactory}, which creates a * new key instance using {@link Class#newInstance()} default constructor. You could provide an * {@link AllocateInstanceObjectFactory}, which uses {@code Unsafe.allocateInstance(Class)} (you @@ -403,7 +403,7 @@ public interface ChronicleHashBuilder *

By default, {@code ChronicleHashBuilder}s detects immutability automatically only for very * few standard JDK types (for example, for {@link String}), it is not recommended to rely on * {@code ChronicleHashBuilder} to be smart enough about this. @@ -416,9 +416,9 @@ public interface ChronicleHashBuilder the section about * replication in ChronicleMap manual for more information. - * + *

*

By default, hash containers, created by this builder doesn't replicate their data. - * + *

*

This method call overrides all previous replication configurations of this builder, made * either by this method or {@link #replication(byte, TcpTransportAndNetworkConfig)} shortcut * method. @@ -451,7 +451,7 @@ public interface ChronicleHashBuilder *

This method is a shortcut for {@code instance().create()}. * * @return a new off-heap hash container @@ -464,17 +464,17 @@ public interface ChronicleHashBuilder *

Multiple containers could give access to the same data simultaneously, either inside a * single JVM or across processes. Access is synchronized correctly across all instances, i. e. * hash container mapping the data from the first JVM isn't able to modify the data, * concurrently accessed from the second JVM by another hash container instance, mapping the * same data. - * + *

*

On container's {@link ChronicleHash#close() close()} the data isn't removed, it remains on * disk and available to be opened again (given the same file name) or during different JVM * run. - * + *

*

This method is shortcut for {@code instance().persistedTo(file).create()}. * * @param file the file with existing hash container or a desired location of a new off-heap diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java index 499fb69b4..ed2dc411d 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java @@ -34,12 +34,12 @@ public interface ChronicleHashInstanceBuilder { * "channels". See * the * section about Channels and ChannelProvider in ChronicleMap manual for more information. - * + *

*

Another way to establish replication is {@link #replicated(SingleChronicleHashReplication)} method * or it's shortcut: {@link #replicated(byte, TcpTransportAndNetworkConfig)}. - * + *

*

By default, hash containers, created by this builder doesn't replicate their data. - * + *

*

This method call overrides all previous replication configurations of this builder, made * either by means of this method, {@link #replicated(SingleChronicleHashReplication)} * or {@link #replicated(byte, TcpTransportAndNetworkConfig)} method calls. diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashStatelessClientBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashStatelessClientBuilder.java index faa099318..6d878d322 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashStatelessClientBuilder.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashStatelessClientBuilder.java @@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit; * another host * * @param the type of {@code ChronicleHash} accessed remotely, {@code ChronicleMap} or - * {@code ChronicleSet} + * {@code ChronicleSet} */ public interface ChronicleHashStatelessClientBuilder< C extends ChronicleHashStatelessClientBuilder, H extends ChronicleHash> { diff --git a/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java b/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java index 28d6bfedc..27eb158bc 100644 --- a/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java +++ b/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.hash; /** * TODO mention in docs + * * @author Rob Austin. */ public class RemoteCallTimeoutException extends RuntimeException { diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Access.java b/src/main/java/net/openhft/chronicle/hash/hashing/Access.java index 33512f052..1a1cf43f2 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Access.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Access.java @@ -25,19 +25,19 @@ import java.nio.ByteOrder; * Access} implementation returns {@link ByteOrder#LITTLE_ENDIAN} on {@link #byteOrder(Object) * byteOrder(input)} call, the following expressions should always have the same value: *

- * + *

*

{@code getXXX(input, offset)} methods could throw unchecked exceptions when requested bytes * range is outside of the bounds of the byte sequence, represented by the given {@code input}. * However, they could omit checks for better performance. - * + *

*

{@code Access} API is designed for inputs, that actually represent byte sequences that lay * continuously in memory. Theoretically {@code Access} strategy could be implemented for * non-continuous byte sequences, or abstractions which aren't actually present in memory as they @@ -52,9 +52,9 @@ public interface Access { * Reads {@code [offset, offset + 7]} bytes of the byte sequence represented by the given * {@code input} as a single {@code long} value. * - * @param input the object to access + * @param input the object to access * @param offset offset to the first byte to read within the byte sequence represented - * by the given object + * by the given object * @return eight bytes as a {@code long} value, in {@linkplain #byteOrder(Object) the expected * order} */ @@ -64,9 +64,9 @@ public interface Access { * Shortcut for {@code getInt(input, offset) & 0xFFFFFFFFL}. Could be implemented more * efficiently. * - * @param input the object to access + * @param input the object to access * @param offset offset to the first byte to read within the byte sequence represented - * by the given object + * by the given object * @return four bytes as an unsigned int value, in {@linkplain #byteOrder(Object) the expected * order} */ @@ -76,9 +76,9 @@ public interface Access { * Reads {@code [offset, offset + 3]} bytes of the byte sequence represented by the given * {@code input} as a single {@code int} value. * - * @param input the object to access + * @param input the object to access * @param offset offset to the first byte to read within the byte sequence represented - * by the given object + * by the given object * @return four bytes as an {@code int} value, in {@linkplain #byteOrder(Object) the expected * order} */ @@ -88,9 +88,9 @@ public interface Access { * Shortcut for {@code getShort(input, offset) & 0xFFFF}. Could be implemented more * efficiently. * - * @param input the object to access + * @param input the object to access * @param offset offset to the first byte to read within the byte sequence represented - * by the given object + * by the given object * @return two bytes as an unsigned short value, in {@linkplain #byteOrder(Object) the expected * order} */ @@ -100,9 +100,9 @@ public interface Access { * Reads {@code [offset, offset + 1]} bytes of the byte sequence represented by the given * {@code input} as a single {@code short} value, returned widened to {@code int}. * - * @param input the object to access + * @param input the object to access * @param offset offset to the first byte to read within the byte sequence represented - * by the given object + * by the given object * @return two bytes as a {@code short} value, in {@linkplain #byteOrder(Object) the expected * order}, widened to {@code int} */ @@ -111,9 +111,9 @@ public interface Access { /** * Shortcut for {@code getByte(input, offset) & 0xFF}. Could be implemented more efficiently. * - * @param input the object to access + * @param input the object to access * @param offset offset to the byte to read within the byte sequence represented - * by the given object + * by the given object * @return a byte by the given {@code offset}, interpreted as unsigned */ int getUnsignedByte(T input, long offset); @@ -122,9 +122,9 @@ public interface Access { * Reads a single byte at the given {@code offset} in the byte sequence represented by the given * {@code input}, returned widened to {@code int}. * - * @param input the object to access + * @param input the object to access * @param offset offset to the byte to read within the byte sequence represented - * by the given object + * by the given object * @return a byte by the given {@code offset}, widened to {@code int} */ int getByte(T input, long offset); diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java b/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java index 633c00c01..ab7ceb0a9 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java @@ -25,22 +25,25 @@ import java.nio.ByteBuffer; */ public final class Accesses { + private Accesses() { + } + /** * Returns the {@code Access} delegating {@code getXXX(input, offset)} methods to {@code * sun.misc.Unsafe.getXXX(input, offset)}. - * + *

*

Usage example:

{@code
      * class Pair {
      *     long first, second;
-     *
+     * 

* static final long pairDataOffset = * theUnsafe.objectFieldOffset(Pair.class.getDeclaredField("first")); - * + *

* static long hashPair(Pair pair, LongHashFunction hashFunction) { * return hashFunction.hash(pair, Accesses.unsafe(), pairDataOffset, 16L); * } * }}

- * + *

*

{@code null} is a valid input, on accepting {@code null} {@code Unsafe} just interprets * the given offset as a wild memory address. * @@ -63,6 +66,4 @@ public final class Accesses { public static Access toBytes() { return BytesAccess.INSTANCE; } - - private Accesses() {} } diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java b/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java index 44285ee5b..ff4bcfa5c 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java @@ -37,7 +37,7 @@ public final class Hasher { * Returns the hash code for {@code len} continuous bytes of the given {@code input} object, * starting from the given offset. The abstraction of input as ordered byte sequence and * "offset within the input" is defined by the given {@code access} strategy. - * + *

*

This method doesn't promise to throw a {@code RuntimeException} if {@code * [off, off + len - 1]} subsequence exceeds the bounds of the bytes sequence, defined by {@code * access} strategy for the given {@code input}, so use this method with caution. @@ -47,7 +47,7 @@ public final class Hasher { * as ordered byte sequence * @param offset offset to the first byte of the subsequence to hash * @param length length of the subsequence to hash - * @param the type of the input + * @param the type of the input * @return hash code for the specified bytes subsequence */ public static long hash(T input, Access access, long offset, long length) { diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Primitives.java b/src/main/java/net/openhft/chronicle/hash/hashing/Primitives.java index b9e6fca02..a82a0bbd5 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Primitives.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Primitives.java @@ -18,7 +18,8 @@ package net.openhft.chronicle.hash.hashing; final class Primitives { - private Primitives() {} + private Primitives() { + } static long unsignedInt(int i) { return i & 0xFFFFFFFFL; diff --git a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java index 902781f97..3fc2c1cf1 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java @@ -164,7 +164,7 @@ public abstract class AbstractReplication implements Serializable { * Configures if the node, provided with replication, created by this builder, should * replicate only local data, last updated with own identifier, or all data currently * present on the node, when a new node joins the replication grid. - * + *

*

Default configuration is {@code false}, potentially swamping new nodes with * duplicates. However, this does guarantee that all the data is replicated over to the new * node and is useful especially in the case that the originating node of some data is not diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java b/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java index 89ace3b3d..2dcd70025 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java @@ -30,7 +30,7 @@ public interface ConnectionListener { void onConnect(InetAddress address, byte identifier, boolean isServer); /** - * @param address the address that we have been disconnected from + * @param address the address that we have been disconnected from * @param identifier the identifer the address that we have been disconnected from or Byte */ void onDisconnect(InetAddress address, byte identifier); diff --git a/src/main/java/net/openhft/chronicle/hash/replication/RemoteNodeValidator.java b/src/main/java/net/openhft/chronicle/hash/replication/RemoteNodeValidator.java index 44c4322be..660c763f4 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/RemoteNodeValidator.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/RemoteNodeValidator.java @@ -28,8 +28,8 @@ public interface RemoteNodeValidator { * and host. * * @param remoteIdentifier remoteIdentifier - * @param remoteAddress remoteAddress - * @return true if unique + * @param remoteAddress remoteAddress + * @return true if unique */ boolean validate(byte remoteIdentifier, SocketAddress remoteAddress); diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java index 1d3a1c4a3..bfce72e5d 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java @@ -27,15 +27,15 @@ import java.io.Serializable; * ChronicleHashInstanceBuilder#replicatedViaChannel(ReplicationChannel)} method, to establish a channel * replication. See * the corresponding section in ChronicleMap manual for more information. - * + *

*

A {@code ReplicationChannel} could be used to replicate only one {@link ChronicleHash} instance. * * @see ReplicationHub * @see ReplicationHub#createChannel(int) */ -public final class ReplicationChannel implements Serializable{ - private ReplicationHub hub; +public final class ReplicationChannel implements Serializable { private final int channelId; + private ReplicationHub hub; ReplicationChannel(ReplicationHub hub, int channelId) { this.hub = hub; diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java index 4c9781cd8..b8ca27c0b 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java @@ -33,7 +33,7 @@ import java.util.Arrays; * buffers, worker threads for that, considerably reducing resources usage and increasing cumulative * (for all replicated containers) replication throughput. See * the corresponding section in ChronicleMap manual for more information. - * + *

*

Create instances of this class using this pattern:

{@code
  * ReplicationHub hub = ReplicationHub.builder()
  *     .tcpTransportAndNetwork(tcpConfig)
@@ -131,7 +131,7 @@ public final class ReplicationHub extends AbstractReplication {
         /**
          * Configures the maximum number of channels could be {@linkplain #createChannel(int)}
          * created for {@code ReplicationHub}s, created by this builder.
-         *
+         * 

*

Default value is {@code 128}. * * @param maxNumberOfChannels {@link ReplicationHub#maxNumberOfChannels()} of {@link diff --git a/src/main/java/net/openhft/chronicle/hash/replication/SingleChronicleHashReplication.java b/src/main/java/net/openhft/chronicle/hash/replication/SingleChronicleHashReplication.java index b0778a944..ba17f08d7 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/SingleChronicleHashReplication.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/SingleChronicleHashReplication.java @@ -20,15 +20,15 @@ import org.jetbrains.annotations.NotNull; public class SingleChronicleHashReplication extends AbstractReplication { + public SingleChronicleHashReplication(byte localIdentifier, Builder builder) { + super(localIdentifier, builder); + } + @NotNull public static Builder builder() { return new Builder(); } - public SingleChronicleHashReplication(byte localIdentifier, Builder builder) { - super(localIdentifier, builder); - } - @Override public String toString() { return "SingleChronicleHashReplication{" + super.toString() + "}"; @@ -36,7 +36,8 @@ public class SingleChronicleHashReplication extends AbstractReplication { public static class Builder extends AbstractReplication.Builder { - private Builder() {} + private Builder() { + } @NotNull @Override diff --git a/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java b/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java index 857841f06..851954683 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java @@ -26,7 +26,7 @@ import java.io.Serializable; * TimeProvider was aims to possibly later provide an optimization to * {@link System#currentTimeMillis()} on every call to replicated {@link ChronicleMap} * or {@link ChronicleSet}. - * + *

* Subclasses should be immutable, because {@link ChronicleHashBuilder} doesn't make defensive * copies. * diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/BytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/BytesInterop.java index 3175c3ac7..7fabfd4ae 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/BytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/BytesInterop.java @@ -23,7 +23,7 @@ import net.openhft.lang.model.Byteable; * Writer for objects, which themselves are bytes sequence in some sense: * {@link Byteable Byteables}, {@code byte[]} arrays, other primitive arrays, "flat" objects * (with primitives fields only), particularly boxed primitive types. - * + *

*

This interface is called "BytesInterop" because it allows to work with object as they * are already marshalled to {@code Bytes}: {@linkplain #startsWith(Bytes, Object) compare} * with other {@code Bytes}, i. e. interoperate objects and {@code Bytes}. @@ -41,7 +41,7 @@ public interface BytesInterop extends BytesWriter { * {@code bytes}' is positioned at the first byte to compare. {@code bytes}' limit * is unspecified. {@code bytes}' position and limit shouldn't be altered during * this call. - * @param e the object to serialize virtually and compare with the given {@code bytes} + * @param e the object to serialize virtually and compare with the given {@code bytes} * @return if the given {@code bytes} starts with the given {@code e} object's serialized form */ boolean startsWith(Bytes bytes, E e); diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/BytesReader.java b/src/main/java/net/openhft/chronicle/hash/serialization/BytesReader.java index 52ed3ff53..8cfde0daf 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/BytesReader.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/BytesReader.java @@ -26,18 +26,18 @@ import java.io.Serializable; * Deserializer (object from {@link Bytes}, mirroring the {@link BytesWriter}, i. e. assuming the * length of the serialized form isn't written in the beginning of the serialized form itself, * but managed by {@link ChronicleHash} implementation and passed to the reading methods. - * + *

*

Implementation example:


  * class LongPair { long first, second; }
- * 
+ * 

* enum LongPairArrayReader implements BytesReader<LongPair[]> { * INSTANCE; - * + *

* @Override * public LongPair[] read(Bytes bytes, long size) { * return read(bytes, size, null); * } - * + *

* @Override * public LongPair[] read(Bytes bytes, long size, LongPair[] toReuse) { * if (size > Integer.MAX_VALUE * 16L) @@ -72,13 +72,13 @@ public interface BytesReader extends Serializable { /** * Reads and returns the object from {@code [position(), position() + size]} bytes of the given * {@link Bytes}. - * + *

*

Implementation of this method should increment the {@code bytes}' position by the given * size, i. e. "consume" the bytes of the deserialized object. It must not alter the * {@code bytes}' {@link Bytes#limit() limit} and contents. * * @param bytes the {@code Bytes} to read the object from - * @param size the size of the serialized form of the returned object + * @param size the size of the serialized form of the returned object * @return the object read from the bytes * @see BytesWriter#write(Bytes, Object) * @see #read(Bytes, long, Object) @@ -93,8 +93,8 @@ public interface BytesReader extends Serializable { * be {@code null}, in this case this method should behave exactly the same as * {@link #read(Bytes, long)} method does. * - * @param bytes the {@code Bytes} to read the object from - * @param size the size of the serialized form of the returned object + * @param bytes the {@code Bytes} to read the object from + * @param size the size of the serialized form of the returned object * @param toReuse the object to read the deserialized data into * @return the object read from the bytes, either reused or newly created * @see #read(Bytes, long) diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/BytesWriter.java b/src/main/java/net/openhft/chronicle/hash/serialization/BytesWriter.java index 9f2cad0e2..40d3eae99 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/BytesWriter.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/BytesWriter.java @@ -26,18 +26,18 @@ import java.io.Serializable; * of any object before actual serialization 2) doesn't include that length in the serialized * form itself, assuming it will be passed by the {@link ChronicleHash} into * {@link BytesReader#read(Bytes, long)} deserialization method. - * + *

*

Implementation example:


  * class LongPair { long first, second; }
- *
+ * 

* enum LongPairArrayWriter implements BytesWriter<LongPair[]> { * INSTANCE; - * + *

* @Override * public long size(LongPair[] longPairs) { * return longPairs.length * 16L; * } - * + *

* @Override * public void write(Bytes bytes, LongPair[] longPairs) { * for (LongPair pair : longPairs) { @@ -66,7 +66,7 @@ public interface BytesWriter extends Serializable { /** * Serializes the given object to the given {@code bytes}, without writing the length of the * serialized form itself. - * + *

*

Implementation of this method should increment the {@code bytes}' {@linkplain * Bytes#position() position} by {@link #size(Object) size(e)}. The given object should * be written into these range between the initial {@code bytes}' position and the position @@ -74,7 +74,7 @@ public interface BytesWriter extends Serializable { * {@code bytes}' {@linkplain Bytes#limit() limit} and contents outside of the specified range. * * @param bytes the {@code Bytes} to write the given object to - * @param e the object to serialize to the given bytes + * @param e the object to serialize to the given bytes * @see BytesReader#read(Bytes, long) */ void write(Bytes bytes, E e); diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/SizeMarshallers.java b/src/main/java/net/openhft/chronicle/hash/serialization/SizeMarshallers.java index ab72cce07..07bd32c07 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/SizeMarshallers.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/SizeMarshallers.java @@ -22,10 +22,17 @@ import static net.openhft.lang.io.IOTools.stopBitLength; public final class SizeMarshallers { + private SizeMarshallers() { + } + public static SizeMarshaller stopBit() { return StopBit.INSTANCE; } + public static SizeMarshaller constant(long size) { + return new ConstantSizeMarshaller(size); + } + private enum StopBit implements SizeMarshaller { INSTANCE; @@ -60,10 +67,6 @@ public final class SizeMarshallers { } } - public static SizeMarshaller constant(long size) { - return new ConstantSizeMarshaller(size); - } - private static class ConstantSizeMarshaller implements SizeMarshaller { private static final long serialVersionUID = 0L; @@ -103,6 +106,4 @@ public final class SizeMarshallers { return size; } } - - private SizeMarshallers() {} } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java index 450d067a9..826639782 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java @@ -22,25 +22,12 @@ import net.openhft.lang.threadlocal.Provider; import net.openhft.lang.threadlocal.ThreadLocalCopies; public abstract class BasicCopyingMetaBytesInterop implements MetaBytesInterop { - private static final long serialVersionUID = 0L; - static final Provider provider = Provider.of(DirectBytesBuffer.class); - - static abstract class BasicCopyingMetaBytesInteropProvider> implements MetaProvider { - private static final long serialVersionUID = 0L; - - @Override - public ThreadLocalCopies getCopies(ThreadLocalCopies copies) { - return provider.getCopies(copies); - } - } - + private static final long serialVersionUID = 0L; final DirectBytesBuffer buffer; transient long size; transient long hash; - protected BasicCopyingMetaBytesInterop(DirectBytesBuffer buffer) { this.buffer = buffer; } @@ -67,4 +54,14 @@ public abstract class BasicCopyingMetaBytesInterop implements MetaBytesInt public void write(W writer, Bytes bytes, E e) { bytes.write(buffer.buffer, buffer.buffer.position(), buffer.buffer.remaining()); } + + static abstract class BasicCopyingMetaBytesInteropProvider> implements MetaProvider { + private static final long serialVersionUID = 0L; + + @Override + public ThreadLocalCopies getCopies(ThreadLocalCopies copies) { + return provider.getCopies(copies); + } + } } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesReaders.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesReaders.java index 2430db5c8..a5768dbb0 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesReaders.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesReaders.java @@ -25,6 +25,9 @@ import net.openhft.lang.io.serialization.BytesMarshaller; */ public final class BytesReaders { + private BytesReaders() { + } + /** * Returns a {@link BytesReader} wrapping the given {@link BytesMarshaller}. One of the * bridge methods between general serialization API from {@link net.openhft.lang} and @@ -44,7 +47,7 @@ public final class BytesReaders { * #fromBytesMarshaller(BytesMarshaller) fromBytesMarshaller(m)} call, {@code null} otherwise. * * @param reader reader to extract {@code BytesMarshaller} from - * @param type of the objects marshalled + * @param type of the objects marshalled * @return {@code BytesMarshaller} from which the specified reader was created, or {@code null} */ public static BytesMarshaller getBytesMarshaller(BytesReader reader) { @@ -70,7 +73,4 @@ public final class BytesReaders { return (E) marshaller.read(bytes, toReuse); } } - - private BytesReaders() { - } } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java index d1925857f..5043df172 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java @@ -27,6 +27,12 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte private static final long serialVersionUID = 1L; private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(16L); + transient W writer; + transient E cur; + + protected CopyingMetaBytesInterop(DirectBytesBuffer buffer) { + super(buffer); + } public static void checkMaxSizeStillReasonable(long maxSize, Exception ex) { if (maxSize > MAX_REASONABLE_SERIALIZED_SIZE) { @@ -39,17 +45,6 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte } } - transient W writer; - transient E cur; - - protected CopyingMetaBytesInterop(DirectBytesBuffer buffer) { - super(buffer); - } - - DirectBytesBuffer buffer() { - return buffer; - } - public static > MetaBytesInterop forBytesMarshaller(Serializable bufferIdentity) { return new DirectBytesBuffer(bufferIdentity).forBytesMarshaller; @@ -66,6 +61,15 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte return new BytesMarshallerCopyingMetaBytesInteropProvider<>(mutable, maxSize); } + public static > + MetaProvider> providerForBytesWriter(boolean mutable) { + return new BytesWriterCopyingMetaBytesInteropProvider<>(mutable); + } + + DirectBytesBuffer buffer() { + return buffer; + } + private static class BytesMarshallerCopyingMetaBytesInteropProvider> extends BasicCopyingMetaBytesInteropProvider> { @@ -89,11 +93,6 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte } } - public static > - MetaProvider> providerForBytesWriter(boolean mutable) { - return new BytesWriterCopyingMetaBytesInteropProvider<>(mutable); - } - private static class BytesWriterCopyingMetaBytesInteropProvider> extends BasicCopyingMetaBytesInteropProvider> { private static final long serialVersionUID = 0L; @@ -105,7 +104,7 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte @Override public CopyingMetaBytesInterop get(ThreadLocalCopies copies, - CopyingMetaBytesInterop originalMetaWriter, W writer, E e) { + CopyingMetaBytesInterop originalMetaWriter, W writer, E e) { DirectBytesBuffer.ForBytesWriter forBytesWriter = provider.get(copies, originalMetaWriter.buffer()).forBytesWriter; forBytesWriter.init(writer, e, mutable); diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java index d97543c44..50926512f 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java @@ -33,15 +33,6 @@ public abstract class DataValueMetaBytesInterop super(buffer); } - void init(BytesWriter writer, E e, long size) { - Bytes buffer = this.buffer.obtain(size, true); - writer.write(buffer, e); - buffer.flip(); - assert buffer.remaining() == size; - this.size = size; - hash = 0L; - } - public static MetaBytesInterop> forIdentity(Serializable bufferIdentity) { return new DirectBytesBuffer(bufferIdentity).forDataValueWriter; } @@ -51,8 +42,17 @@ public abstract class DataValueMetaBytesInterop return new InteropProvider<>(eClass); } + void init(BytesWriter writer, E e, long size) { + Bytes buffer = this.buffer.obtain(size, true); + writer.write(buffer, e); + buffer.flip(); + assert buffer.remaining() == size; + this.size = size; + hash = 0L; + } + private static class InteropProvider extends BasicCopyingMetaBytesInteropProvider< - E, BytesWriter, MetaBytesInterop>> { + E, BytesWriter, MetaBytesInterop>> { private static final long serialVersionUID = 0L; private final Class eClass; @@ -84,7 +84,7 @@ public abstract class DataValueMetaBytesInterop if (e instanceof Byteable) return metaByteableInterop; DirectBytesBuffer.ForDataValueWriter forDataValueWriter = - provider.get(copies, ((DataValueMetaBytesInterop)originalMetaWriter).buffer) + provider.get(copies, ((DataValueMetaBytesInterop) originalMetaWriter).buffer) .forDataValueWriter; forDataValueWriter.init(writer, e, size); return forDataValueWriter; diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java index 85c9a95ef..b5aa43057 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java @@ -510,7 +510,7 @@ abstract class AbstractChannelReplicator implements Closeable { start = in.position(); - externalizable.writeExternalEntry(entry, in, chronicleId,bootstrapTime); + externalizable.writeExternalEntry(entry, in, chronicleId, bootstrapTime); if (in.position() == start) { in.position(pos0); diff --git a/src/main/java/net/openhft/chronicle/map/Asserts.java b/src/main/java/net/openhft/chronicle/map/Asserts.java index fd0ff55bb..802d27c3f 100644 --- a/src/main/java/net/openhft/chronicle/map/Asserts.java +++ b/src/main/java/net/openhft/chronicle/map/Asserts.java @@ -20,9 +20,10 @@ import org.jetbrains.annotations.NotNull; final class Asserts { + private Asserts() { + } + public static void assertNotNull(@NotNull Object obj) { assert obj != null; } - - private Asserts() {} } diff --git a/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java b/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java index 35ee966c2..451ca7055 100644 --- a/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java @@ -33,7 +33,7 @@ import java.io.Serializable; * ChronicleMapBuilder#keySizeMarshaller(SizeMarshaller)}), then (optionally) alignment (see {@link * ChronicleMapBuilder#entryAndValueAlignment(Alignment)} ), followed by the serialized value * itself. - * + *

*

There are helper methods {@link ChronicleMap#readKey(Bytes, long)} and {@link * ChronicleMap#readValue(Bytes, long)} that help to deal with this. */ diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index 332c8ae0f..7b704655c 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -287,6 +287,7 @@ final class ChannelProvider implements Closeable { ChannelProvider.this.close(); } }; + private ChannelProvider(ReplicationHub hub) { localIdentifier = hub.identifier(); this.hub = hub; diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 6bfb5ee8a..e25dfb498 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -31,18 +31,18 @@ import java.util.concurrent.ConcurrentMap; /** * Extension of {@link ConcurrentMap} interface, stores the data off-heap. - * + *

*

For information on

  • how to construct a {@code ChronicleMap}
  • {@code * ChronicleMap} flavors and properties
  • available configurations
see {@link * ChronicleMapBuilder} documentation. - * + *

*

Functionally this interface defines some methods supporting garbage-free off-heap programming: * {@link #getUsing(Object, Object)}, {@link #acquireUsing(Object, Object)}. - * + *

*

Roughly speaking, {@code ChronicleMap} compares keys and values by their binary serialized * form, that shouldn't necessary be the same equality relation as defined by built-in {@link * Object#equals(Object)} method, which is prescribed by general {@link Map} contract. - * + *

*

Note that {@code ChronicleMap} extends {@link Closeable}, don't forget to {@linkplain #close() * close} map when it is no longer needed. * @@ -61,7 +61,7 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Returns the value to which the specified key is mapped, or {@code null} if this map contains * no mapping for the key. - * + *

*

If the value class allows reusing, particularly if it is a {@link Byteable} subclass, * consider {@link #getUsing(Object, Object)} method instead of this to reduce garbage * creation. @@ -77,7 +77,7 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Returns the value to which the specified key is mapped, read to the provided {@code value} * object, if possible, or returns {@code null}, if this map contains no mapping for the key. - * + *

*

If the specified key is present in the map, the value data is read to the provided {@code * value} object via value marshaller's {@link BytesMarshaller#read(Bytes, Object) read(Bytes, * value)} or value reader's {@link BytesReader#read(Bytes, long, Object) read(Bytes, size, @@ -85,7 +85,7 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * using which this map was constructed. If the value deserializer is able to reuse the given * {@code value} object, calling this method instead of {@link #get(Object)} could help to * reduce garbage creation. - * + *

*

The provided {@code value} object is allowed to be {@code null}, in this case {@code * map.getUsing(key, null)} call is semantically equivalent to simple {@code map.get(key)} * call. @@ -103,12 +103,12 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * The method is similar {@link V getUsing(K key, V usingValue);} but in addition read locks * the map segment to operations to be performed atomically. ( see the example below ) - * + *

* Returns the ReadContext which holds a map segment lock and provides method to get the value * ( to which the specified key is mapped) atomically ( see example below for an explanation ), * read to the provided {@code value} object, if possible, or returns {@code null}, if this map * contains no mapping for the key. - * + *

*

If the specified key is present in the map, the readContext.value() uses the provided * {@code usingValue} object via value marshaller's {@link BytesMarshaller#read(Bytes, Object) * read(Bytes, value)} or value reader's {@link BytesReader#read(Bytes, long, Object) @@ -128,14 +128,14 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * }

* To ensure that you can read the 'issueDate' and 'symbol' can be read atomically, these values * must be read while the segment lock is in place. - * - * + *

+ *

*

The provided {@code value} object is allowed to be {@code null}, in this case * * @param key the key whose associated value is to be returned * @param usingValue the object to read value data in, if possible * @return the read context containing the value to which the specified key is mapped - * + *

* no mapping for the key * @see #get(Object) * @see #getUsing(Object, Object) @@ -146,18 +146,18 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Acquire a value for a key, creating if absent. - * + *

*

If the specified key is absent in the map, {@linkplain ChronicleMapBuilder#defaultValue(Object) * default value} is taken or {@linkplain ChronicleMapBuilder#defaultValueProvider(DefaultValueProvider) * default value provider} is called. Then this object is put to this map for the specified * key. - * + *

*

Then, either if the key was initially absent in the map or already present, the value is * deserialized just as during {@link #getUsing(Object, Object) getUsing(key, usingValue)} call, * passed the same {@code key} and {@code usingValue} as into this method call. This means, as * in {@link #getUsing}, {@code usingValue} could safely be {@code null}, in this case a new * value instance is created to deserialize the data. - * + *

* In code, {@code acquireUsing} is specified as : *

{@code
      * V acquireUsing(K key, V usingValue) {
@@ -165,12 +165,12 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash {
      *         put(key, defaultValue(key));
      *     return getUsing(key, usingValue);
      * }}
- * - * + *

+ *

* Where {@code defaultValue(key)} returns either {@linkplain ChronicleMapBuilder#defaultValue(Object) * default value} or {@link ChronicleMapBuilder#defaultValueProvider(DefaultValueProvider) * defaultValueProvider.} - * + *

*

If the {@code ChronicleMap} is off-heap updatable, i. e. created via {@link * ChronicleMapBuilder} builder (values are {@link Byteable}), there is one more option of what * to do if the key is absent in the map. By default, value bytes are just zeroed out, no @@ -247,22 +247,21 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Creates an empty value instance, which can be used with the * following methods : - * + *

* {@link ChronicleMap#getUsing(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#getUsingLocked(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#acquireUsing(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#acquireUsingLocked(java.lang.Object, java.lang.Object) } - * + *

* for example like this : - * - *

{@code
+     * 

+ *

{@code
      * V value = map.newValueInstance();
      * try (ReadContext rc = map.getUsingLocked(key, value)) {
      *  // add your logic here
      * } // the read lock is released here
      * }
* - * * @return a new empty instance based on the Value type * @see ChronicleMap#getUsing(java.lang.Object, java.lang.Object) * @see ChronicleMap#getUsingLocked(java.lang.Object, java.lang.Object) @@ -274,15 +273,15 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Creates an empty value instance, which can be used with the * following methods : - * + *

* {@link ChronicleMap#getUsing(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#getUsingLocked(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#acquireUsing(java.lang.Object, java.lang.Object) } * {@link ChronicleMap#acquireUsingLocked(java.lang.Object, java.lang.Object) } - * + *

* for example like this : - * - *

{@code
+     * 

+ *

{@code
      * K key = map.newKeyInstance();
      * key.setMyStringField("some key");
      *
@@ -291,7 +290,6 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash {
      * } // the read lock is released here
      * }
* - * * @return a new empty instance based on the Key type * @see ChronicleMap#getUsing(java.lang.Object, java.lang.Object) * @see ChronicleMap#getUsingLocked(java.lang.Object, java.lang.Object) diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index bac787cce..cc8300e7a 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -151,6 +151,7 @@ public class ChronicleMapBuilder implements Cloneable, private PrepareValueBytes prepareValueBytes = null; private SingleChronicleHashReplication singleHashReplication = null; private InetSocketAddress[] pushToAddresses; + ChronicleMapBuilder(Class keyClass, Class valueClass) { keyBuilder = new SerializationBuilder<>(keyClass, SerializationBuilder.Role.KEY); valueBuilder = new SerializationBuilder<>(valueClass, SerializationBuilder.Role.VALUE); diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapStatelessClientBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapStatelessClientBuilder.java index 8cd064cd3..571331969 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapStatelessClientBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapStatelessClientBuilder.java @@ -32,10 +32,7 @@ public final class ChronicleMapStatelessClientBuilder implements ChronicleMap>, MapBuilder> { - static ChronicleMapStatelessClientBuilder of( - InetSocketAddress serverAddress) { - return new ChronicleMapStatelessClientBuilder<>(serverAddress); - } + private final InetSocketAddress remoteAddress; // This method is meaningful, despite you could call of().create(), because Java 7 doesn't // infer type parameters if case of chained calls, like this; and then you couldn't omit class @@ -44,33 +41,35 @@ public final class ChronicleMapStatelessClientBuilder implements // vs // createClientOf(addr) // static import // -- the second is really shorter. - - /** - * Equivalent of {@code ChronicleMapStatelessClientBuilder.of(serverAddress).create()}. - * - * @param serverAddress address of the server map - * @param key type of the map - * @param value type of the map - * @return stateless client of the ChronicleMap of server - */ - public static ChronicleMap createClientOf(InetSocketAddress serverAddress) - throws IOException { - return ChronicleMapStatelessClientBuilder.of(serverAddress).create(); - } - - private final InetSocketAddress remoteAddress; + private final AtomicBoolean used = new AtomicBoolean(false); private boolean putReturnsNull = false; private boolean removeReturnsNull = false; private long timeoutMs = TimeUnit.SECONDS.toMillis(10); private String name; private int tcpBufferSize = (int) MemoryUnit.KILOBYTES.toBytes(64); - private final AtomicBoolean used = new AtomicBoolean(false); - ChronicleMapStatelessClientBuilder(InetSocketAddress remoteAddress) { this.remoteAddress = remoteAddress; } + static ChronicleMapStatelessClientBuilder of( + InetSocketAddress serverAddress) { + return new ChronicleMapStatelessClientBuilder<>(serverAddress); + } + + /** + * Equivalent of {@code ChronicleMapStatelessClientBuilder.of(serverAddress).create()}. + * + * @param serverAddress address of the server map + * @param key type of the map + * @param value type of the map + * @return stateless client of the ChronicleMap of server + */ + public static ChronicleMap createClientOf(InetSocketAddress serverAddress) + throws IOException { + return ChronicleMapStatelessClientBuilder.of(serverAddress).create(); + } + InetSocketAddress remoteAddress() { return remoteAddress; } diff --git a/src/main/java/net/openhft/chronicle/map/ConstantValueProvider.java b/src/main/java/net/openhft/chronicle/map/ConstantValueProvider.java index 35f925722..0e68e8344 100644 --- a/src/main/java/net/openhft/chronicle/map/ConstantValueProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ConstantValueProvider.java @@ -24,10 +24,9 @@ import java.nio.ByteBuffer; final class ConstantValueProvider implements DefaultValueProvider { private static final long serialVersionUID = 0L; - - private transient V value; private final int size; private final byte[] serializedValueBytes; + private transient V value; ConstantValueProvider(V value, MetaBytesWriter metaValueWriter, W valueWriter) { this.value = value; diff --git a/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java b/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java index f97179f8f..f309147b7 100644 --- a/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java +++ b/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java @@ -24,7 +24,7 @@ import java.io.Closeable; /** * A simpler form of the replication interface used by Engine - * + *

* *** PLEASE DON'T REFACTOR THIS WITHOUT FIRST CHANGING THE ENGINE CODE *** * * @author Rob Austin. diff --git a/src/main/java/net/openhft/chronicle/map/Function.java b/src/main/java/net/openhft/chronicle/map/Function.java index 3498a19b2..9ecfecdb5 100644 --- a/src/main/java/net/openhft/chronicle/map/Function.java +++ b/src/main/java/net/openhft/chronicle/map/Function.java @@ -20,7 +20,7 @@ import java.io.Serializable; /** * Represents a function that accepts one argument and produces a result. - * + *

*

This is a functional interface whose functional method is {@link * #apply(Object)}. * diff --git a/src/main/java/net/openhft/chronicle/map/HashSplitting.java b/src/main/java/net/openhft/chronicle/map/HashSplitting.java index 9ab4a2dfa..3079f8328 100644 --- a/src/main/java/net/openhft/chronicle/map/HashSplitting.java +++ b/src/main/java/net/openhft/chronicle/map/HashSplitting.java @@ -23,18 +23,8 @@ import static net.openhft.lang.Maths.isPowerOf2; interface HashSplitting extends Serializable { int segmentIndex(long hash); - long segmentHash(long hash); - class Splitting { - static HashSplitting forSegments(int segments) { - assert segments > 0; - if (segments == 1) - return ForSingleSegment.INSTANCE; - if (isPowerOf2(segments)) - return new ForPowerOf2Segments(segments); - return new ForNonPowerOf2Segments(segments); - } - } + long segmentHash(long hash); enum ForSingleSegment implements HashSplitting { INSTANCE; @@ -50,6 +40,17 @@ interface HashSplitting extends Serializable { } } + class Splitting { + static HashSplitting forSegments(int segments) { + assert segments > 0; + if (segments == 1) + return ForSingleSegment.INSTANCE; + if (isPowerOf2(segments)) + return new ForPowerOf2Segments(segments); + return new ForNonPowerOf2Segments(segments); + } + } + class ForPowerOf2Segments implements HashSplitting { private static final long serialVersionUID = 0L; diff --git a/src/main/java/net/openhft/chronicle/map/Int24Int24MultiMap.java b/src/main/java/net/openhft/chronicle/map/Int24Int24MultiMap.java index e3011b5ec..f7b0c055a 100755 --- a/src/main/java/net/openhft/chronicle/map/Int24Int24MultiMap.java +++ b/src/main/java/net/openhft/chronicle/map/Int24Int24MultiMap.java @@ -302,6 +302,7 @@ class Int24Int24MultiMap implements MultiMap { public long capacity() { return capacity; } + @Override public DirectBitSet getPositions() { return positions; diff --git a/src/main/java/net/openhft/chronicle/map/IntIntMultiMap.java b/src/main/java/net/openhft/chronicle/map/IntIntMultiMap.java index c90b60f9a..ada72f987 100755 --- a/src/main/java/net/openhft/chronicle/map/IntIntMultiMap.java +++ b/src/main/java/net/openhft/chronicle/map/IntIntMultiMap.java @@ -213,7 +213,7 @@ class IntIntMultiMap implements MultiMap { @Override public long nextPos(SearchState searchState) { long pos = searchState.searchPos; - for(long count = capacity; count > 0; count--) { + for (long count = capacity; count > 0; count--) { long entry = bytes.readLong(pos); if (entry == UNSET_ENTRY) { searchState.searchPos = pos; diff --git a/src/main/java/net/openhft/chronicle/map/MapBuilder.java b/src/main/java/net/openhft/chronicle/map/MapBuilder.java index d057b9eb4..5d11ab63f 100644 --- a/src/main/java/net/openhft/chronicle/map/MapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/MapBuilder.java @@ -31,13 +31,13 @@ public interface MapBuilder> { * Configures if the maps created by this {@code MapBuilder} should return {@code null} * instead of previous mapped values on {@link ChronicleMap#put(Object, Object) * ChornicleMap.put(key, value)} calls. - * + *

*

{@link Map#put(Object, Object) Map.put()} returns the previous value, functionality * which is rarely used but fairly cheap for simple in-process, on-heap implementations like * {@link HashMap}. But an off-heap collection has to create a new object and deserialize * the data from off-heap memory. A collection hiding remote queries over the network should * send the value back in addition to that. It's expensive for something you probably don't use. - * + *

*

By default, of cause, {@code ChronicleMap} conforms the general {@code Map} contract and * returns the previous mapped value on {@code put()} calls. * @@ -53,13 +53,13 @@ public interface MapBuilder> { * Configures if the maps created by this {@code MapBuilder} should return {@code null} * instead of the last mapped value on {@link ChronicleMap#remove(Object) * ChronicleMap.remove(key)} calls. - * + *

*

{@link Map#remove(Object) Map.remove()} returns the previous value, functionality which is * rarely used but fairly cheap for simple in-process, on-heap implementations like {@link * HashMap}. But an off-heap collection has to create a new object and deserialize the data * from off-heap memory. A collection hiding remote queries over the network should send * the value back in addition to that. It's expensive for something you probably don't use. - * + *

*

By default, of cause, {@code ChronicleMap} conforms the general {@code Map} contract and * returns the mapped value on {@code remove()} calls. * diff --git a/src/main/java/net/openhft/chronicle/map/MapEventListener.java b/src/main/java/net/openhft/chronicle/map/MapEventListener.java index c57d37b4a..90bfa492c 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/MapEventListener.java @@ -26,18 +26,18 @@ import java.io.Serializable; /** * Contains methods which are called when {@link ChronicleMap} key events occur. Typical use cases: *

  • Map data backup / replication.
  • Logging, monitoring, debugging.
- * + *

*

This is an adapter class - all methods have default implementations as no-ops. Extend this * class and override only methods corresponding the events you are interested in. - * + *

*

To configure {@code MapEventListener} for {@code ChronicleMap}, use {@link * ChronicleMapBuilder#eventListener(MapEventListener)} method. - * + *

*

See {@link #logging(String)} implementation. - * + *

*

All these calls are synchronous while a {@code ChronicleMap} lock is held so make them as * quick as possible. - * + *

*

The {@code entry} passed to the methods is {@code Bytes} instance positioned at meta data * area. See {@link ChronicleHashBuilder#metaDataBytes(int)} for more information. * @@ -70,7 +70,7 @@ public abstract class MapEventListener implements Serializable { * ChronicleMapBuilder#defaultValue(Object) default} for the map or obtained during {@link * ChronicleMap#acquireUsing acquireUsing} call is put for the key, this method is called as * well. - * + *

*

This method is called when put is already happened. * * @param key the key the given value is put for diff --git a/src/main/java/net/openhft/chronicle/map/MapInstanceBuilder.java b/src/main/java/net/openhft/chronicle/map/MapInstanceBuilder.java index 4ed525ce6..43fa37799 100644 --- a/src/main/java/net/openhft/chronicle/map/MapInstanceBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/MapInstanceBuilder.java @@ -30,13 +30,12 @@ final class MapInstanceBuilder implements ChronicleHashInstanceBuilder>, Serializable { final ChronicleMapBuilder mapBuilder; + final AtomicBoolean used; transient SingleChronicleHashReplication singleHashReplication; transient ReplicationChannel channel; transient File file; String name; - final AtomicBoolean used; - MapInstanceBuilder(ChronicleMapBuilder mapBuilder, SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel, diff --git a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java index e6e1dc408..0d1decf24 100644 --- a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java +++ b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java @@ -27,7 +27,7 @@ import static net.openhft.lang.MemoryUnit.*; /** * Created by peter on 09/11/14. - * + *

* In future we might support I32 -> I16 or similar. */ enum MultiMapFactory { @@ -94,7 +94,7 @@ enum MultiMapFactory { if (minCapacity < 0L) throw new IllegalArgumentException("minCapacity should be positive"); long capacity = Maths.nextPower2(minCapacity, 16L); - if (((double) minCapacity) / capacity > 2./3.) { + if (((double) minCapacity) / capacity > 2. / 3.) { // multi map shouldn't be too dense capacity <<= 1L; } diff --git a/src/main/java/net/openhft/chronicle/map/PrepareValueBytes.java b/src/main/java/net/openhft/chronicle/map/PrepareValueBytes.java index 7ef9c33da..5f46c25c5 100644 --- a/src/main/java/net/openhft/chronicle/map/PrepareValueBytes.java +++ b/src/main/java/net/openhft/chronicle/map/PrepareValueBytes.java @@ -33,14 +33,13 @@ import java.io.Serializable; * .prepareDefaultValueBytes((bytes, k) -> bytes.writeLong(1L)) * ... * .create();}

- * + *

*

Although the value type is not used in the API, {@link PrepareValueBytes} is not intended * to be generic by value type, because strategy should know the value layout and * {@linkplain Byteable#maxSize() how much bytes} does it take in memory. * * @param the key type of {@link ChronicleMap}, on which {@code acquireUsing()} is queried * @param the value type of {@link ChronicleMap}, on which {@code acquireUsing()} is queried - */ public interface PrepareValueBytes extends Serializable { @@ -51,11 +50,11 @@ public interface PrepareValueBytes extends Serializable { * outside of this range shouldn't be altered. * * @param bytes the bytes, positioned at the first value byte. Bytes' {@linkplain Bytes#limit( - * long) limit} and {@linkplain Bytes#remaining()} are not specified, but it is guaranteed that - * the latter is not less than {@linkplain Byteable#maxSize() the value size}. - * @param key the key which is absent in the {@link ChronicleMap} during {@link - * ChronicleMap#acquireUsing(Object, Object) acquireUsing()} call and value bytes are prepared - * for + *long) limit} and {@linkplain Bytes#remaining()} are not specified, but it is guaranteed that + * the latter is not less than {@linkplain Byteable#maxSize() the value size}. + * @param key the key which is absent in the {@link ChronicleMap} during {@link + * ChronicleMap#acquireUsing(Object, Object) acquireUsing()} call and value bytes are prepared + * for */ void prepare(Bytes bytes, K key); } diff --git a/src/main/java/net/openhft/chronicle/map/ReadValue.java b/src/main/java/net/openhft/chronicle/map/ReadValue.java index e3d343c4f..547e6a3ab 100644 --- a/src/main/java/net/openhft/chronicle/map/ReadValue.java +++ b/src/main/java/net/openhft/chronicle/map/ReadValue.java @@ -28,5 +28,6 @@ interface ReadValue { * Updates the entry position by valueSize. */ RV readValue(@NotNull ThreadLocalCopies copies, Bytes entry, RV usingValue, long valueSize); + RV readNull(); } diff --git a/src/main/java/net/openhft/chronicle/map/Replica.java b/src/main/java/net/openhft/chronicle/map/Replica.java index eff3d1b3f..3b41542a3 100644 --- a/src/main/java/net/openhft/chronicle/map/Replica.java +++ b/src/main/java/net/openhft/chronicle/map/Replica.java @@ -48,7 +48,7 @@ interface Replica extends Closeable, EngineReplicationLangBytes { * Gets (if it does not exist, creates) an instance of ModificationIterator associated with a * remote node, this weak associated is bound using the {@code identifier}. * - * @param remoteIdentifier the identifier of the remote node + * @param remoteIdentifier the identifier of the remote node * @return the ModificationIterator dedicated for replication to the remote node with the given * identifier * @see #identifier() @@ -152,11 +152,12 @@ interface Replica extends Closeable, EngineReplicationLangBytes { /** * The map implements this method to save its contents. - * @param entry the byte location of the entry to be stored - * @param destination a buffer the entry will be written to, the segment may reject this - * operation and add zeroBytes, if the identifier in the entry did not - * match the maps local - * @param chronicleId is the channel id used to identify the canonical map or queue + * + * @param entry the byte location of the entry to be stored + * @param destination a buffer the entry will be written to, the segment may reject this + * operation and add zeroBytes, if the identifier in the entry did not + * match the maps local + * @param chronicleId is the channel id used to identify the canonical map or queue * @param bootstrapTime */ void writeExternalEntry(@NotNull Bytes entry, @@ -169,7 +170,7 @@ interface Replica extends Closeable, EngineReplicationLangBytes { * in the same sequence and with the same types as were written by {@code * writeExternalEntry()}. This method is typically called when we receive a remote * replication event, this event could originate from either a remote {@code put(K key, V - *value)} or {@code remove(Object key)} + * value)} or {@code remove(Object key)} * * @param copies * @param segmentState @@ -217,16 +218,14 @@ interface Replica extends Closeable, EngineReplicationLangBytes { /** * Called whenever a put() or remove() has occurred to a replicating map. * - * @param entry the entry you will receive, this does not have to be locked, as - * locking is already provided from the caller. - * @param chronicleId only assigned when clustering + * @param entry the entry you will receive, this does not have to be locked, as + * locking is already provided from the caller. + * @param chronicleId only assigned when clustering * @param bootStrapTimeStamp sent to the client on every update this is the timestamp * that the remote client should bootstrap from when there has * been a disconnection, this time maybe later than the message * time as event are not send in chronological order from the * bit set. - * - * * @return {@code false} if this entry should be ignored because the identifier of the * source node is not from one of our changes, WARNING even though we check the identifier * in the ModificationIterator the entry may have been updated. diff --git a/src/main/java/net/openhft/chronicle/map/SelectedSelectionKeySet.java b/src/main/java/net/openhft/chronicle/map/SelectedSelectionKeySet.java index 4495b787b..d9d5a4d99 100644 --- a/src/main/java/net/openhft/chronicle/map/SelectedSelectionKeySet.java +++ b/src/main/java/net/openhft/chronicle/map/SelectedSelectionKeySet.java @@ -41,14 +41,14 @@ final class SelectedSelectionKeySet extends AbstractSet { if (isA) { int size = keysASize; - keysA[size ++] = o; + keysA[size++] = o; keysASize = size; if (size == keysA.length) { doubleCapacityA(); } } else { int size = keysBSize; - keysB[size ++] = o; + keysB[size++] = o; keysBSize = size; if (size == keysB.length) { doubleCapacityB(); diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java index a707613e8..a08d07364 100755 --- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java @@ -49,6 +49,29 @@ final class SerializationBuilder implements Cloneable, Serializable { private static final long serialVersionUID = 0L; private static final Bytes EMPTY_BYTES = new ByteBufferBytes(ByteBuffer.allocate(0)); + private static final List knownJDKImmutableClasses = Arrays.asList( + String.class, Byte.class, Short.class, Character.class, Integer.class, + Float.class, Long.class, Double.class, BigDecimal.class, BigInteger.class, URL.class + ); + final Class eClass; + final boolean sizeIsStaticallyKnown; + private final Role role; + boolean serializesGeneratedClasses = false; + private boolean instancesAreMutable; + private SizeMarshaller sizeMarshaller = stopBit(); + private BytesReader reader; + private Object interop; + private CopyingInterop copyingInterop = null; + private MetaBytesInterop metaInterop; + private MetaProvider metaInteropProvider; + private long maxSize; + @SuppressWarnings("unchecked") + SerializationBuilder(Class eClass, Role role) { + this.role = role; + this.eClass = eClass; + configureByDefault(eClass, role); + sizeIsStaticallyKnown = constantSizeMarshaller(); + } private static boolean concreteClass(Class c) { return !c.isInterface() && !Modifier.isAbstract(c.getModifiers()); @@ -60,42 +83,10 @@ final class SerializationBuilder implements Cloneable, Serializable { Externalizable.class.isAssignableFrom(c); } - private static final List knownJDKImmutableClasses = Arrays.asList( - String.class, Byte.class, Short.class, Character.class, Integer.class, - Float.class, Long.class, Double.class, BigDecimal.class, BigInteger.class, URL.class - ); - private static boolean instancesAreMutable(Class c) { return !knownJDKImmutableClasses.contains(c); } - enum Role {KEY, VALUE} - - private enum CopyingInterop {FROM_MARSHALLER, FROM_WRITER} - - private final Role role; - final Class eClass; - private boolean instancesAreMutable; - private SizeMarshaller sizeMarshaller = stopBit(); - private BytesReader reader; - private Object interop; - private CopyingInterop copyingInterop = null; - private MetaBytesInterop metaInterop; - private MetaProvider metaInteropProvider; - private long maxSize; - - final boolean sizeIsStaticallyKnown; - - boolean serializesGeneratedClasses = false; - - @SuppressWarnings("unchecked") - SerializationBuilder(Class eClass, Role role) { - this.role = role; - this.eClass = eClass; - configureByDefault(eClass, role); - sizeIsStaticallyKnown = constantSizeMarshaller(); - } - private void configureByDefault(Class eClass, Role role) { instancesAreMutable = instancesAreMutable(eClass); @@ -446,6 +437,10 @@ final class SerializationBuilder implements Cloneable, Serializable { } } + enum Role {KEY, VALUE} + + private enum CopyingInterop {FROM_MARSHALLER, FROM_WRITER} + private static class SerializableMarshaller implements BytesMarshaller { private static final long serialVersionUID = 0L; diff --git a/src/main/java/net/openhft/chronicle/map/ShortShortMultiMap.java b/src/main/java/net/openhft/chronicle/map/ShortShortMultiMap.java index 05e617ca6..17f203345 100755 --- a/src/main/java/net/openhft/chronicle/map/ShortShortMultiMap.java +++ b/src/main/java/net/openhft/chronicle/map/ShortShortMultiMap.java @@ -227,7 +227,7 @@ class ShortShortMultiMap implements MultiMap { @Override public long nextPos(SearchState searchState) { int pos = (int) searchState.searchPos; - for(int count = capacity; count > 0; count--) { + for (int count = capacity; count > 0; count--) { int entry = bytes.readInt(pos); if (entry == UNSET_ENTRY) { searchState.searchPos = pos; diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 1847dd819..8f9a6a3ec 100755 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -1072,7 +1072,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon try { // block until we have received all the bytes in this chunk receiveBytesFromSocket(remainingBytes, timeoutTime); - }catch (java.nio.channels.AsynchronousCloseException e ){ + } catch (java.nio.channels.AsynchronousCloseException e) { return inBytes; } diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 77b428319..16784ec09 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1153,10 +1153,10 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo if (!message.startsWith("java.io.IOException: Not enough available space for writing ")) { throw e; } - String substring = message.substring("java.io.IOException: Not enough available space for writing ".length(), message.length()); - int i = substring.indexOf(' '); + String substring = message.substring("java.io.IOException: Not enough available space for writing ".length(), message.length()); + int i = substring.indexOf(' '); if (i == -1) - throw e; + throw e; int size = Integer.parseInt(substring.substring(0, i)); diff --git a/src/main/java/net/openhft/chronicle/map/UnaryOperator.java b/src/main/java/net/openhft/chronicle/map/UnaryOperator.java index 80cb1d047..878f01c71 100755 --- a/src/main/java/net/openhft/chronicle/map/UnaryOperator.java +++ b/src/main/java/net/openhft/chronicle/map/UnaryOperator.java @@ -20,11 +20,10 @@ import java.io.Serializable; /** * Represents a mutator that accepts one mutable argument, which it may alter and produces a result. - * + *

*

This is not functional as it can alter an argument. * * @param the type of the mutable input - */ public interface UnaryOperator extends Serializable { diff --git a/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java b/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java index 74e89ae0c..606a949c5 100755 --- a/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java +++ b/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java @@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit; /** * {@code ChronicleSetBuilder} manages the whole set of {@link ChronicleSet} configurations, could * be used as a classic builder and/or factory. - * + *

*

{@code ChronicleMapBuilder} is mutable, see a note in {@link * ChronicleHashBuilder} interface documentation. * @@ -101,21 +101,21 @@ public final class ChronicleSetBuilder /** * {@inheritDoc} - * + *

*

Example: if keys in your set(s) are English words in {@link String} form, average English * word length is 5.1, configure average key size of 6:

{@code
      * ChronicleSet uniqueWords = ChronicleSetBuilder.of(String.class)
      *     .entries(50000)
      *     .averageKeySize(6)
      *     .create();}
- * + *

*

(Note that 6 is chosen as average key size in bytes despite strings in Java are UTF-16 * encoded (and each character takes 2 bytes on-heap), because default off-heap {@link String} * encoding is UTF-8 in {@code ChronicleSet}.) * + * @param averageKeySize * @see #constantKeySizeBySample(Object) * @see #actualChunkSize(int) - * @param averageKeySize */ @Override public ChronicleSetBuilder averageKeySize(double averageKeySize) { @@ -125,7 +125,7 @@ public final class ChronicleSetBuilder /** * {@inheritDoc} - * + *

*

For example, if your keys are Git commit hashes:

{@code
      * Set gitCommitsOfInterest = ChronicleSetBuilder.of(byte[].class)
      *     .constantKeySizeBySample(new byte[20])
@@ -210,7 +210,7 @@ public final class ChronicleSetBuilder
 
     /**
      * {@inheritDoc}
-     *
+     * 

*

Example:

{@code Set set = ChronicleSetBuilder.of(Key.class)
      *     .entries(1_000_000)
      *     .keySize(100)
@@ -245,7 +245,7 @@ public final class ChronicleSetBuilder
 
     /**
      * {@inheritDoc}
-     *
+     * 

*

Actually this is just a convenience method supporting key marshaller configurations, made * initially during {@link #of(Class)} call. Because if you {@linkplain * #keyMarshaller(BytesMarshaller) configure} own custom key marshaller, this method doesn't diff --git a/src/main/java/net/openhft/chronicle/set/ChronicleSetStatelessClientBuilder.java b/src/main/java/net/openhft/chronicle/set/ChronicleSetStatelessClientBuilder.java index e8b365bf4..3373b61f4 100644 --- a/src/main/java/net/openhft/chronicle/set/ChronicleSetStatelessClientBuilder.java +++ b/src/main/java/net/openhft/chronicle/set/ChronicleSetStatelessClientBuilder.java @@ -28,10 +28,6 @@ public final class ChronicleSetStatelessClientBuilder implements ChronicleHashStatelessClientBuilder< ChronicleSetStatelessClientBuilder, ChronicleSet> { - public static ChronicleSetStatelessClientBuilder of(InetSocketAddress serverAddress) { - return new ChronicleSetStatelessClientBuilder<>(serverAddress); - } - private final ChronicleMapStatelessClientBuilder mapClientBuilder; ChronicleSetStatelessClientBuilder(InetSocketAddress serverAddress) { @@ -39,6 +35,10 @@ public final class ChronicleSetStatelessClientBuilder implements this.mapClientBuilder = ChronicleMapBuilder.of(eClass, DummyValue.class, serverAddress); } + public static ChronicleSetStatelessClientBuilder of(InetSocketAddress serverAddress) { + return new ChronicleSetStatelessClientBuilder<>(serverAddress); + } + @Override public ChronicleSetStatelessClientBuilder timeout(long timeout, TimeUnit units) { mapClientBuilder.timeout(timeout, units); diff --git a/src/main/java/net/openhft/chronicle/set/DummyValue.java b/src/main/java/net/openhft/chronicle/set/DummyValue.java index b89403094..18e4dc025 100644 --- a/src/main/java/net/openhft/chronicle/set/DummyValue.java +++ b/src/main/java/net/openhft/chronicle/set/DummyValue.java @@ -16,6 +16,6 @@ package net.openhft.chronicle.set; - enum DummyValue { +enum DummyValue { DUMMY_VALUE } diff --git a/src/main/java/net/openhft/chronicle/set/SetFromMap.java b/src/main/java/net/openhft/chronicle/set/SetFromMap.java index 4792450b9..7a3ddb335 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -31,6 +31,7 @@ import static net.openhft.chronicle.set.DummyValue.DUMMY_VALUE; class SetFromMap extends AbstractSet implements ChronicleSet, Serializable { + private static final long serialVersionUID = 2454657854757543876L; private final ChronicleMap m; // The backing map private transient Set s; // Its keySet @@ -96,13 +97,11 @@ class SetFromMap extends AbstractSet public boolean removeAll(Collection c) { return s.removeAll(c); } + // addAll is the only inherited implementation public boolean retainAll(Collection c) { return s.retainAll(c); } - // addAll is the only inherited implementation - - private static final long serialVersionUID = 2454657854757543876L; private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {