Java 8 使用编年史地图时发生IllegalArgumentException

Java 8 使用编年史地图时发生IllegalArgumentException,java-8,chronicle-map,Java 8,Chronicle Map,我正试图写一个程序使用编年史地图。我已经编写了一个UDP服务器,它将每1秒广播一条消息。UDP客户端将接收消息并将消息存储在历史记录映射中。计划如下: UDP服务器程序: public class UDPServer { public static void main(String[] args) { DatagramSocket socket = null; try { socket = new DatagramSocket()

我正试图写一个程序使用编年史地图。我已经编写了一个UDP服务器,它将每1秒广播一条消息。UDP客户端将接收消息并将消息存储在历史记录映射中。计划如下:

UDP服务器程序:

public class UDPServer {

    public static void main(String[] args) {
        DatagramSocket socket = null;
        try {
            socket = new DatagramSocket();
            byte[] buf = new byte[256];
            String messg = "Hello UDP Server\n";
            String transmittedMsg = null;
            int count = 0;

            while (true) {
                transmittedMsg = count + "";
                buf = transmittedMsg.getBytes();
                InetAddress address = InetAddress.getByName ("127.0.0.1");
                DatagramPacket packet = new DatagramPacket (buf, buf.length, address, 4000);
                socket.send(packet);

                Thread.sleep(1000);
                count++;
            }
        } catch (SocketTimeoutException ex) {
            System.out.println("Timeout error: " + ex.getMessage());
            ex.printStackTrace();
        } catch (IOException ex) {
            System.out.println("Client error: " + ex.getMessage());
            ex.printStackTrace();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        } finally {
            socket.close();
        }
    }
}
UDP客户端程序:

public class UDPClient {

    public static void main(String[] args) {
        DatagramSocket socket = null;
        DatagramPacket packet = null;
        byte[] buf = new byte[256];
        ChronicleMap<String, String> cr = null;

        try {
            socket = new DatagramSocket(4000);
            InetAddress address = InetAddress.getByName ("127.0.0.1");

            while (true) {
                packet = new DatagramPacket(buf, buf.length, address, 5000);
                socket.receive(packet);
                String received = new String(packet.getData());
                System.out.println(received);

                cr = ChronicleMapBuilder.of(String.class, String.class)
                        .name("test-map")
                        .averageKey("Message")
                        .averageValue("0")
                        .entries(1)
                        .actualChunkSize(100)
                        .actualSegments(1)
                        .createPersistedTo(new File("D://test.txt"));

                cr.put("Message", received);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (cr != null) {
                cr.close();
            }
        }
    }
}

请帮助。

显然,您收到的某些条目比

averageKey(“消息”)
平均值(“0”)
你指定的

您还可以混合使用高级配置:
averageKey()
averageValue()
entries()
,以及低级配置:
actualChunkSize()
actualSegments()
,这是不推荐的

java.lang.IllegalArgumentException: ChronicleMap{name=test-map, file=D:\test.txt, identityHashCode=11583403}: Entry is too large: requires 68 chunks, 9 is maximum.
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.allocReturnCode(CompiledMapQueryContext.java:1805)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.allocReturnCodeGuarded(CompiledMapQueryContext.java:123)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.alloc(CompiledMapQueryContext.java:3468)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.initEntryAndKey(CompiledMapQueryContext.java:3502)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.putEntry(CompiledMapQueryContext.java:3995)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.doInsert(CompiledMapQueryContext.java:4184)
    at net.openhft.chronicle.map.MapEntryOperations.insert(MapEntryOperations.java:153)
    at net.openhft.chronicle.map.impl.CompiledMapQueryContext.insert(CompiledMapQueryContext.java:4107)
    at net.openhft.chronicle.map.MapMethods.put(MapMethods.java:88)
    at net.openhft.chronicle.map.VanillaChronicleMap.put(VanillaChronicleMap.java:724)
    at udp.client.UDPClient.main(UDPClient.java:38)