diff --git a/src/main/java/net/openhft/chronicle/map/EngineMap.java b/src/main/java/net/openhft/chronicle/map/EngineMap.java index facd20a1b..0c82b5070 100644 --- a/src/main/java/net/openhft/chronicle/map/EngineMap.java +++ b/src/main/java/net/openhft/chronicle/map/EngineMap.java @@ -1,6 +1,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.bytes.Bytes; +import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder; import net.openhft.chronicle.hash.function.SerializableFunction; import net.openhft.chronicle.wire.TextWire; import net.openhft.chronicle.wire.Wire; @@ -16,6 +17,8 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; +import static net.openhft.chronicle.map.ChronicleMapBuilder.of; + /** * Created by Rob Austin */ @@ -34,10 +37,19 @@ public class EngineMap implements ChronicleMap { Class kClass, Class vClass, MapWireConnectionHub mapWireConnectionHub, - Class wireType) throws IOException { + Class wireType, + long entries) throws IOException { + this.mapWireConnectionHub = mapWireConnectionHub; this.wireType = wireType; - final BytesChronicleMap b = this.mapWireConnectionHub.acquireMap(name); + + + // todo - for the moment we will default to 100 entries per map, but this is for engine to + // todo decided later. + final ChronicleHashInstanceBuilder instance + = of(byte[].class, byte[].class).entries(entries).instance(); + + final BytesChronicleMap b = this.mapWireConnectionHub.acquireMap(name, instance); this.map = (Map) b.delegate; this.vClass = vClass; this.kClass = kClass; diff --git a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java index 2bfbd65c7..a746939b6 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java @@ -74,6 +74,7 @@ public class MapWireConnectionHub implements Closeable { } return (short) (max + 1); + } /** @@ -81,12 +82,12 @@ public class MapWireConnectionHub implements Closeable { * channel * * @param fromName the name of the channel + * @param builder * @return the id associated with this name */ - BytesChronicleMap acquireMap(@NotNull final String fromName) throws IOException { - - // todo this is a horrible hack, it slow and NOT processor safe, but was added to get - // todo something working for now. + BytesChronicleMap acquireMap(@NotNull final String fromName, + @NotNull final ChronicleHashInstanceBuilder builder) + throws IOException { final Integer channelId = channelNameToId.get(fromName); @@ -96,12 +97,14 @@ public class MapWireConnectionHub implements Closeable { final int nextFreeChannel = getNextFreeChannel(); try { - mapFactory.get().replicatedViaChannel(hub.createChannel(nextFreeChannel)).create(); + + builder.replicatedViaChannel(hub.createChannel(nextFreeChannel)).create(); channelNameToId.put(fromName, nextFreeChannel); return bytesMap(nextFreeChannel); + } catch (IOException e) { - // todo send this error back to the user + // todo send this error back to the user in wire LOG.error("", e); throw e; } diff --git a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java index 6c3525223..892e712a5 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java @@ -48,6 +48,7 @@ import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnect import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields.csp; import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields.reply; import static net.openhft.chronicle.engine.client.StringUtils.endsWith; +import static net.openhft.chronicle.map.ChronicleMapBuilder.*; import static net.openhft.chronicle.map.MapWireHandler.EventId.*; import static net.openhft.chronicle.map.MapWireHandler.Params.*; import static net.openhft.chronicle.wire.Wires.acquireStringBuilder; @@ -96,7 +97,10 @@ public class MapWireHandler implements WireHandler, Consumer hash != -1 && hash < (cspText.length() - 1)) { final String channelStr = cspText.substring(slash + 1, hash); try { - bytesChronicleMap = mapWireConnectionHub.acquireMap(channelStr); + + // todo better get the number of entries + bytesChronicleMap = mapWireConnectionHub.acquireMap(channelStr, + of(byte[].class, byte[].class).entries(1000).instance()); } catch (IOException e) { // todo send to user