diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java index 00bd382bc..5a1381679 100755 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java @@ -17,6 +17,7 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.bytes.Byteable; +import net.openhft.chronicle.bytes.Bytes; import net.openhft.chronicle.hash.replication.ReplicableEntry; import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication; import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; @@ -44,6 +45,16 @@ import java.util.concurrent.TimeUnit; * the corresponding configuration changed. To make an independent configuration, {@linkplain * #clone} the builder. * + *
{@code ChronicleHashBuilder} focuses on configurations, it could be used to create several + * containers of the same key-value domain. In this case {@code ChronicleHashBuilder} play like a + * factory (design pattern), rather than builder. The {@code ChronicleHashBuilder} could be + * "converted" to an {@link ChronicleHashInstanceBuilder} using {@link #instance()} method. + * {@code ChronicleHashInstanceBuilder} is a classic disposable builder, allowing to configure + * parameters, supposed to be unique for each created Chronicle Hash. + * + *
{@code ChronicleHashBuilder} instances are not safe for concurrent use from multiple threads, + * if at least one of the threads mutates the {@code ChronicleHashBuilder}'s state. + * *
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 applied as-is, without extra round-ups, adjustments,
@@ -472,7 +483,10 @@ public interface ChronicleHashBuilder 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.
+ * either by this method or {@link #replication(byte, TcpTransportAndNetworkConfig)}, or
+ * {@link #replication(byte)} shortcut methods.
*
* @param replication the replication config
* @return this builder back
@@ -538,7 +552,8 @@ public interface ChronicleHashBuilder This method is used to configure a replicated Chronicle Hash, that shouldn't communicate
+ * to other nodes. For example, if several processes access the same persisted Chronicle Hash,
+ * only one of them should communicate to other nodes and replicate entries.
+ *
+ * @param identifier the network-wide identifier for containers, created by this builder. This
+ * identifier is used when calling e. g. put() of the created container, to write the entry
+ * origin identifier (along with timestamp) into the entry memory. This change may be replicated
+ * to other nodes by a concurrent (or later) process, mapping to the same file.
+ * @return this builder back
+ */
B replication(byte identifier);
+ /**
+ * Returns a new {@code ChronicleHashInstanceBuilder}, which inherits configuration from this
+ * builder (in it's current state) and could be used to specify individual configurations
+ * for a Chronicle Hash container. Changes to this {@code ChronicleHashBuilder}, made after
+ * an instance is create, doesn't affect that instance, i. e. the returned instance is
+ * independent from the {@code ChronicleHashBuilder}, used to create it.
+ *
+ * @return a new Chronicle Hash instance builder
+ */
ChronicleHashInstanceBuilder This method is a shortcut for {@code instance().create()}.
+ * Creates a new hash container from this builder, storing it's data in off-heap memory, not
+ * mapped to any file. On {@link ChronicleHash#close()} called on the returned container, or
+ * after the container object is collected during GC, or on JVM shutdown the off-heap memory
+ * used by the returned container is freed.
*
* @return a new off-heap hash container
* @see #createPersistedTo(File)
- * @see #instance()
*/
H create();
/**
- * Opens a hash container residing the specified file, or creates a new one if the file not yet
- * exists and maps its off-heap memory to the file. All changes to the map are persisted to disk
- * (this is an operating system guarantee) independently from JVM process lifecycle.
+ * Opens a hash container residing the specified file, or creates a new one from this builder,
+ * if the file doesn't yet exist and maps its off-heap memory to the file. All changes to the
+ * map are persisted to disk (this is an operating system guarantee) independently from JVM
+ * process lifecycle.
*
* 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.
diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java
index 206571436..9d9710bc5 100644
--- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java
+++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashInstanceBuilder.java
@@ -19,10 +19,32 @@ package net.openhft.chronicle.hash;
import net.openhft.chronicle.hash.replication.ReplicationChannel;
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
+import net.openhft.chronicle.map.ChronicleMap;
+import net.openhft.chronicle.set.ChronicleSet;
import java.io.File;
import java.io.IOException;
+/**
+ * A disposable builder of {@link ChronicleHash} instances, allowing to set unique configurations
+ * using "chaining" pattern.
+ *
+ * Usage example: Another way to establish replication is {@link #replicated(SingleChronicleHashReplication)} method
- * or it's shortcut: {@link #replicated(byte, TcpTransportAndNetworkConfig)}.
+ * 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.
*
@@ -52,9 +74,44 @@ public interface ChronicleHashInstanceBuilder By default, persistence file is configured to {@code null}, i. e. the in-memory Chronicle
+ * Hash instance is created.
+ *
+ * @param file the file the Chronicle Hash, which is going to be created by this builder, should
+ * be persisted to, to {@code null}, if the Chronicle Hash should be purely
+ * in-memory
+ * @return this builder back
+ */
+ ChronicleHashInstanceBuilder {@code ChronicleMap} ("ChronicleMaps, created by {@code ChronicleMapBuilder}") currently
- * doesn't support resizing. That is why you must configure {@linkplain #entries(long) number
- * of entries} you are going to insert into the created map at most. See {@link
+ * In addition to the key and value types, you must configure {@linkplain #entries(long)
+ * number of entries} you are going to insert into the created map at most. See {@link
* #entries(long)} method documentation for more information on this.
*
* If you key or value type is not constantly sized and known to {@code ChronicleHashBuilder}, i.
- * e. it is not a boxed primitive, value interface, or {@link Byteable}, you must provide the
- * {@code ChronicleHashBuilder} with some information about you keys or values: if they are
- * constantly-sized, call {@link #constantKeySizeBySample(Object)}, otherwise {@link
- * ChronicleHashBuilder#averageKeySize(double)} method, accordingly for values.
+ * e. it is not a boxed primitive, {@linkplain net.openhft.chronicle.values.Values value interface},
+ * or {@link Byteable}, you must provide the {@code ChronicleHashBuilder} with some
+ * information about you keys or values: if they are constantly-sized, call {@link
+ * #constantKeySizeBySample(Object)}, otherwise {@link #averageKey(Object)} or {@link
+ * #averageKeySize(double)} method, and accordingly for values.
*
* @param {@code
+ * ChronicleMap
+ *
+ * @param {@code
* ChronicleMap
* it could be prepared and used to create many similar maps: {@code
* ChronicleMapBuilder
@@ -85,19 +85,20 @@ import static net.openhft.chronicle.map.VanillaChronicleMap.alignAddr;
* ChronicleMapBuilder}", unless specified different, because theoretically someone might provide
* {@code ChronicleMap} implementations with completely different properties.
*
- *