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 aa7e23b4d..7e0e48d44 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationChannel.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.hash.replication; import net.openhft.chronicle.hash.ChronicleHash; -import net.openhft.chronicle.hash.ChronicleHashBuilder; import net.openhft.chronicle.hash.ChronicleHashInstanceConfig; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java index 1e26a0720..f86fab3dc 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java @@ -57,17 +57,17 @@ import static net.openhft.chronicle.map.Objects.builderEquals; /** * {@code AbstractChronicleMapBuilder} manages most of {@link ChronicleMap} configurations; has two concrete - * subclasses: {@link OnHeapUpdatableChronicleMapBuilder} should be used to create maps with ordinary values, {@link - * ChronicleMapBuilder} -- maps with {@link Byteable} values, which point directly to off-heap - * memory; could be used as a classic builder and/or factory. This means + * subclasses: {@link OnHeapUpdatableChronicleMapBuilder} should be used to create maps with ordinary values, + * {@link ChronicleMapBuilder} -- maps with {@link Byteable} values, which point directly to off-heap memory; + * could be used as a classic builder and/or factory. This means * that in addition to the standard builder usage pattern:
{@code
* ChronicleMap map = ChronicleMapOnHeapUpdatableBuilder
* .of(Key.class, Value.class)
* .entries(100500)
* // ... other configurations
* .create();}
- * one of concrete {@code AbstractChronicleMapBuilder} subclasses, {@link OnHeapUpdatableChronicleMapBuilder} or {@link
- * ChronicleMapBuilder}, could be prepared and used to create many similar
+ * one of concrete {@code AbstractChronicleMapBuilder} subclasses, {@link OnHeapUpdatableChronicleMapBuilder}
+ * or {@link ChronicleMapBuilder}, could be prepared and used to create many similar
* maps: {@code
* ChronicleMapBuilder builder = ChronicleMapBuilder
* .of(Key.class, Value.class)
@@ -94,9 +94,9 @@ import static net.openhft.chronicle.map.Objects.builderEquals;
* @see ChronicleMap
* @see ChronicleSetBuilder
*/
-public abstract class AbstractChronicleMapBuilder>
- implements Cloneable, ChronicleHashBuilder, B> {
+ implements Cloneable, ChronicleHashBuilder, B>, ChronicleMapBuilderI {
static final short UDP_REPLICATION_MODIFICATION_ITERATOR_ID = 128;
private static final Bytes EMPTY_BYTES = new ByteBufferBytes(ByteBuffer.allocate(0));
@@ -110,6 +110,8 @@ public abstract class AbstractChronicleMapBuilder keyBuilder;
SerializationBuilder valueBuilder;
+ private String name;
+
// used when configuring the number of segments.
private int minSegments = -1;
private int actualSegments = -1;
@@ -243,14 +245,14 @@ public abstract class AbstractChronicleMapBuilder prepareValueBytes) {
+ public B prepareValueBytesOnAcquire(@NotNull PrepareValueBytes prepareValueBytes) {
this.prepareValueBytes = prepareValueBytes;
this.defaultValue = null;
this.defaultValueProvider = null;
@@ -842,7 +844,7 @@ public abstract class AbstractChronicleMapBuilder createReplicated(byte identifier) throws IOException {
+ public ChronicleMap createReplicated(byte identifier) throws IOException {
preMapConstruction(true);
VanillaChronicleMap map =
new ReplicatedChronicleMap,
@@ -952,5 +954,16 @@ public abstract class AbstractChronicleMapBuilder> 10),
VanillaChronicleMap.MAX_ENTRY_OVERSIZE_FACTOR);
}
+
+ @Override
+ public ChronicleMapBuilderI name(String name) {
+ this.name = name;
+ return this;
+ }
+
+
+ public String name() {
+ return this.name;
+ }
}
diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java
index 736fab825..0f68572fa 100644
--- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java
+++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java
@@ -330,6 +330,23 @@ public final class ChronicleMapBuilder implements ChronicleMapBuilderI name(String name) {
+ delegate.name(name);
+ return this;
+ }
+
+ @Override
+ public String name() {
+ return delegate.name() ;
+ }
+
@Override
public ChronicleMapBuilder replication(SingleChronicleHashReplication withId) {
delegate.replication(withId);
diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilderI.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilderI.java
index 7a1f4e948..9e89e8b89 100644
--- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilderI.java
+++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilderI.java
@@ -17,13 +17,14 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
+import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
/**
* @author Rob Austin.
*/
-interface ChronicleMapBuilderI {
+interface ChronicleMapBuilderI extends Serializable {
/**
@@ -296,4 +297,9 @@ interface ChronicleMapBuilderI {
ChronicleMapBuilderI removeReturnsNull(boolean b);
+ ChronicleMapBuilderI name(String name);
+
+ String name();
+
+
}
diff --git a/src/main/java/net/openhft/chronicle/map/FindMapByName.java b/src/main/java/net/openhft/chronicle/map/FindMapByName.java
new file mode 100644
index 000000000..74778866a
--- /dev/null
+++ b/src/main/java/net/openhft/chronicle/map/FindMapByName.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.openhft.chronicle.map;
+
+import net.openhft.chronicle.hash.replication.ReplicationHub;
+import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Rob Austin.
+ */
+class FindMapByName {
+
+ int maxEntrySize = 10*1024;
+
+
+ private final ReplicationHub replicationHub;
+ private Map map;
+
+ public FindMapByName(byte identifier) throws IOException {
+
+
+ final TcpTransportAndNetworkConfig tcpConfig =
+ TcpTransportAndNetworkConfig.of(8076)
+ .heartBeatInterval(1, TimeUnit.SECONDS);
+
+ replicationHub = ReplicationHub.builder()
+ .maxEntrySize(maxEntrySize)
+ .tcpTransportAndNetwork(tcpConfig)
+ .createWithId(identifier);
+
+ map = (Map)ChronicleMapBuilder.of(CharSequence.class, ChronicleMapBuilder.class)
+ .entrySize(300)
+ .instance()
+ .replicatedViaChannel(replicationHub.createChannel((short) 1)).create();
+ }
+
+ public ChronicleMapBuilder get(String name) throws IOException {
+ return map.get(name);
+ }
+
+
+ public void add(ChronicleMapBuilder builder) throws IOException {
+ builder.name();
+ this.map.put(builder.name(), builder);
+ }
+}
diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
index 7c69e0718..f1e41bbc5 100644
--- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
+++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
@@ -42,7 +42,7 @@ import static net.openhft.chronicle.map.Objects.hash;
import static net.openhft.chronicle.hash.serialization.SizeMarshallers.stopBit;
import static net.openhft.chronicle.map.SerializationBuilder.Role.KEY;
-final class SerializationBuilder implements Cloneable {
+final class SerializationBuilder implements Cloneable, Serializable{
private static boolean concreteClass(Class c) {
return !c.isInterface() && !Modifier.isAbstract(c.getModifiers());
diff --git a/src/test/java/net/openhft/chronicle/map/MapByNameTest.java b/src/test/java/net/openhft/chronicle/map/MapByNameTest.java
new file mode 100644
index 000000000..d19360bd4
--- /dev/null
+++ b/src/test/java/net/openhft/chronicle/map/MapByNameTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.openhft.chronicle.map;
+
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * @author Rob Austin.
+ */
+public class MapByNameTest {
+
+
+ private FindMapByName findMapByName;
+
+ @Before
+ public void setUp() throws IOException {
+ findMapByName = new FindMapByName((byte) 2);
+ }
+
+ @Test
+
+ public void test() throws IOException, InterruptedException {
+
+ ChronicleMapBuilder builder = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
+ .minSegments(2)
+ .name("map1")
+ .removeReturnsNull(true);
+
+ final ChronicleMap map =
+ builder.create();
+
+
+ findMapByName.add(builder);
+ ChronicleMapBuilder map1 = findMapByName.get("map1");
+
+ ChronicleMap chronicleMap = map1.create();
+ chronicleMap.put("hello","world");
+
+ Assert.assertEquals(chronicleMap.get("hello"), "world");
+ }
+
+
+}