net.openhft.chronicle.wire.Marshallable Java Examples
The following examples show how to use
net.openhft.chronicle.wire.Marshallable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterTest.java From Chronicle-Network with Apache License 2.0 | 6 votes |
@Test public void testDeepCopy() { MyClusterContext cc = (MyClusterContext) new MyClusterContext().value(22).wireType(WireType.TEXT); String s = Marshallable.$toString(cc); MyClusterContext o = Marshallable.fromString(s); Assert.assertEquals(cc.value, o.value); MyClusterContext cc2 = cc.deepCopy(); Assert.assertEquals(cc.value, cc2.value); try (Cluster<HostDetails, ?, MyClusterContext<?>> c = new MyCluster("mine")) { c.clusterContext(cc); try (Cluster<HostDetails, ?, MyClusterContext<?>> c2 = c.deepCopy()) { MyClusterContext mcc = c2.clusterContext(); Assert.assertNotNull(mcc); Assert.assertEquals(22, mcc.value); } } }
Example #2
Source File: ChronicleMapBuilder.java From Chronicle-Map with Apache License 2.0 | 6 votes |
/** * Returns a new {@code ChronicleMapBuilder} instance which is able to {@linkplain #create() * create} maps with the specified key and value classes. It makes some assumptions about the size of entries * and the marshallers used * * @param keyClass class object used to infer key type and discover it's properties via * reflection * @param valueClass class object used to infer value type and discover it's properties via * reflection * @param <K> key type of the maps, created by the returned builder * @param <V> value type of the maps, created by the returned builder * @return a new builder for the given key and value classes */ public static <K, V> ChronicleMapBuilder<K, V> simpleMapOf( @NotNull Class<K> keyClass, @NotNull Class<V> valueClass) { ChronicleMapBuilder<K, V> builder = new ChronicleMapBuilder<>(keyClass, valueClass) .putReturnsNull(true) .removeReturnsNull(true); builder.name(toCamelCase(valueClass.getSimpleName())); if (!builder.isKeySizeKnown()) builder.averageKeySize(128); if (!builder.isValueSizeKnown()) builder.averageValueSize(512); if (BytesMarshallable.class.isAssignableFrom(valueClass)) { builder.valueMarshaller(new BytesMarshallableReaderWriter<>((Class) valueClass)); } else if (Marshallable.class.isAssignableFrom(valueClass)) { //noinspection unchecked builder.averageValueSize(1024) .valueMarshaller(new MarshallableReaderWriter<>((Class) valueClass)); } return builder; }
Example #3
Source File: ResultGenerator.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
private static long getLatestTimestamp(final EightyByteMessage message) { if (EightyByteMessage.isSet(message.t6)) { return message.t6; } if (EightyByteMessage.isSet(message.t5)) { return message.t5; } if (EightyByteMessage.isSet(message.t4)) { return message.t4; } if (EightyByteMessage.isSet(message.t3)) { return message.t3; } if (EightyByteMessage.isSet(message.t2)) { return message.t2; } if (EightyByteMessage.isSet(message.t1)) { return message.t1; } if (EightyByteMessage.isSet(message.t0)) { return message.t0; } throw new IllegalStateException("No values were set on message: " + Marshallable.$toString(message)); }
Example #4
Source File: SerializationBuilder.java From Chronicle-Map with Apache License 2.0 | 5 votes |
private static void checkNonMarshallableEnum(Class c) { if (Enum.class.isAssignableFrom(c) && (Marshallable.class.isAssignableFrom(c) || ReadResolvable.class.isAssignableFrom(c))) { throw new IllegalArgumentException(c + ": since Chronicle Map 3.9.0, enum marshaller " + "shouldn't be a Java enum and implement " + Marshallable.class.getName() + " or " + ReadResolvable.class.getName() + ". There are problems with " + "serializing/deserializing them in Chronicle Map header. Emulate enums by " + "static final fields"); } }
Example #5
Source File: SingleChronicleQueueBuilderTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testReadMarshallable() { SingleChronicleQueueBuilder builder = Marshallable.fromString("!net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder {\n" + " writeBufferMode: None,\n" + " readBufferMode: None,\n" + " wireType: BINARY_LIGHT,\n" + " path: " + DirectoryUtils.tempDir("marshallable") + " rollCycle: !net.openhft.chronicle.queue.RollCycles DAILY,\n" + " onRingBufferStats: !net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder$NoBytesRingBufferStats NONE,\n" + " timeProvider: !net.openhft.chronicle.core.time.SystemTimeProvider INSTANCE,\n" + "}\n"); builder.build().close(); }
Example #6
Source File: SingleChronicleQueueBuilderTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testWriteMarshallable() { final SingleChronicleQueueBuilder builder = SingleChronicleQueueBuilder.single("test").rollCycle(HOURLY); builder.build().close(); String val = Marshallable.$toString(builder); System.err.println(val); SingleChronicleQueueBuilder builder2 = Marshallable.fromString(val); builder2.build().close(); }
Example #7
Source File: ResultGenerator.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Override public void onEightyByteMessage(final EightyByteMessage message) { final MessageHistory messageHistory = MessageHistory.get(); if (maxQueueDeltas.length == 0) { maxQueueDeltas = new long[(messageHistory.timings() - 1)]; } long batchStartEpochSeconds = message.batchStartMillis / 1000; for (int i = 0; i < messageHistory.timings() - 1; i++) { maxQueueDeltas[i] = Math.max(messageHistory.timing(i + 1) - messageHistory.timing(i), maxQueueDeltas[i]); } if (currentSecond == -1L) { currentSecond = batchStartEpochSeconds; writeToResults("time msg/sec min max avg 50% 99% 99.99% batch_time"); for (int i = 0; i < maxQueueDeltas.length; i++) { writeToResults(" q_" + i); } writeToResults("\n"); } if (batchStartEpochSeconds < currentSecond) { batchStartEpochSeconds = currentSecond; } if (batchStartEpochSeconds != currentSecond) { final long batchTimeSeconds = batchStartEpochSeconds - currentSecond; final String logMsg = String.format("%s %d %d %d %d %d %d %d %d", FORMATTER.format(LocalDateTime.ofEpochSecond(batchStartEpochSeconds, 0, ZoneOffset.UTC)), messagesInThisSecond, TimeUnit.NANOSECONDS.toMicros(minTotalLatencyInThisSecond), TimeUnit.NANOSECONDS.toMicros(maxTotalLatencyInThisSecond), TimeUnit.NANOSECONDS.toMicros(totalLatencyInThisSecond / messagesInThisSecond), TimeUnit.NANOSECONDS.toMicros((long) latencyHistogram.percentile(0.50d)), TimeUnit.NANOSECONDS.toMicros((long) latencyHistogram.percentile(0.99d)), TimeUnit.NANOSECONDS.toMicros((long) latencyHistogram.percentile(0.9999d)), batchTimeSeconds); writeToResults(logMsg); for (int i = 0; i < maxQueueDeltas.length; i++) { writeToResults(" " + TimeUnit.NANOSECONDS.toMicros(maxQueueDeltas[i])); } writeToResults("\n"); System.out.println("Worst in second"); System.out.println(FORMATTER.format(LocalDateTime.ofEpochSecond(worstCopy.batchStartMillis / 1000, 0, ZoneOffset.UTC))); System.out.println("publish to first stage"); if (worstCopy.stagesToPublishBitMask == 5) { System.out.println(TimeUnit.NANOSECONDS.toMicros(worstCopy.t0 - worstCopy.publishNanos)); } else { System.out.println(TimeUnit.NANOSECONDS.toMicros(worstCopy.t1 - worstCopy.publishNanos)); } System.out.println("first to second stage"); if (worstCopy.stagesToPublishBitMask == 5) { System.out.println(TimeUnit.NANOSECONDS.toMicros(worstCopy.t2 - worstCopy.t0)); } else { System.out.println(TimeUnit.NANOSECONDS.toMicros(worstCopy.t2 - worstCopy.t1)); } System.out.println(worstMessage); messagesInThisSecond = 0L; maxTotalLatencyInThisSecond = 0L; minTotalLatencyInThisSecond = Long.MAX_VALUE; totalLatencyInThisSecond = 0L; currentSecond = batchStartEpochSeconds; latencyHistogram.reset(); worstMessage = null; Arrays.fill(maxQueueDeltas, 0L); } messagesInThisSecond++; final long totalMessageLatency = getLatestTimestamp(message) - message.publishNanos; maxTotalLatencyInThisSecond = Math.max(maxTotalLatencyInThisSecond, totalMessageLatency); if (maxTotalLatencyInThisSecond == totalMessageLatency) { worstMessage = Marshallable.$toString(message); message.copyTo(worstCopy); } minTotalLatencyInThisSecond = Math.min(minTotalLatencyInThisSecond, totalMessageLatency); totalLatencyInThisSecond += totalMessageLatency; latencyHistogram.sampleNanos(totalMessageLatency); }