HCOLL-167 simplified the map builder by making "file" very much an option parameter, is it not REQUIRED for all types of maps. Also updated the many of the TCP replication test to remove the user of file() as its simply not required for this in many cases.

This commit is contained in:
Rob Austin
2014-10-20 17:19:27 +01:00
parent 1b40eb8147
commit 8e57eeafc2
41 changed files with 193 additions and 193 deletions
@@ -362,31 +362,20 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
*/
B stateless(StatelessBuilder statelessBuilder);
/**
* 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.
*
* <p>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.
*
* <p>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.
* Specifies that hash containers us the specified file, if create is called and this is not set
* the map will be created in off-heap memory, and changes will not be persisted to disk. If a
* file is provided all changes to the map are persisted to disk (this is an operating system
* guarantee) independently from JVM process lifecycle.
*
* @param file the file with existing hash container or a desired location of a new off-heap
* persisted hash container
* @return a hash container mapped to the given file
* @throws IOException if any IO error, related to off-heap memory allocation or file mapping
* occurs
* @return this builder back
* @see ChronicleHash#file()
* @see ChronicleHash#close()
* @see #create()
*/
C create(File file) throws IOException;
B file(File file) throws IOException;
/**
* Creates a new hash container, storing it's data in off-heap memory, not mapped to any file.
@@ -401,4 +390,8 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
C create() throws IOException;
}
@@ -130,6 +130,7 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
private byte identifier = -1;
private StatelessBuilder statelessBuilder;
private File file;
ChronicleMapBuilder(Class<K> keyClass, Class<V> valueClass) {
keyBuilder = new SerializationBuilder<K>(keyClass, SerializationBuilder.Role.KEY);
@@ -672,6 +673,12 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
return this;
}
@Override
public ChronicleMapBuilder<K, V> file(File file) throws IOException {
this.file = file;
return this;
}
public ChronicleMapBuilder<K, V> valueMarshallerAndFactory(
@NotNull BytesMarshaller<V> valueMarshaller, @NotNull ObjectFactory<V> valueFactory) {
valueBuilder.marshaller(valueMarshaller, valueFactory);
@@ -759,8 +766,7 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
return new ConstantValueProvider<K, V>(defaultValue, metaValueWriter, valueWriter);
}
@Override
public ChronicleMap<K, V> create(File file) throws IOException {
public ChronicleMap<K, V> createWithFile(File file) throws IOException {
for (int i = 0; i < 10; i++) {
if (file.exists() && file.length() > 0) {
FileInputStream fis = new FileInputStream(file);
@@ -810,10 +816,14 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
@Override
public ChronicleMap<K, V> create() throws IOException {
if (statelessBuilder != null) {
if (statelessBuilder != null)
return createStatelessMap(statelessBuilder);
}
return (file != null) ? createWithFile(file) : createWithoutFile();
}
private ChronicleMap<K, V> createWithoutFile() throws IOException {
VanillaChronicleMap<K, ?, ?, V, ?, ?> map = newMap();
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
map.sizeInBytes(), true);
@@ -824,11 +834,10 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
private ChronicleMap<K, V> createStatelessMap(StatelessBuilder statelessBuilder) throws IOException {
preMapConstruction();
KeyValueSerializer keyValueSerializer = new KeyValueSerializer(this.keyBuilder,
this.valueBuilder);
final KeyValueSerializer<K, V> keyValueSerializer
= new KeyValueSerializer<K, V>(keyBuilder, valueBuilder);
return new StatelessMapClient<K, V>(keyValueSerializer,
statelessBuilder);
return new StatelessMapClient<K, V>(keyValueSerializer, statelessBuilder);
}
private VanillaChronicleMap<K, ?, ?, V, ?, ?> newMap() throws IOException {
@@ -261,9 +261,9 @@ public class ChronicleSetBuilder<E>
}
@Override
public ChronicleSet<E> create(File file) throws IOException {
final ChronicleMap<E, DummyValue> map = chronicleMapBuilder.create(file);
return new SetFromMap<E>(map);
public ChronicleSetBuilder<E> file(File file) throws IOException {
chronicleMapBuilder.file(file);
return this;
}
@Override
@@ -272,5 +272,7 @@ public class ChronicleSetBuilder<E>
return new SetFromMap<E>(map);
}
}