├── .github └── dependabot.yaml ├── .gitignore ├── DISCLAIMER.adoc ├── LICENSE ├── NOTICE ├── ReadMe.adoc ├── benchmark ├── README.adoc ├── pom.xml └── src │ └── main │ └── java │ └── net │ └── openhft │ └── chronicle │ └── map │ └── perf │ ├── MapJLBHTest.java │ ├── MapStress.java │ └── NonPersistedMapJLBHTest.java ├── checkstyle-suppressions.xml ├── docs ├── CM_Compatibility_and_Versioning.adoc ├── CM_Download.adoc ├── CM_FAQs.adoc ├── CM_Features.adoc ├── CM_Replication.adoc ├── CM_Tutorial.adoc ├── CM_Tutorial_Behaviour.adoc ├── CM_Tutorial_Bytes.adoc ├── CM_Tutorial_DataAccess.adoc ├── CM_Tutorial_Sized.adoc ├── CM_Tutorial_Understanding.adoc ├── CM_Updates.adoc └── images │ ├── CM_Overview.jpg │ ├── Configure_Three_Way_Replication.png │ ├── Image1_.png │ ├── Image2_.png │ ├── Map_line.png │ └── source │ ├── Image1.svg │ └── Image2.svg ├── pom.xml ├── spec ├── 1-design-goals.md ├── 2-design-overview.md ├── 3-memory-layout.md ├── 3_1-header-fields.md ├── 3_2-lock-structure.md ├── 4-hashing-algorithms.md ├── 5-initialization.md ├── 6-queries.md └── README.md ├── src ├── main │ ├── java │ │ └── net │ │ │ └── openhft │ │ │ ├── chronicle │ │ │ ├── hash │ │ │ │ ├── AbstractData.java │ │ │ │ ├── Beta.java │ │ │ │ ├── ChecksumEntry.java │ │ │ │ ├── ChronicleFileLockException.java │ │ │ │ ├── ChronicleHash.java │ │ │ │ ├── ChronicleHashBuilder.java │ │ │ │ ├── ChronicleHashBuilderPrivateAPI.java │ │ │ │ ├── ChronicleHashClosedException.java │ │ │ │ ├── ChronicleHashCorruption.java │ │ │ │ ├── ChronicleHashRecoveryFailedException.java │ │ │ │ ├── Data.java │ │ │ │ ├── ExternalHashQueryContext.java │ │ │ │ ├── HashAbsentEntry.java │ │ │ │ ├── HashContext.java │ │ │ │ ├── HashEntry.java │ │ │ │ ├── HashQueryContext.java │ │ │ │ ├── HashSegmentContext.java │ │ │ │ ├── ReplicatedHashSegmentContext.java │ │ │ │ ├── SegmentLock.java │ │ │ │ ├── VanillaGlobalMutableState.java │ │ │ │ ├── impl │ │ │ │ │ ├── BigSegmentHeader.java │ │ │ │ │ ├── ChronicleHashCloseOnExitHook.java │ │ │ │ │ ├── ChronicleHashResources.java │ │ │ │ │ ├── CompactOffHeapLinearHashTable.java │ │ │ │ │ ├── ContextHolder.java │ │ │ │ │ ├── HashSplitting.java │ │ │ │ │ ├── InMemoryChronicleHashResources.java │ │ │ │ │ ├── IntCompactOffHeapLinearHashTable.java │ │ │ │ │ ├── InternalMapFileAnalyzer.java │ │ │ │ │ ├── LocalLockState.java │ │ │ │ │ ├── LongCompactOffHeapLinearHashTable.java │ │ │ │ │ ├── MemoryResource.java │ │ │ │ │ ├── PersistedChronicleHashResources.java │ │ │ │ │ ├── SegmentHeader.java │ │ │ │ │ ├── SizePrefixedBlob.java │ │ │ │ │ ├── TierCountersArea.java │ │ │ │ │ ├── VanillaChronicleHash.java │ │ │ │ │ ├── VanillaChronicleHashHolder.java │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── stage │ │ │ │ │ │ ├── data │ │ │ │ │ │ │ └── bytes │ │ │ │ │ │ │ │ ├── EntryKeyBytesData.java │ │ │ │ │ │ │ │ └── InputKeyBytesData.java │ │ │ │ │ │ ├── entry │ │ │ │ │ │ │ ├── Alloc.java │ │ │ │ │ │ │ ├── AllocatedChunks.java │ │ │ │ │ │ │ ├── ChecksumHashing.java │ │ │ │ │ │ │ ├── ChecksumStrategy.java │ │ │ │ │ │ │ ├── HashEntryChecksumStrategy.java │ │ │ │ │ │ │ ├── HashEntryStages.java │ │ │ │ │ │ │ ├── HashLookupPos.java │ │ │ │ │ │ │ ├── HashLookupSearch.java │ │ │ │ │ │ │ ├── InputKeyHashCode.java │ │ │ │ │ │ │ ├── KeyHashCode.java │ │ │ │ │ │ │ ├── LocksInterface.java │ │ │ │ │ │ │ ├── NoChecksumStrategy.java │ │ │ │ │ │ │ ├── ReadLock.java │ │ │ │ │ │ │ ├── SegmentStages.java │ │ │ │ │ │ │ ├── UpdateLock.java │ │ │ │ │ │ │ └── WriteLock.java │ │ │ │ │ │ ├── hash │ │ │ │ │ │ │ ├── Chaining.java │ │ │ │ │ │ │ ├── ChainingInterface.java │ │ │ │ │ │ │ ├── CheckOnEachPublicOperation.java │ │ │ │ │ │ │ ├── KeyBytesInterop.java │ │ │ │ │ │ │ ├── LogHolder.java │ │ │ │ │ │ │ ├── OwnerThreadHolder.java │ │ │ │ │ │ │ └── ThreadLocalState.java │ │ │ │ │ │ ├── iter │ │ │ │ │ │ │ ├── HashSegmentIteration.java │ │ │ │ │ │ │ ├── IterationAlloc.java │ │ │ │ │ │ │ ├── IterationKeyHashCode.java │ │ │ │ │ │ │ ├── IterationSegmentStages.java │ │ │ │ │ │ │ ├── SegmentsRecovery.java │ │ │ │ │ │ │ └── TierRecovery.java │ │ │ │ │ │ ├── query │ │ │ │ │ │ │ ├── HashQuery.java │ │ │ │ │ │ │ ├── KeySearch.java │ │ │ │ │ │ │ ├── QueryAlloc.java │ │ │ │ │ │ │ ├── QueryHashLookupSearch.java │ │ │ │ │ │ │ ├── QuerySegmentStages.java │ │ │ │ │ │ │ └── SearchAllocatedChunks.java │ │ │ │ │ │ └── replication │ │ │ │ │ │ │ └── ReplicableEntryDelegating.java │ │ │ │ │ └── util │ │ │ │ │ │ ├── BuildVersion.java │ │ │ │ │ │ ├── CanonicalRandomAccessFiles.java │ │ │ │ │ │ ├── CharSequences.java │ │ │ │ │ │ ├── Cleaner.java │ │ │ │ │ │ ├── CleanerUtils.java │ │ │ │ │ │ ├── FileIOUtils.java │ │ │ │ │ │ ├── Objects.java │ │ │ │ │ │ ├── Throwables.java │ │ │ │ │ │ ├── jna │ │ │ │ │ │ └── PosixFallocate.java │ │ │ │ │ │ └── math │ │ │ │ │ │ ├── ContinuedFraction.java │ │ │ │ │ │ ├── Gamma.java │ │ │ │ │ │ ├── PoissonDistribution.java │ │ │ │ │ │ ├── Precision.java │ │ │ │ │ │ └── package-info.java │ │ │ │ ├── internal │ │ │ │ │ └── package-info.java │ │ │ │ ├── locks │ │ │ │ │ ├── InterProcessDeadLockException.java │ │ │ │ │ ├── InterProcessLock.java │ │ │ │ │ ├── InterProcessReadWriteUpdateLock.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── package-info.java │ │ │ │ ├── replication │ │ │ │ │ ├── DefaultEventualConsistencyStrategy.java │ │ │ │ │ ├── RemoteOperationContext.java │ │ │ │ │ ├── ReplicableEntry.java │ │ │ │ │ └── TimeProvider.java │ │ │ │ └── serialization │ │ │ │ │ ├── BytesReader.java │ │ │ │ │ ├── BytesWriter.java │ │ │ │ │ ├── DataAccess.java │ │ │ │ │ ├── ListMarshaller.java │ │ │ │ │ ├── MapMarshaller.java │ │ │ │ │ ├── SetMarshaller.java │ │ │ │ │ ├── SizeMarshaller.java │ │ │ │ │ ├── SizedReader.java │ │ │ │ │ ├── SizedWriter.java │ │ │ │ │ ├── StatefulCopyable.java │ │ │ │ │ ├── impl │ │ │ │ │ ├── AbstractCharSequenceUtf8DataAccess.java │ │ │ │ │ ├── BooleanMarshaller.java │ │ │ │ │ ├── ByteArrayDataAccess.java │ │ │ │ │ ├── ByteArraySizedReader.java │ │ │ │ │ ├── ByteBufferDataAccess.java │ │ │ │ │ ├── ByteBufferSizedReader.java │ │ │ │ │ ├── ByteableDataAccess.java │ │ │ │ │ ├── ByteableSizedReader.java │ │ │ │ │ ├── BytesAsSizedReader.java │ │ │ │ │ ├── BytesMarshallableDataAccess.java │ │ │ │ │ ├── BytesMarshallableReader.java │ │ │ │ │ ├── BytesMarshallableReaderWriter.java │ │ │ │ │ ├── BytesSizedMarshaller.java │ │ │ │ │ ├── CachingCreatingMarshaller.java │ │ │ │ │ ├── CharSequenceBytesReader.java │ │ │ │ │ ├── CharSequenceBytesWriter.java │ │ │ │ │ ├── CharSequenceSizedReader.java │ │ │ │ │ ├── CharSequenceUtf8DataAccess.java │ │ │ │ │ ├── CommonMarshallableReaderWriter.java │ │ │ │ │ ├── ConstantSizeMarshaller.java │ │ │ │ │ ├── DefaultElasticBytes.java │ │ │ │ │ ├── DoubleDataAccess.java │ │ │ │ │ ├── DoubleMarshaller.java │ │ │ │ │ ├── EnumMarshallable.java │ │ │ │ │ ├── ExternalBytesMarshallableDataAccess.java │ │ │ │ │ ├── ExternalizableDataAccess.java │ │ │ │ │ ├── ExternalizableReader.java │ │ │ │ │ ├── InstanceCreatingMarshaller.java │ │ │ │ │ ├── IntegerDataAccess_3_13.java │ │ │ │ │ ├── IntegerMarshaller.java │ │ │ │ │ ├── LongDataAccess.java │ │ │ │ │ ├── LongMarshaller.java │ │ │ │ │ ├── MarshallableReaderWriter.java │ │ │ │ │ ├── NotReusingSizedMarshallableDataAccess.java │ │ │ │ │ ├── SerializableDataAccess.java │ │ │ │ │ ├── SerializableReader.java │ │ │ │ │ ├── SerializationBuilder.java │ │ │ │ │ ├── SizedMarshallableDataAccess.java │ │ │ │ │ ├── StopBitSizeMarshaller.java │ │ │ │ │ ├── StringBuilderSizedReader.java │ │ │ │ │ ├── StringBuilderUtf8DataAccess.java │ │ │ │ │ ├── StringBytesReader.java │ │ │ │ │ ├── StringSizedReader.java │ │ │ │ │ ├── StringUtf8DataAccess.java │ │ │ │ │ ├── TypedMarshallableReaderWriter.java │ │ │ │ │ ├── ValueDataAccess.java │ │ │ │ │ ├── ValueReader.java │ │ │ │ │ └── package-info.java │ │ │ │ │ └── package-info.java │ │ │ ├── map │ │ │ │ ├── AbstractChronicleMap.java │ │ │ │ ├── ChronicleHashCorruptionImpl.java │ │ │ │ ├── ChronicleMap.java │ │ │ │ ├── ChronicleMapBuilder.java │ │ │ │ ├── ChronicleMapBuilderPrivateAPI.java │ │ │ │ ├── ChronicleMapEntrySet.java │ │ │ │ ├── ChronicleMapIterator.java │ │ │ │ ├── DefaultSpi.java │ │ │ │ ├── DefaultValueProvider.java │ │ │ │ ├── ExternalMapQueryContext.java │ │ │ │ ├── FindByName.java │ │ │ │ ├── JsonSerializer.java │ │ │ │ ├── MapAbsentEntry.java │ │ │ │ ├── MapClosable.java │ │ │ │ ├── MapContext.java │ │ │ │ ├── MapDiagnostics.java │ │ │ │ ├── MapEntry.java │ │ │ │ ├── MapEntryOperations.java │ │ │ │ ├── MapFileAnalyzer.java │ │ │ │ ├── MapMethods.java │ │ │ │ ├── MapMethodsSupport.java │ │ │ │ ├── MapQueryContext.java │ │ │ │ ├── MapSegmentContext.java │ │ │ │ ├── OldDeletedEntriesCleanupThread.java │ │ │ │ ├── Replica.java │ │ │ │ ├── ReplicatedChronicleMap.java │ │ │ │ ├── ReplicatedGlobalMutableStateV2.java │ │ │ │ ├── ReturnValue.java │ │ │ │ ├── SelectedSelectionKeySet.java │ │ │ │ ├── VanillaChronicleMap.java │ │ │ │ ├── WriteThroughEntry.java │ │ │ │ ├── impl │ │ │ │ │ ├── CompilationAnchor.java │ │ │ │ │ ├── CompiledMapIterationContext.java │ │ │ │ │ ├── CompiledMapQueryContext.java │ │ │ │ │ ├── CompiledReplicatedMapIterationContext.java │ │ │ │ │ ├── CompiledReplicatedMapQueryContext.java │ │ │ │ │ ├── IterationContext.java │ │ │ │ │ ├── MapIterationContext.java │ │ │ │ │ ├── MapQueryContext.java │ │ │ │ │ ├── NullReturnValue.java │ │ │ │ │ ├── QueryContextInterface.java │ │ │ │ │ ├── ReplicatedChronicleMapHolder.java │ │ │ │ │ ├── ReplicatedIterationContext.java │ │ │ │ │ ├── ReplicatedMapIterationContext.java │ │ │ │ │ ├── ReplicatedMapQueryContext.java │ │ │ │ │ ├── VanillaChronicleMapHolder.java │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── ret │ │ │ │ │ │ ├── InstanceReturnValue.java │ │ │ │ │ │ └── UsableReturnValue.java │ │ │ │ │ └── stage │ │ │ │ │ │ ├── data │ │ │ │ │ │ ├── DummyValueZeroData.java │ │ │ │ │ │ ├── ZeroBytesStore.java │ │ │ │ │ │ ├── bytes │ │ │ │ │ │ │ ├── EntryValueBytesData.java │ │ │ │ │ │ │ └── WrappedValueBytesData.java │ │ │ │ │ │ └── instance │ │ │ │ │ │ │ └── WrappedValueInstanceDataHolder.java │ │ │ │ │ │ ├── entry │ │ │ │ │ │ ├── MapEntryStages.java │ │ │ │ │ │ └── ReplicatedMapEntryStages.java │ │ │ │ │ │ ├── input │ │ │ │ │ │ └── ReplicatedInput.java │ │ │ │ │ │ ├── iter │ │ │ │ │ │ ├── IterationCheckOnEachPublicOperation.java │ │ │ │ │ │ ├── MapSegmentIteration.java │ │ │ │ │ │ ├── ReplicatedMapAbsentDelegatingForIteration.java │ │ │ │ │ │ ├── ReplicatedMapEntryDelegating.java │ │ │ │ │ │ ├── ReplicatedMapSegmentIteration.java │ │ │ │ │ │ └── ReplicatedTierRecovery.java │ │ │ │ │ │ ├── map │ │ │ │ │ │ ├── DefaultValue.java │ │ │ │ │ │ ├── MapEntryOperationsDelegation.java │ │ │ │ │ │ ├── ReplicatedChronicleMapHolderImpl.java │ │ │ │ │ │ ├── ValueBytesInterop.java │ │ │ │ │ │ ├── VanillaChronicleMapHolderImpl.java │ │ │ │ │ │ ├── WrappedValueBytesDataAccess.java │ │ │ │ │ │ └── WrappedValueInstanceDataHolderAccess.java │ │ │ │ │ │ ├── query │ │ │ │ │ │ ├── Absent.java │ │ │ │ │ │ ├── AcquireHandle.java │ │ │ │ │ │ ├── MapAbsent.java │ │ │ │ │ │ ├── MapAndSetContext.java │ │ │ │ │ │ ├── MapQuery.java │ │ │ │ │ │ ├── QueryCheckOnEachPublicOperation.java │ │ │ │ │ │ ├── ReplicatedMapAbsent.java │ │ │ │ │ │ ├── ReplicatedMapAbsentDelegating.java │ │ │ │ │ │ └── ReplicatedMapQuery.java │ │ │ │ │ │ ├── replication │ │ │ │ │ │ ├── ReplicatedQueryAlloc.java │ │ │ │ │ │ └── ReplicationUpdate.java │ │ │ │ │ │ └── ret │ │ │ │ │ │ ├── DefaultReturnValue.java │ │ │ │ │ │ └── UsingReturnValue.java │ │ │ │ ├── internal │ │ │ │ │ ├── AnalyticsHolder.java │ │ │ │ │ ├── InternalAssertUtil.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── locks │ │ │ │ │ ├── ChronicleStampedLock.java │ │ │ │ │ └── ChronicleStampedLockVOInterface.java │ │ │ │ ├── package-info.java │ │ │ │ └── replication │ │ │ │ │ ├── MapRemoteOperations.java │ │ │ │ │ ├── MapRemoteQueryContext.java │ │ │ │ │ └── MapReplicableEntry.java │ │ │ └── set │ │ │ │ ├── ChronicleSet.java │ │ │ │ ├── ChronicleSetBuilder.java │ │ │ │ ├── ChronicleSetBuilderPrivateAPI.java │ │ │ │ ├── DummyValue.java │ │ │ │ ├── DummyValueData.java │ │ │ │ ├── DummyValueMarshaller.java │ │ │ │ ├── ExternalSetQueryContext.java │ │ │ │ ├── SetAbsentEntry.java │ │ │ │ ├── SetContext.java │ │ │ │ ├── SetEntry.java │ │ │ │ ├── SetEntryOperations.java │ │ │ │ ├── SetFromMap.java │ │ │ │ ├── SetQueryContext.java │ │ │ │ ├── SetSegmentContext.java │ │ │ │ ├── internal │ │ │ │ └── package-info.java │ │ │ │ ├── package-info.java │ │ │ │ └── replication │ │ │ │ ├── SetRemoteOperations.java │ │ │ │ ├── SetRemoteQueryContext.java │ │ │ │ └── SetReplicableEntry.java │ │ │ ├── sg │ │ │ ├── Context.java │ │ │ ├── Stage.java │ │ │ ├── StageRef.java │ │ │ └── Staged.java │ │ │ └── xstream │ │ │ └── converters │ │ │ ├── AbstractChronicleMapConverter.java │ │ │ ├── ByteBufferConverter.java │ │ │ ├── CharSequenceConverter.java │ │ │ ├── StringBuilderConverter.java │ │ │ ├── ValueConverter.java │ │ │ ├── VanillaChronicleMapConverter.java │ │ │ └── internal │ │ │ └── package-info.java │ └── resources │ │ └── map.version └── test │ ├── java │ ├── eg │ │ ├── AverageValueSizeTest.java │ │ ├── BigData.java │ │ ├── OffHeapByteArrayExampleTest.java │ │ ├── TestInstrumentVOInterface.java │ │ └── WordCountTest.java │ ├── examples │ │ └── portfolio │ │ │ ├── PortfolioAssetInterface.java │ │ │ ├── PortfolioValueAccumulator.java │ │ │ └── PortfolioValueTest.java │ └── net │ │ └── openhft │ │ ├── chronicle │ │ ├── hash │ │ │ ├── impl │ │ │ │ └── util │ │ │ │ │ ├── CleanerUtilsTest.java │ │ │ │ │ └── ThrowablesTest.java │ │ │ └── serialization │ │ │ │ └── impl │ │ │ │ ├── ByteBufferDataAccessTest.java │ │ │ │ └── SerializableDataAccessTest.java │ │ ├── map │ │ │ ├── AbstractMarshallableKeyValueTest.java │ │ │ ├── AcquireGetUsingMain.java │ │ │ ├── ArrayTest.java │ │ │ ├── AutoResizeTest.java │ │ │ ├── BasicReplicationTest.java │ │ │ ├── BiMapTest.java │ │ │ ├── BitUnitTest.java │ │ │ ├── BloatFactorTest.java │ │ │ ├── BooleanValuesTest.java │ │ │ ├── BuildVersionTest.java │ │ │ ├── BytesMarshallableValueTest.java │ │ │ ├── CHMLatencyTestMain.java │ │ │ ├── CHMTestIterator1.java │ │ │ ├── CHMUseCasesTest.java │ │ │ ├── ChronicleMap3_12IntegerKeyCompatibilityTest.java │ │ │ ├── ChronicleMapEqualsTest.java │ │ │ ├── ChronicleMapImportExportTest.java │ │ │ ├── ChronicleMapNameTest.java │ │ │ ├── ChronicleMapSanityCheckTest.java │ │ │ ├── ChronicleMapTest.java │ │ │ ├── ConcurrentMap8Test.java │ │ │ ├── ConstantSizeBySampleTest.java │ │ │ ├── DataKeyValueTest.java │ │ │ ├── DatasetTrackerIssue61Test.java │ │ │ ├── DefaultValueTest.java │ │ │ ├── DeflatorStringMarshaller.java │ │ │ ├── DeletedSearchStateTest.java │ │ │ ├── DemoChronicleMapTest.java │ │ │ ├── EntryCountMapTest.java │ │ │ ├── ExitHookTest.java │ │ │ ├── FileLockUtilTest.java │ │ │ ├── ForEachSegmentTest.java │ │ │ ├── GlobalMutableStateTest.java │ │ │ ├── GuavaTest.java │ │ │ ├── HColl423Test.java │ │ │ ├── Histogram.java │ │ │ ├── HistogramTest.java │ │ │ ├── HugeSparseMapTest.java │ │ │ ├── IntValueMapTest.java │ │ │ ├── Issue110Test.java │ │ │ ├── Issue125Test.java │ │ │ ├── Issue229Test.java │ │ │ ├── Issue354Test.java │ │ │ ├── Issue354bTest.java │ │ │ ├── Issue42Test.java │ │ │ ├── Issue43Test.java │ │ │ ├── Issue58.java │ │ │ ├── Issue60Test.java │ │ │ ├── Issue62ChronicleClient.java │ │ │ ├── Issue62ChronicleServer.java │ │ │ ├── Issue63Test.java │ │ │ ├── KeySegmentDistributionTest.java │ │ │ ├── KeySizesTest.java │ │ │ ├── LargeEntriesTest.java │ │ │ ├── LargeMapMain.java │ │ │ ├── LataTest.java │ │ │ ├── ListenersTest.java │ │ │ ├── LoggingMapEntryOperations.java │ │ │ ├── LostKeyTest.java │ │ │ ├── MapCloseTest.java │ │ │ ├── MarkTest.java │ │ │ ├── MarshallableReaderWriterTest.java │ │ │ ├── MemoryLeaksTest.java │ │ │ ├── MissSizedMapsTest.java │ │ │ ├── NegativeIntegerKeyTest.java │ │ │ ├── NestedContextsInIterationContextTest.java │ │ │ ├── NestedContextsTest.java │ │ │ ├── NoUpperBoundChunksPerEntryTest.java │ │ │ ├── OSResizesMain.java │ │ │ ├── OverflowAllocationDuringIterationTest.java │ │ │ ├── PageLatencyMain.java │ │ │ ├── ProcessInstanceLimiterMain.java │ │ │ ├── RecoverTest.java │ │ │ ├── RecursiveRefereneChMapTest.java │ │ │ ├── ReplicatedChronicleMapTest.java │ │ │ ├── ReplicationCheckingMap.java │ │ │ ├── SerializableTest.java │ │ │ ├── SimplePersistedMapOverflowTest.java │ │ │ ├── TrickyContextCasesTest.java │ │ │ ├── ValueAlignmentRelocationTest.java │ │ │ ├── ValueInterfaceWithEnumTest.java │ │ │ ├── VeryLargeMapMain.java │ │ │ ├── VinceTest.java │ │ │ ├── WarnOnWindowsTest.java │ │ │ ├── WriteThroughputTest.java │ │ │ ├── example │ │ │ │ ├── DistributedSequenceMain.java │ │ │ │ ├── HashQueryContextExamples.java │ │ │ │ ├── LotsOfEntriesMain.java │ │ │ │ ├── PointListSerializationTest.java │ │ │ │ ├── SimpleMapOperationsListeningTest.java │ │ │ │ └── StringArrayExampleTest.java │ │ │ ├── externalizable │ │ │ │ ├── ExternalizableTest.java │ │ │ │ └── SomeClass.java │ │ │ ├── fromdocs │ │ │ │ ├── BondVOInterface.java │ │ │ │ ├── CharSequenceArrayBytesMarshaller.java │ │ │ │ ├── CharSequenceArraySerializationTest.java │ │ │ │ ├── CharSequenceCustomEncodingBytesReader.java │ │ │ │ ├── CharSequenceCustomEncodingBytesWriter.java │ │ │ │ ├── ChecksumEntryTest.java │ │ │ │ ├── CustomCharSequenceEncodingTest.java │ │ │ │ ├── OpenJDKAndHashMapExamplesTest.java │ │ │ │ ├── Point.java │ │ │ │ ├── PointListSizedMarshaller.java │ │ │ │ ├── PointSerializationTest.java │ │ │ │ ├── acid │ │ │ │ │ ├── ChronicleAcidIsolation.java │ │ │ │ │ ├── ChronicleAcidIsolationGovernor.java │ │ │ │ │ ├── ChronicleStampedLock.pptx │ │ │ │ │ ├── ChronicleStampedLock=WANTED.png │ │ │ │ │ ├── ReadMe.adoc │ │ │ │ │ ├── exodus │ │ │ │ │ │ ├── DirtyReadOffender.java │ │ │ │ │ │ ├── DirtyReadTolerance.java │ │ │ │ │ │ └── DirtyReadVictim.java │ │ │ │ │ ├── genesis │ │ │ │ │ │ ├── DirtyReadOffender.java │ │ │ │ │ │ ├── DirtyReadTolerance.java │ │ │ │ │ │ └── DirtyReadVictim.java │ │ │ │ │ └── revelations │ │ │ │ │ │ ├── ChronicleStampedLock.java │ │ │ │ │ │ ├── ChronicleStampedLockVOInterface.java │ │ │ │ │ │ ├── DirtyReadIntolerant.java │ │ │ │ │ │ ├── DirtyReadOffender.java │ │ │ │ │ │ ├── DirtyReadTolerance.java │ │ │ │ │ │ ├── DirtyReadVictim.java │ │ │ │ │ │ ├── DirtyReadVictimTest.java │ │ │ │ │ │ ├── Weyuker,E.pdf │ │ │ │ │ │ └── clrs=Algorithms.pdf │ │ │ │ └── pingpong_latency │ │ │ │ │ ├── PingPongAddLeft.java │ │ │ │ │ ├── PingPongAddRight.java │ │ │ │ │ ├── PingPongCASLeft.java │ │ │ │ │ ├── PingPongCASRight.java │ │ │ │ │ ├── PingPongLockLeft.java │ │ │ │ │ └── PingPongLockRight.java │ │ │ ├── ipc │ │ │ │ ├── StateMachineData.java │ │ │ │ ├── StateMachineProcessor.java │ │ │ │ ├── StateMachineState.java │ │ │ │ └── StateMachineTutorial.java │ │ │ ├── issue │ │ │ │ ├── Issue423LockFileRemainsLockedOnWindowsIfBuilderThrowsTest.java │ │ │ │ ├── ParallelStartupTest.java │ │ │ │ └── PutIfAbsentNoGarbageTest.java │ │ │ ├── jsr166 │ │ │ │ ├── JSR166TestCase.java │ │ │ │ └── map │ │ │ │ │ ├── ChronicleMapTest.java │ │ │ │ │ ├── LoopHelpers.java │ │ │ │ │ └── MapCheck.java │ │ │ ├── locks │ │ │ │ ├── BondVOInterface.java │ │ │ │ ├── DirtyReadIntolerant.java │ │ │ │ ├── DirtyReadIntolerant_ReaderReader_Test.java │ │ │ │ ├── DirtyReadOffender.java │ │ │ │ ├── DirtyReadOffenderIPCTest.java │ │ │ │ ├── DirtyReadOffenderTest.java │ │ │ │ ├── DirtyReadOffender_ReaderWriterTest.java │ │ │ │ ├── DirtyReadOffender_WriterReaderTest.java │ │ │ │ ├── DirtyReadOffender_WriterWriterTest.java │ │ │ │ ├── DirtyReadTolerance.java │ │ │ │ ├── DirtyReadVictim.java │ │ │ │ ├── DirtyReadVictimIPCTest.java │ │ │ │ ├── DirtyReadVictimTest.java │ │ │ │ ├── ReaderToo.java │ │ │ │ └── WriterToo.java │ │ │ └── utility │ │ │ │ └── ProcessInstanceLimiter.java │ │ └── set │ │ │ ├── Builder.java │ │ │ ├── ChronicleSetBuilderTest.java │ │ │ ├── Issue24ChronicleSetTest.java │ │ │ ├── Issue3Test.java │ │ │ └── SetEntryOperationsTest.java │ │ └── lang │ │ └── values │ │ ├── ArrayTest.java │ │ ├── DoubleArray.java │ │ ├── DoubleArrayTest.java │ │ ├── MovingAverageArray.java │ │ └── MovingAverageCompact.java │ └── resources │ ├── chronicle-map-3-12-no-checksums.dat │ ├── chronicle-map-3-12-with-checksums.dat │ ├── input.txt.gz │ └── war_and_peace.txt.gz └── system.properties /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | target-branch: "develop" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### How to update 2 | # This is copied from OpenHFT/.gitignore 3 | # update the original and run OpenHFT/update_gitignore.sh 4 | data/ 5 | perfmap/ 6 | 7 | ### Compiled class file 8 | *.class 9 | 10 | ### Package Files 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | ### Log file 16 | *.log 17 | 18 | ### IntelliJ 19 | *.iml 20 | *.ipr 21 | *.iws 22 | .idea 23 | compat_reports 24 | .attach_pid* 25 | 26 | ### Virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | 29 | ### Maven template 30 | target/ 31 | pom.xml.tag 32 | pom.xml.releaseBackup 33 | pom.xml.versionsBackup 34 | pom.xml.next 35 | release.properties 36 | 37 | ### Eclipse template 38 | *.pydevproject 39 | .metadata 40 | .gradle 41 | bin/ 42 | tmp/ 43 | *.tmp 44 | *.bak 45 | *.swp 46 | *~.nib 47 | local.properties 48 | .classpath 49 | .project 50 | .settings/ 51 | .loadpath 52 | 53 | ### Queue files 54 | *.cq4t 55 | *.cq4 56 | 57 | file.lock 58 | 59 | issue423 60 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Chronicle Map 2 | Copyright 2012-2018 Chronicle Map Contributors -------------------------------------------------------------------------------- /checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/images/CM_Overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/docs/images/CM_Overview.jpg -------------------------------------------------------------------------------- /docs/images/Configure_Three_Way_Replication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/docs/images/Configure_Three_Way_Replication.png -------------------------------------------------------------------------------- /docs/images/Image1_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/docs/images/Image1_.png -------------------------------------------------------------------------------- /docs/images/Image2_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/docs/images/Image2_.png -------------------------------------------------------------------------------- /docs/images/Map_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/docs/images/Map_line.png -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/Beta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * Copyright 2010 The Guava Authors 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package net.openhft.chronicle.hash; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import static java.lang.annotation.ElementType.*; 26 | 27 | /** 28 | * Signifies that a public API (public class, method or field) is subject to incompatible changes, 29 | * or even removal, in a future release. An API bearing this annotation is exempt from any 30 | * compatibility guarantees. Note that the presence of this annotation implies nothing about the 31 | * quality or performance of the API in question, only the fact that it is not "API-frozen." 32 | *

33 | * This annotation is a copy of Guava's 34 | * {@code Beta}. 35 | */ 36 | @Retention(value = RetentionPolicy.CLASS) 37 | @Target(value = {ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, TYPE}) 38 | @Documented 39 | @Beta 40 | public @interface Beta { 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/ChronicleHashClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | import net.openhft.chronicle.core.io.ClosedIllegalStateException; 20 | 21 | /** 22 | * Thrown when a {@link ChronicleHash} is accessed after {@link ChronicleHash#close()}. 23 | */ 24 | @SuppressWarnings({"rawtypes", "unchecked"}) 25 | public final class ChronicleHashClosedException extends ClosedIllegalStateException { 26 | private static final long serialVersionUID = 0L; 27 | 28 | public ChronicleHashClosedException(ChronicleHash hash) { 29 | this(hash.toIdentityString()); 30 | } 31 | 32 | public ChronicleHashClosedException(String chronicleHashIdentityString) { 33 | super("Access to " + chronicleHashIdentityString + " after close()"); 34 | } 35 | 36 | public ChronicleHashClosedException(String s, Throwable t) { 37 | super(s, t); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/ExternalHashQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | /** 20 | * {@link HashQueryContext} + {@link AutoCloseable}, for external {@link ChronicleHash} queries 21 | * in try-with-resources blocks. 22 | * 23 | * @param the hash key type 24 | * @see ChronicleHash#queryContext(Object) 25 | */ 26 | public interface ExternalHashQueryContext extends HashQueryContext, AutoCloseable { 27 | 28 | /** 29 | * Closes the query context, automatically releases all locks and disposes all resources, 30 | * acquired during the query operation. I. e. you shouldn't release locks manually in the end 31 | * of try-with-resources statement:

{@code
32 |      * try (ExternalHashQueryContext q = hash.queryContext(key))
33 |      *     q.writeLock().lock();
34 |      *     // ...make a query under exclusive lock
35 |      *     // NOT NEEDED - q.readLock().unlock();
36 |      * }}
37 | */ 38 | @Override 39 | void close(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | import net.openhft.chronicle.map.MapAbsentEntry; 20 | import net.openhft.chronicle.set.SetAbsentEntry; 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | /** 24 | * Low-level operational context for the situations, when the new entry is going to be inserted 25 | * into the {@link ChronicleHash}. 26 | *

27 | * This interface is not usable by itself; it merely defines the common base for {@link 28 | * MapAbsentEntry} and {@link SetAbsentEntry}. 29 | * 30 | * @param the hash key type 31 | * @see HashQueryContext#absentEntry() 32 | */ 33 | public interface HashAbsentEntry { 34 | 35 | /** 36 | * Returns the context, in which the entry is going to be inserted into the hash. 37 | */ 38 | HashContext context(); 39 | 40 | /** 41 | * Returns the key is going to be inserted into the {@code ChronicleHash}. 42 | */ 43 | @NotNull 44 | Data absentKey(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/HashContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | /** 20 | * Root interface for contexts, in which {@link HashEntry HashEntries} could be accessed. 21 | * 22 | * @param the key type of accessed {@link ChronicleHash} 23 | */ 24 | public interface HashContext { 25 | /** 26 | * Returns the accessed {@code ChronicleHash}. 27 | */ 28 | ChronicleHash hash(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/HashEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | import net.openhft.chronicle.map.MapEntry; 20 | import net.openhft.chronicle.set.SetEntry; 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | /** 24 | * A context of a present entry in the {@code ChronicleHash}. 25 | *

26 | * This interface is not usable by itself; it merely defines the common base for {@link MapEntry} 27 | * and {@link SetEntry}. 28 | * 29 | * @param type of the key in {@code ChronicleHash} 30 | * @see HashQueryContext#entry() 31 | */ 32 | public interface HashEntry { 33 | /** 34 | * Returns the context, in which the entry is accessed. 35 | */ 36 | HashContext context(); 37 | 38 | /** 39 | * Returns the entry key. 40 | */ 41 | @NotNull 42 | Data key(); 43 | 44 | /** 45 | * Removes the entry from the {@code ChronicleHash}. 46 | * 47 | * @throws IllegalStateException if some locking/state conditions required to perform remove 48 | * operation are not met 49 | */ 50 | void doRemove(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/ReplicatedHashSegmentContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | import net.openhft.chronicle.hash.replication.ReplicableEntry; 20 | 21 | import java.util.function.Consumer; 22 | import java.util.function.Predicate; 23 | 24 | public interface ReplicatedHashSegmentContext> 25 | extends HashSegmentContext { 26 | 27 | void forEachSegmentReplicableEntry(Consumer action); 28 | 29 | boolean forEachSegmentReplicableEntryWhile(Predicate predicate); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/SegmentLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash; 18 | 19 | import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; 20 | 21 | /** 22 | * {@link InterProcessReadWriteUpdateLock} of a segment in {@code ChronicleHash}. 23 | *

24 | * In Chronicle-Map off-heap design, locks (and concurrency) are per-segment. 25 | * 26 | * @see ChronicleHashBuilder#minSegments(int) 27 | * @see ChronicleHashBuilder#actualSegments(int) 28 | */ 29 | public interface SegmentLock extends InterProcessReadWriteUpdateLock { 30 | 31 | /** 32 | * Returns the index of the accessed segment. 33 | */ 34 | int segmentIndex(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/InMemoryChronicleHashResources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | import net.openhft.chronicle.core.OS; 20 | 21 | import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS; 22 | import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertAddress; 23 | import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertPosition; 24 | 25 | public final class InMemoryChronicleHashResources extends ChronicleHashResources { 26 | @Override 27 | void releaseMemoryResource(final MemoryResource allocation) { 28 | assert SKIP_ASSERTIONS || assertAddress(allocation.address); 29 | assert SKIP_ASSERTIONS || assertPosition(allocation.size); 30 | OS.memory().freeMemory(allocation.address, allocation.size); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/LocalLockState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | public enum LocalLockState { 20 | UNLOCKED(false, false, false), 21 | READ_LOCKED(true, false, false), 22 | UPDATE_LOCKED(true, true, false), 23 | WRITE_LOCKED(true, true, true); 24 | 25 | public final boolean read; 26 | public final boolean update; 27 | public final boolean write; 28 | 29 | LocalLockState(boolean read, boolean update, boolean write) { 30 | this.read = read; 31 | this.update = update; 32 | this.write = write; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/MemoryResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS; 20 | import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertAddress; 21 | import static net.openhft.chronicle.map.internal.InternalAssertUtil.assertPosition; 22 | 23 | final class MemoryResource { 24 | final long address; 25 | final long size; 26 | 27 | MemoryResource(final long address, final long size) { 28 | assert SKIP_ASSERTIONS || assertAddress(address); 29 | assert SKIP_ASSERTIONS || assertPosition(size); 30 | this.address = address; 31 | this.size = size; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/PersistedChronicleHashResources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | import net.openhft.chronicle.core.OS; 20 | import net.openhft.chronicle.hash.impl.util.CanonicalRandomAccessFiles; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | public final class PersistedChronicleHashResources extends ChronicleHashResources { 26 | 27 | private File file; 28 | 29 | public PersistedChronicleHashResources(File file) { 30 | this.file = file; 31 | OS.memory().storeFence(); // Emulate final semantics of the file field 32 | } 33 | 34 | @Override 35 | void releaseMemoryResource(MemoryResource mapping) throws IOException { 36 | OS.unmap(mapping.address, mapping.size); 37 | } 38 | 39 | @Override 40 | Throwable releaseExtraSystemResources() { 41 | if (file == null) 42 | return null; 43 | Throwable thrown = null; 44 | try { 45 | CanonicalRandomAccessFiles.release(file); 46 | file = null; 47 | } catch (Throwable t) { 48 | thrown = t; 49 | } 50 | return thrown; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/SizePrefixedBlob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | public final class SizePrefixedBlob { 20 | 21 | public static final int HEADER_OFFSET = 0; 22 | public static final int SIZE_WORD_OFFSET = 8; 23 | public static final int SELF_BOOTSTRAPPING_HEADER_OFFSET = 12; 24 | 25 | public static final int READY = 0; 26 | public static final int NOT_COMPLETE = 0x80000000; 27 | 28 | public static final int DATA = 0; 29 | public static final int META_DATA = 0x40000000; 30 | 31 | public static final int SIZE_MASK = (1 << 30) - 1; 32 | 33 | private SizePrefixedBlob() { 34 | } 35 | 36 | public static boolean isReady(int sizeWord) { 37 | return sizeWord > 0; 38 | } 39 | 40 | public static int extractSize(int sizeWord) { 41 | return sizeWord & SIZE_MASK; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHashHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl; 18 | 19 | import net.openhft.sg.Staged; 20 | 21 | @Staged 22 | public interface VanillaChronicleHashHolder { 23 | VanillaChronicleHash h(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.chronicle.hash.impl; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/Alloc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public interface Alloc { 20 | 21 | /** 22 | * Allocates a block of specified number of chunks in a segment tier, optionally clears the 23 | * previous allocation. 24 | * 25 | * @param chunks chunks to allocate 26 | * @param prevPos the previous position to clear, -1 if not needed 27 | * @param prevChunks the size of the previous allocation to clear, 0 if not needed 28 | * @return the new allocation position 29 | * @throws RuntimeException if fails to allocate a block 30 | */ 31 | long alloc(int chunks, long prevPos, int prevChunks); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/ChecksumHashing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public enum ChecksumHashing { 20 | ; // none 21 | 22 | /** 23 | * A smart procedure copied from CityHash/FarmHash, see the full implementation in 24 | * Zero-allocation-hashing or Chronicle-Algorithms 25 | */ 26 | public static long hash8To16Bytes(long len, long first8Bytes, long last8Bytes) { 27 | long K2 = 0x9ae16a3b2f90404fL; 28 | long mul = K2 + (len << 1); 29 | long a = first8Bytes + K2; 30 | long c = ((last8Bytes >>> 37) | (last8Bytes << 27)) * mul + a; 31 | long d = (((a >>> 25) | (a << 39)) + last8Bytes) * mul; 32 | long a1 = (c ^ d) * mul ^ ((c ^ d) * mul >>> 47); 33 | return ((d ^ a1) * mul ^ ((d ^ a1) * mul >>> 47)) * mul; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/ChecksumStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public interface ChecksumStrategy { 20 | 21 | int CHECKSUM_STORED_BYTES = 4; 22 | 23 | void computeAndStoreChecksum(); 24 | 25 | boolean innerCheckSum(); 26 | 27 | int computeChecksum(); 28 | 29 | int storedChecksum(); 30 | 31 | long extraEntryBytes(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/InputKeyHashCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | import net.openhft.chronicle.algo.hashing.LongHashFunction; 20 | import net.openhft.chronicle.hash.impl.stage.query.KeySearch; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | @SuppressWarnings({"rawtypes", "unchecked"}) 26 | public class InputKeyHashCode implements KeyHashCode { 27 | 28 | @StageRef 29 | public KeySearch ks; 30 | 31 | public long keyHash = 0; 32 | 33 | void initKeyHash() { 34 | keyHash = ks.inputKey.hash(LongHashFunction.xx_r39()); 35 | } 36 | 37 | @Override 38 | public long keyHashCode() { 39 | return keyHash; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/KeyHashCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public interface KeyHashCode { 20 | 21 | long keyHashCode(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/LocksInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public interface LocksInterface { 20 | 21 | boolean segmentHeaderInit(); 22 | 23 | long segmentHeaderAddress(); 24 | 25 | boolean locksInit(); 26 | 27 | LocksInterface rootContextLockedOnThisSegment(); 28 | 29 | void setNestedContextsLockedOnSameSegment(boolean nestedContextsLockedOnSameSegment); 30 | 31 | int latestSameThreadSegmentModCount(); 32 | 33 | int changeAndGetLatestSameThreadSegmentModCount(int change); 34 | 35 | int totalReadLockCount(); 36 | 37 | int changeAndGetTotalReadLockCount(int change); 38 | 39 | int totalUpdateLockCount(); 40 | 41 | int changeAndGetTotalUpdateLockCount(int change); 42 | 43 | int totalWriteLockCount(); 44 | 45 | int changeAndGetTotalWriteLockCount(int change); 46 | 47 | LocksInterface nextNode(); 48 | 49 | void setNextNode(LocksInterface nextNode); 50 | 51 | String debugLocksState(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/entry/NoChecksumStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.entry; 18 | 19 | public enum NoChecksumStrategy implements ChecksumStrategy { 20 | INSTANCE; 21 | 22 | @Override 23 | public void computeAndStoreChecksum() { 24 | throw new UnsupportedOperationException("Checksum is not stored in this Chronicle Hash"); 25 | } 26 | 27 | @Override 28 | public boolean innerCheckSum() { 29 | return true; 30 | } 31 | 32 | @Override 33 | public int computeChecksum() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public int storedChecksum() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public long extraEntryBytes() { 44 | return 0; // no extra bytes to store checksum 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ChainingInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.hash; 18 | 19 | import net.openhft.chronicle.map.VanillaChronicleMap; 20 | 21 | import java.util.List; 22 | import java.util.function.BiFunction; 23 | 24 | @SuppressWarnings({"rawtypes", "unchecked"}) 25 | public abstract class ChainingInterface extends ThreadLocalState { 26 | 27 | public abstract List getContextChain(); 28 | 29 | public abstract void initUsed(boolean used, VanillaChronicleMap map); 30 | 31 | public abstract boolean usedInit(); 32 | 33 | public abstract T getContext( 34 | Class contextClass, BiFunction createChaining, 35 | VanillaChronicleMap map); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/hash/KeyBytesInterop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.hash; 18 | 19 | import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; 20 | import net.openhft.chronicle.hash.serialization.SizedReader; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNeeded; 25 | 26 | @Staged 27 | public class KeyBytesInterop { 28 | 29 | @StageRef 30 | VanillaChronicleHashHolder hh; 31 | 32 | public final SizedReader keyReader = copyIfNeeded(hh.h().keyReader); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/hash/LogHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.hash; 18 | 19 | import net.openhft.sg.Staged; 20 | 21 | @Staged 22 | public class LogHolder { 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/hash/OwnerThreadHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.hash; 18 | 19 | import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; 20 | import net.openhft.sg.StageRef; 21 | import net.openhft.sg.Staged; 22 | 23 | import java.util.ConcurrentModificationException; 24 | 25 | @Staged 26 | public class OwnerThreadHolder { 27 | 28 | final Thread owner = Thread.currentThread(); 29 | @StageRef 30 | VanillaChronicleHashHolder hh; 31 | 32 | public void checkAccessingFromOwnerThread() { 33 | if (owner != Thread.currentThread()) { 34 | throw new ConcurrentModificationException(hh.h().toIdentityString() + 35 | ": Context shouldn't be accessed from multiple threads"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/iter/IterationAlloc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.iter; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.entry.Alloc; 20 | import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | public class IterationAlloc implements Alloc { 26 | 27 | @StageRef 28 | public SegmentStages s; 29 | 30 | /** 31 | * Move only to next tiers, to avoid double visiting of relocated entries during iteration 32 | */ 33 | @Override 34 | public long alloc(int chunks, long prevPos, int prevChunks) { 35 | long ret = s.allocReturnCode(chunks); 36 | if (prevPos >= 0) 37 | s.free(prevPos, prevChunks); 38 | if (ret >= 0) 39 | return ret; 40 | while (true) { 41 | s.nextTier(); 42 | ret = s.allocReturnCode(chunks); 43 | if (ret >= 0) 44 | return ret; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/iter/IterationKeyHashCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.iter; 18 | 19 | import net.openhft.chronicle.algo.hashing.LongHashFunction; 20 | import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; 21 | import net.openhft.chronicle.hash.impl.stage.entry.HashEntryStages; 22 | import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode; 23 | import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages; 24 | import net.openhft.sg.StageRef; 25 | import net.openhft.sg.Staged; 26 | 27 | @Staged 28 | public class IterationKeyHashCode implements KeyHashCode { 29 | 30 | @StageRef 31 | VanillaChronicleHashHolder hh; 32 | @StageRef 33 | SegmentStages s; 34 | @StageRef 35 | HashEntryStages e; 36 | 37 | long keyHash = 0; 38 | 39 | void initKeyHash() { 40 | long addr = s.tierBaseAddr + e.keyOffset; 41 | long len = e.keySize; 42 | keyHash = LongHashFunction.xx_r39().hashMemory(addr, len); 43 | } 44 | 45 | @Override 46 | public long keyHashCode() { 47 | return keyHash; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryAlloc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.entry.Alloc; 20 | import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | public class QueryAlloc implements Alloc { 26 | 27 | @StageRef 28 | public SegmentStages s; 29 | 30 | @Override 31 | public long alloc(int chunks, long prevPos, int prevChunks) { 32 | long ret = s.allocReturnCode(chunks); 33 | if (prevPos >= 0) 34 | s.free(prevPos, prevChunks); 35 | if (ret >= 0) 36 | return ret; 37 | int alreadyAttemptedTier = s.tier; 38 | s.goToFirstTier(); 39 | while (true) { 40 | if (s.tier != alreadyAttemptedTier) { 41 | ret = s.allocReturnCode(chunks); 42 | if (ret >= 0) 43 | return ret; 44 | } 45 | s.nextTier(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryHashLookupSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.entry.HashLookupSearch; 20 | import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | public abstract class QueryHashLookupSearch extends HashLookupSearch { 26 | 27 | @StageRef 28 | KeyHashCode h; 29 | 30 | void initSearchKey() { 31 | initSearchKey(hl().maskUnsetKey(hh.h().hashSplitting.segmentHash(h.keyHashCode()))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/query/QuerySegmentStages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode; 20 | import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | public abstract class QuerySegmentStages extends SegmentStages { 26 | 27 | @StageRef 28 | KeyHashCode h; 29 | 30 | void initSegmentIndex() { 31 | segmentIndex = hh.h().hashSplitting.segmentIndex(h.keyHashCode()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/stage/query/SearchAllocatedChunks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.entry.AllocatedChunks; 20 | import net.openhft.sg.StageRef; 21 | import net.openhft.sg.Staged; 22 | 23 | @Staged 24 | public class SearchAllocatedChunks extends AllocatedChunks { 25 | 26 | @StageRef 27 | KeySearch ks; 28 | 29 | /** 30 | * @return {@code true} if tier has changed 31 | */ 32 | public boolean initEntryAndKey(long entrySize) { 33 | initAllocatedChunks(hh.h().inChunks(entrySize)); 34 | int tierBeforeAllocation = s.tier; 35 | long pos = alloc.alloc(allocatedChunks, -1, 0); 36 | entry.writeNewEntry(pos, ks.inputKey); 37 | return s.tier != tierBeforeAllocation; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/CharSequences.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.util; 18 | 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | public final class CharSequences { 22 | 23 | private CharSequences() { 24 | } 25 | 26 | public static boolean equivalent(@NotNull CharSequence a, @NotNull CharSequence b) { 27 | if (a.equals(b)) 28 | return true; 29 | if (a instanceof String) 30 | return ((String) a).contentEquals(b); 31 | if (b instanceof String) 32 | return ((String) b).contentEquals(a); 33 | int len = a.length(); 34 | if (len != b.length()) 35 | return false; 36 | for (int i = 0; i < len; i++) { 37 | if (a.charAt(i) != b.charAt(i)) 38 | return false; 39 | } 40 | return true; 41 | } 42 | 43 | public static int hash(@NotNull CharSequence cs) { 44 | if (cs instanceof String) 45 | return cs.hashCode(); 46 | int h = 0; 47 | for (int i = 0, len = cs.length(); i < len; i++) { 48 | h = 31 * h + cs.charAt(i); 49 | } 50 | return h; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/Cleaner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.util; 18 | 19 | public interface Cleaner { 20 | 21 | void clean(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/FileIOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.util; 18 | 19 | import java.io.IOException; 20 | import java.nio.ByteBuffer; 21 | import java.nio.channels.FileChannel; 22 | 23 | public final class FileIOUtils { 24 | 25 | private FileIOUtils() { 26 | } 27 | 28 | public static void readFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer) 29 | throws IOException { 30 | int startBufferPosition = buffer.position(); 31 | while (buffer.remaining() > 0 && 32 | buffer.position() < fileChannel.size()) { 33 | int bytesRead = fileChannel.read(buffer, 34 | filePosition + buffer.position() - startBufferPosition); 35 | if (bytesRead == -1) 36 | break; 37 | } 38 | } 39 | 40 | public static void writeFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer) 41 | throws IOException { 42 | int startBufferPosition = buffer.position(); 43 | while (buffer.remaining() > 0) { 44 | fileChannel.write(buffer, filePosition + buffer.position() - startBufferPosition); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/Objects.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.util; 18 | 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | import java.util.Arrays; 23 | 24 | /** 25 | * java.util.Objects since Java 7 26 | */ 27 | public final class Objects { 28 | private Objects() { 29 | } 30 | 31 | public static int hash(Object... values) { 32 | return Arrays.hashCode(values); 33 | } 34 | 35 | public static boolean equal(@Nullable Object a, @Nullable Object b) { 36 | return a != null ? a.equals(b) : b == null; 37 | } 38 | 39 | public static boolean builderEquals(@NotNull Object builder, @Nullable Object o) { 40 | return builder == o || 41 | o != null && builder.getClass() == o.getClass() && 42 | builder.toString().equals(o.toString()); 43 | } 44 | 45 | public static void requireNonNull(Object obj) { 46 | if (obj == null) 47 | throw new NullPointerException(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/jna/PosixFallocate.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.hash.impl.util.jna; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import net.openhft.posix.PosixAPI; 5 | 6 | import java.io.FileDescriptor; 7 | import java.io.IOException; 8 | import java.lang.reflect.Field; 9 | 10 | public final class PosixFallocate { 11 | 12 | private PosixFallocate() { 13 | } 14 | 15 | public static void fallocate(FileDescriptor descriptor, long offset, long length) throws IOException { 16 | int fd = getNativeFileDescriptor(descriptor); 17 | if (fd != -1) { 18 | int ret = PosixAPI.posix().fallocate(getNativeFileDescriptor(descriptor), 0, offset, length); 19 | if (ret != 0) { 20 | throw new IOException("posix_fallocate() returned " + ret); 21 | } 22 | } 23 | } 24 | 25 | private static int getNativeFileDescriptor(FileDescriptor descriptor) throws IOException { 26 | try { 27 | final Field field = descriptor.getClass().getDeclaredField("fd"); 28 | Jvm.setAccessible(field); 29 | return (int) field.get(descriptor); 30 | } catch (final Exception e) { 31 | throw new IOException("unsupported FileDescriptor implementation", e); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/impl/util/math/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * All classes in this package are copied from Apache Commons Math 3.5 19 | * with minor simplifications, removing unused methods and replacing usages 20 | * of {@code FastMath} with vanilla {@link java.lang.Math} 21 | */ 22 | package net.openhft.chronicle.hash.impl.util.math; -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.chronicle.hash.internal; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/locks/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains abstractions of inter-process locks, used in Chronicle Map. 19 | */ 20 | package net.openhft.chronicle.hash.locks; -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains common interfaces and utilities for {@link net.openhft.chronicle.map.ChronicleMap 19 | * ChronicleMaps} ({@code net.openhft.chronicle.map} package) and 20 | * {@link net.openhft.chronicle.set.ChronicleSet ChronicleSets} 21 | * ({@code net.openhft.chronicle.set} package). This package should be the root of 22 | * {@code net.openhft.chronicle.map} and {@code net.openhft.chronicle.set} packages, moved to 23 | * the same level because {@code net.openhft.chronicle} package is occupied by Chronicle Queue project. 25 | */ 26 | package net.openhft.chronicle.hash; -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/replication/RemoteOperationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.replication; 18 | 19 | import net.openhft.chronicle.hash.ChronicleHash; 20 | import net.openhft.chronicle.hash.HashContext; 21 | 22 | /** 23 | * Context of internal replication operation. 24 | * 25 | * @param the key type of accessed {@link ChronicleHash} 26 | */ 27 | public interface RemoteOperationContext extends HashContext { 28 | 29 | /** 30 | * {@link ReplicableEntry#originIdentifier()} of the replicated entry. 31 | */ 32 | byte remoteIdentifier(); 33 | 34 | /** 35 | * {@link ReplicableEntry#originTimestamp()} of the replicated entry. 36 | */ 37 | long remoteTimestamp(); 38 | 39 | /** 40 | * Returns the identifier of the current Chronicle Node (this context object is obtained on). 41 | */ 42 | byte currentNodeIdentifier(); 43 | 44 | /** 45 | * Returns the identifier of the node, from which current replication event came from, or -1 if 46 | * unknown or not applicable (the current replication event came not from another node, but, 47 | * e. g., applied manually). 48 | */ 49 | byte remoteNodeIdentifier(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/ByteableSizedReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.bytes.Byteable; 20 | import net.openhft.chronicle.bytes.Bytes; 21 | import net.openhft.chronicle.hash.serialization.SizedReader; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.jetbrains.annotations.Nullable; 24 | 25 | /** 26 | * Reader of {@link Byteable} subclasses. 27 | * 28 | * @param the subtype of {@link Byteable} deserialized 29 | */ 30 | public class ByteableSizedReader extends InstanceCreatingMarshaller 31 | implements SizedReader { 32 | 33 | public ByteableSizedReader(Class tClass) { 34 | super(tClass); 35 | } 36 | 37 | @NotNull 38 | @Override 39 | public final T read(@NotNull Bytes in, long size, @Nullable T using) { 40 | if (using == null) 41 | using = createInstance(); 42 | using.bytesStore(in.bytesStore(), in.readPosition(), size); 43 | return using; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/BytesMarshallableReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.bytes.Bytes; 20 | import net.openhft.chronicle.bytes.BytesMarshallable; 21 | import net.openhft.chronicle.hash.serialization.BytesReader; 22 | import net.openhft.chronicle.hash.serialization.SizedReader; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | public class BytesMarshallableReader 27 | extends InstanceCreatingMarshaller implements SizedReader, BytesReader { 28 | 29 | public BytesMarshallableReader(Class tClass) { 30 | super(tClass); 31 | } 32 | 33 | @NotNull 34 | @Override 35 | public T read(@NotNull Bytes in, long size, @Nullable T using) { 36 | return read(in, using); 37 | } 38 | 39 | @NotNull 40 | @Override 41 | public T read(Bytes in, @Nullable T using) { 42 | if (using == null) 43 | using = createInstance(); 44 | using.readMarshallable(in); 45 | return using; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/BytesMarshallableReaderWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.hash.serialization.impl; 6 | 7 | import net.openhft.chronicle.bytes.Bytes; 8 | import net.openhft.chronicle.bytes.BytesMarshallable; 9 | import net.openhft.chronicle.bytes.VanillaBytes; 10 | import net.openhft.chronicle.wire.Wire; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | @SuppressWarnings({"rawtypes", "unchecked"}) 15 | public class BytesMarshallableReaderWriter 16 | extends CachingCreatingMarshaller { 17 | private static final ThreadLocal VANILLA_BYTES_TL = ThreadLocal.withInitial(VanillaBytes::vanillaBytes); 18 | 19 | public BytesMarshallableReaderWriter(Class vClass) { 20 | super(vClass); 21 | } 22 | 23 | @NotNull 24 | @Override 25 | public V read(Bytes in, long size, @Nullable V using) { 26 | if (using == null) 27 | using = createInstance(); 28 | 29 | VanillaBytes vanillaBytes = VANILLA_BYTES_TL.get(); 30 | vanillaBytes.bytesStore(in.bytesStore(), in.readPosition(), size); 31 | using.readMarshallable(vanillaBytes); 32 | return using; 33 | } 34 | 35 | @Override 36 | protected void writeToWire(Wire wire, @NotNull V toWrite) { 37 | toWrite.writeMarshallable(wire.bytes()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/BytesSizedMarshaller.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.hash.serialization.impl; 2 | 3 | import net.openhft.chronicle.bytes.Bytes; 4 | import net.openhft.chronicle.core.Maths; 5 | import net.openhft.chronicle.hash.serialization.SizedReader; 6 | import net.openhft.chronicle.hash.serialization.SizedWriter; 7 | 8 | public class BytesSizedMarshaller implements SizedReader>, SizedWriter> { 9 | @Override 10 | public Bytes read(Bytes in, long size, Bytes using) { 11 | final int size0 = Maths.toInt32(size); 12 | if (using == null) 13 | using = Bytes.allocateElasticOnHeap(size0); 14 | 15 | in.read(using, size0); 16 | return using; 17 | } 18 | 19 | @Override 20 | public long size(Bytes toWrite) { 21 | return toWrite.readRemaining(); 22 | } 23 | 24 | @Override 25 | public void write(Bytes out, long size, Bytes toWrite) { 26 | out.write(toWrite, toWrite.readPosition(), size); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/CachingCreatingMarshaller.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.hash.serialization.impl; 2 | 3 | import net.openhft.chronicle.bytes.Bytes; 4 | import net.openhft.chronicle.hash.serialization.SizedReader; 5 | import net.openhft.chronicle.hash.serialization.SizedWriter; 6 | import net.openhft.chronicle.wire.*; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | public abstract class CachingCreatingMarshaller 10 | extends InstanceCreatingMarshaller 11 | implements SizedReader, SizedWriter { 12 | 13 | static final ThreadLocal WIRE_TL = ThreadLocal.withInitial( 14 | () -> WireType.BINARY_LIGHT.apply(Bytes.allocateElasticOnHeap(128))); 15 | static final ThreadLocal LAST_TL = new ThreadLocal<>(); 16 | 17 | public CachingCreatingMarshaller(Class vClass) { 18 | super(vClass); 19 | } 20 | 21 | @Override 22 | public long size(@NotNull V toWrite) { 23 | Wire wire = WIRE_TL.get(); 24 | wire.bytes().clear(); 25 | writeToWire(wire, toWrite); 26 | LAST_TL.set(toWrite); 27 | return wire.bytes().readRemaining(); 28 | } 29 | 30 | protected abstract void writeToWire(Wire wire, @NotNull V toWrite); 31 | 32 | @Override 33 | public void write(Bytes out, long size, @NotNull V toWrite) { 34 | if (LAST_TL.get() == toWrite) { 35 | Wire wire = WIRE_TL.get(); 36 | if (wire.bytes().readRemaining() == size) { 37 | out.write(wire.bytes()); 38 | wire.bytes().clear(); 39 | LAST_TL.remove(); 40 | return; 41 | } 42 | } 43 | BinaryWire wire = Wires.binaryWireForWrite(out, out.writePosition(), size); 44 | writeToWire(wire, toWrite); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceUtf8DataAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.hash.serialization.DataAccess; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | public final class CharSequenceUtf8DataAccess 23 | extends AbstractCharSequenceUtf8DataAccess { 24 | 25 | public CharSequenceUtf8DataAccess() { 26 | this(DefaultElasticBytes.DEFAULT_BYTES_CAPACITY); 27 | } 28 | 29 | private CharSequenceUtf8DataAccess(long bytesCapacity) { 30 | super(bytesCapacity); 31 | } 32 | 33 | @Override 34 | public CharSequence getUsing(@Nullable CharSequence using) { 35 | StringBuilder sb; 36 | if (using instanceof StringBuilder) { 37 | sb = (StringBuilder) using; 38 | sb.setLength(0); 39 | } else { 40 | sb = new StringBuilder(cs.length()); 41 | } 42 | sb.append(cs); 43 | return sb; 44 | } 45 | 46 | @Override 47 | public DataAccess copy() { 48 | return new CharSequenceUtf8DataAccess(bytes().realCapacity()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/DefaultElasticBytes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.bytes.Bytes; 20 | 21 | final class DefaultElasticBytes { 22 | 23 | static final int DEFAULT_BYTES_CAPACITY = 32; 24 | 25 | private DefaultElasticBytes() { 26 | } 27 | 28 | static Bytes allocateDefaultElasticBytes(long bytesCapacity) { 29 | if (bytesCapacity <= 0x7FFFFFF0) { 30 | return Bytes.elasticHeapByteBuffer((int) bytesCapacity); 31 | } else { 32 | return Bytes.allocateElasticDirect(bytesCapacity); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/MarshallableReaderWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.hash.serialization.impl; 6 | 7 | import net.openhft.chronicle.bytes.Bytes; 8 | import net.openhft.chronicle.wire.Marshallable; 9 | import net.openhft.chronicle.wire.Wire; 10 | import net.openhft.chronicle.wire.Wires; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | public class MarshallableReaderWriter 15 | extends CachingCreatingMarshaller { 16 | public MarshallableReaderWriter(Class vClass) { 17 | super(vClass); 18 | } 19 | 20 | @NotNull 21 | @Override 22 | public V read(Bytes in, long size, @Nullable V using) { 23 | if (using == null) 24 | using = createInstance(); 25 | 26 | using.readMarshallable(Wires.binaryWireForRead(in, in.readPosition(), size)); 27 | return using; 28 | } 29 | 30 | @Override 31 | protected void writeToWire(Wire wire, @NotNull V toWrite) { 32 | toWrite.writeMarshallable(wire); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/StringBuilderUtf8DataAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.hash.serialization.DataAccess; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | import static net.openhft.chronicle.hash.serialization.impl.DefaultElasticBytes.DEFAULT_BYTES_CAPACITY; 23 | 24 | public final class StringBuilderUtf8DataAccess 25 | extends AbstractCharSequenceUtf8DataAccess { 26 | 27 | public StringBuilderUtf8DataAccess() { 28 | this(DEFAULT_BYTES_CAPACITY); 29 | } 30 | 31 | private StringBuilderUtf8DataAccess(long bytesCapacity) { 32 | super(bytesCapacity); 33 | } 34 | 35 | @Override 36 | public StringBuilder getUsing(@Nullable StringBuilder using) { 37 | if (using != null) { 38 | using.setLength(0); 39 | } else { 40 | using = new StringBuilder(cs.length()); 41 | } 42 | using.append(cs); 43 | return using; 44 | } 45 | 46 | @Override 47 | public DataAccess copy() { 48 | return new StringBuilderUtf8DataAccess(bytes().realCapacity()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/StringUtf8DataAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.serialization.impl; 18 | 19 | import net.openhft.chronicle.hash.serialization.DataAccess; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | public final class StringUtf8DataAccess extends AbstractCharSequenceUtf8DataAccess { 23 | 24 | public StringUtf8DataAccess() { 25 | this(DefaultElasticBytes.DEFAULT_BYTES_CAPACITY); 26 | } 27 | 28 | private StringUtf8DataAccess(long bytesCapacity) { 29 | super(bytesCapacity); 30 | } 31 | 32 | @Override 33 | public String getUsing(@Nullable String using) { 34 | return cs; 35 | } 36 | 37 | @Override 38 | public DataAccess copy() { 39 | return new StringUtf8DataAccess(bytes().realCapacity()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/hash/serialization/impl/TypedMarshallableReaderWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.hash.serialization.impl; 6 | 7 | import net.openhft.chronicle.bytes.Bytes; 8 | import net.openhft.chronicle.wire.BinaryWire; 9 | import net.openhft.chronicle.wire.Marshallable; 10 | import net.openhft.chronicle.wire.Wire; 11 | import net.openhft.chronicle.wire.Wires; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | @SuppressWarnings({"rawtypes", "unchecked"}) 16 | public class TypedMarshallableReaderWriter 17 | extends CachingCreatingMarshaller { 18 | 19 | public TypedMarshallableReaderWriter(Class vClass) { 20 | super(vClass); 21 | } 22 | 23 | @NotNull 24 | @Override 25 | public V read(Bytes in, long size, @Nullable V using) { 26 | BinaryWire wire = Wires.binaryWireForRead(in, in.readPosition(), size); 27 | return wire.getValueIn().object(using, tClass()); 28 | } 29 | 30 | protected void writeToWire(Wire wire, @NotNull V toWrite) { 31 | wire.getValueOut().object(toWrite); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/DefaultSpi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import net.openhft.chronicle.map.replication.MapRemoteOperations; 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | @SuppressWarnings({"rawtypes", "unchecked"}) 24 | final class DefaultSpi implements MapMethods, MapEntryOperations, MapRemoteOperations, 25 | DefaultValueProvider { 26 | static final DefaultSpi DEFAULT_SPI = new DefaultSpi(); 27 | 28 | static MapMethods mapMethods() { 29 | return DEFAULT_SPI; 30 | } 31 | 32 | static MapEntryOperations mapEntryOperations() { 33 | return DEFAULT_SPI; 34 | } 35 | 36 | static MapRemoteOperations mapRemoteOperations() { 37 | return DEFAULT_SPI; 38 | } 39 | 40 | static DefaultValueProvider defaultValueProvider() { 41 | return DEFAULT_SPI; 42 | } 43 | 44 | @Override 45 | public Data defaultValue(@NotNull MapAbsentEntry absentEntry) { 46 | return absentEntry.defaultValue(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/DefaultValueProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import org.jetbrains.annotations.NotNull; 21 | 22 | /** 23 | * Default value computation strategy, used 24 | * in {@link ChronicleMapBuilder#defaultValueProvider(DefaultValueProvider)} configuration. 25 | * 26 | * @param map key class 27 | * @param map value class 28 | */ 29 | @FunctionalInterface 30 | public interface DefaultValueProvider { 31 | 32 | /** 33 | * Returns the "nil" value, which should be inserted into the map, in the given 34 | * {@code absentEntry} context. This is primarily used in {@link ChronicleMap#acquireUsing} 35 | * operation implementation, i. e. {@link MapMethods#acquireUsing}. 36 | *

37 | * The default implementation simply delegates to {@link MapAbsentEntry#defaultValue()}. 38 | */ 39 | Data defaultValue(@NotNull MapAbsentEntry absentEntry); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/ExternalMapQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.ExternalHashQueryContext; 20 | 21 | /** 22 | * {@link MapQueryContext} + {@link AutoCloseable}, for external {@link ChronicleMap} queries 23 | * in try-with-resources blocks. 24 | * 25 | * @param the map key type 26 | * @param the map value type 27 | * @param the return type of {@link MapEntryOperations}, {@link 28 | * ChronicleMapBuilder#entryOperations(MapEntryOperations) specified} for the queried {@code 29 | * ChronicleMap} 30 | * @see ChronicleMap#queryContext(Object) 31 | */ 32 | public interface ExternalMapQueryContext 33 | extends MapQueryContext, ExternalHashQueryContext { 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/FindByName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.ChronicleHash; 20 | 21 | import java.io.IOException; 22 | import java.util.concurrent.TimeoutException; 23 | 24 | /** 25 | * @author Rob Austin. 26 | */ 27 | @SuppressWarnings({"rawtypes", "unchecked"}) 28 | interface FindByName { 29 | 30 | /** 31 | * @param name the name of the map or set 32 | * @param the type returned 33 | * @return a chronicle map or set 34 | * @throws IllegalArgumentException if a map with this name can not be found 35 | * @throws IOException if it not possible to create the map or set 36 | * @throws TimeoutException if the call times out 37 | * @throws InterruptedException if interrupted by another thread 38 | */ 39 | T from(String name) throws IllegalArgumentException, 40 | IOException, TimeoutException, InterruptedException; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapClosable.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.core.io.ManagedCloseable; 4 | 5 | public interface MapClosable extends ManagedCloseable { 6 | 7 | @Override 8 | default boolean isClosed() { 9 | // if we don't know, pretend it is not. 10 | return false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapDiagnostics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | 22 | @SuppressWarnings({"rawtypes", "unchecked"}) 23 | public final class MapDiagnostics { 24 | 25 | private MapDiagnostics() { 26 | } 27 | 28 | public static void main(String[] args) throws IOException { 29 | String mapFile = args[0]; 30 | try (ChronicleMap map = ChronicleMap.of(Object.class, Object.class) 31 | .createPersistedTo(new File(mapFile))) { 32 | printMapStats(map); 33 | } 34 | } 35 | 36 | public static void printMapStats(ChronicleMap map) { 37 | for (int i = 0; i < map.segments(); i++) { 38 | try (MapSegmentContext c = map.segmentContext(i)) { 39 | System.out.printf("segment %d contains %d entries\n", i, c.size()); 40 | c.forEachSegmentEntry(e -> System.out.printf("%s, %d bytes -> %s, %d bytes\n", 41 | e.key(), e.key().size(), e.value(), e.value().size())); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapFileAnalyzer.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.hash.impl.InternalMapFileAnalyzer; 4 | 5 | import java.io.IOException; 6 | 7 | public final class MapFileAnalyzer { 8 | 9 | public static void main(String[] args) throws IOException { 10 | InternalMapFileAnalyzer.main(args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapMethodsSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | final class MapMethodsSupport { 20 | 21 | private MapMethodsSupport() { 22 | } 23 | 24 | static void returnCurrentValueIfPresent( 25 | MapQueryContext q, ReturnValue returnValue) { 26 | MapEntry entry = q.entry(); 27 | if (entry != null) 28 | returnValue.returnValue(entry.value()); 29 | } 30 | 31 | static boolean tryReturnCurrentValueIfPresent( 32 | MapQueryContext q, ReturnValue returnValue) { 33 | if (q.readLock().tryLock()) { 34 | MapEntry entry = q.entry(); 35 | if (entry != null) { 36 | returnValue.returnValue(entry.value()); 37 | return true; 38 | } 39 | // Key is absent 40 | q.readLock().unlock(); 41 | } 42 | q.updateLock().lock(); 43 | MapEntry entry = q.entry(); 44 | if (entry != null) { 45 | returnValue.returnValue(entry.value()); 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.HashQueryContext; 20 | import net.openhft.chronicle.map.replication.MapRemoteOperations; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | /** 24 | * A context of {@link ChronicleMap} operations with individual keys 25 | * (like during {@code get()}, {@code put()}, etc., opposed to bulk operations). 26 | * This is the main context type of {@link MapMethods} and {@link MapRemoteOperations}. 27 | * 28 | * @param the map key type 29 | * @param the map value type 30 | * @param the return type of {@link MapEntryOperations} specialized for the queried map 31 | * @see ChronicleMap#queryContext(Object) 32 | */ 33 | public interface MapQueryContext extends HashQueryContext, MapContext { 34 | 35 | @Override 36 | @Nullable 37 | MapEntry entry(); 38 | 39 | @Override 40 | @Nullable 41 | MapAbsentEntry absentEntry(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/MapSegmentContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.HashSegmentContext; 20 | 21 | /** 22 | * Context of {@link ChronicleMap}'s segment. 23 | * 24 | * @param the key type of accessed {@code ChronicleMap} 25 | * @param the value type of accessed {@code ChronicleMap} 26 | * @param the return type of {@link MapEntryOperations} specified for the queried map 27 | * @see ChronicleMap#segmentContext(int) 28 | */ 29 | public interface MapSegmentContext 30 | extends HashSegmentContext>, MapContext { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/ReplicatedGlobalMutableStateV2.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.hash.VanillaGlobalMutableState; 4 | import net.openhft.chronicle.values.*; 5 | 6 | /** 7 | * Extends segment headers offset from int to long - it may be greater than 4GB for large data stores. 8 | */ 9 | public interface ReplicatedGlobalMutableStateV2 extends VanillaGlobalMutableState { 10 | 11 | static void main(String[] args) { 12 | System.setProperty("chronicle.values.dumpCode", "true"); 13 | Values.nativeClassFor(ReplicatedGlobalMutableStateV2.class); 14 | } 15 | 16 | @Group(6) 17 | int getCurrentCleanupSegmentIndex(); 18 | 19 | void setCurrentCleanupSegmentIndex( 20 | @Range(min = 0, max = Integer.MAX_VALUE) int currentCleanupSegmentIndex); 21 | 22 | @Group(7) 23 | @Align(offset = 1) 24 | int getModificationIteratorsCount(); 25 | 26 | int addModificationIteratorsCount(@Range(min = 0, max = 128) int addition); 27 | 28 | @Group(8) 29 | // Align to prohibit array filling the highest bit of the previous 2-byte block, that 30 | // complicates generated code for all fields, defined in this interface. 31 | @Align(offset = 2) 32 | @Array(length = 128) 33 | boolean getModificationIteratorInitAt(int index); 34 | 35 | void setModificationIteratorInitAt(int index, boolean init); 36 | 37 | @Group(9) 38 | long getSegmentHeadersOffset(); 39 | 40 | void setSegmentHeadersOffset(@Range(min = 0/*, max = 9223372036854775807L*/) long segmentHeadersOffset); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/WriteThroughEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import java.util.AbstractMap; 20 | 21 | @SuppressWarnings("serial") 22 | class WriteThroughEntry extends AbstractMap.SimpleEntry { 23 | private static final long serialVersionUID = 0L; 24 | 25 | private final ChronicleMap map; 26 | 27 | public WriteThroughEntry(ChronicleMap map, K key, V value) { 28 | super(key, value); 29 | this.map = map; 30 | } 31 | 32 | @Override 33 | public V setValue(V value) { 34 | map.put(getKey(), value); 35 | return super.setValue(value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/CompilationAnchor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.sg.Staged; 20 | 21 | @Staged 22 | public class CompilationAnchor { 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/IterationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.chronicle.hash.ChronicleHashCorruption; 20 | import net.openhft.chronicle.map.ChronicleHashCorruptionImpl; 21 | import net.openhft.chronicle.map.MapEntry; 22 | import net.openhft.chronicle.map.MapSegmentContext; 23 | 24 | public interface IterationContext extends MapEntry, MapSegmentContext { 25 | long pos(); 26 | 27 | void initSegmentIndex(int segmentIndex); 28 | 29 | void recoverSegments( 30 | ChronicleHashCorruption.Listener corruptionListener, 31 | ChronicleHashCorruptionImpl corruption); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/NullReturnValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | public final class NullReturnValue implements InstanceReturnValue { 24 | 25 | private static final NullReturnValue NULL_RETURN_VALUE = new NullReturnValue<>(); 26 | 27 | private NullReturnValue() { 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | public static InstanceReturnValue get() { 32 | return (InstanceReturnValue) NULL_RETURN_VALUE; 33 | } 34 | 35 | @Override 36 | public V returnValue() { 37 | return null; 38 | } 39 | 40 | @Override 41 | public void returnValue(@NotNull Data value) { 42 | // ignore 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.chronicle.bytes.BytesStore; 20 | import net.openhft.chronicle.hash.Data; 21 | import net.openhft.chronicle.hash.serialization.DataAccess; 22 | import net.openhft.chronicle.map.ExternalMapQueryContext; 23 | import net.openhft.chronicle.map.MapClosable; 24 | import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; 25 | import net.openhft.chronicle.map.impl.ret.UsableReturnValue; 26 | 27 | public interface QueryContextInterface extends ExternalMapQueryContext { 28 | 29 | void initInputKey(Data inputKey); 30 | 31 | Data getInputKeyBytesAsData(BytesStore bytesStore, long offset, long size); 32 | 33 | DataAccess inputKeyDataAccess(); 34 | 35 | InstanceReturnValue defaultReturnValue(); 36 | 37 | UsableReturnValue usingReturnValue(); 38 | 39 | DataAccess inputValueDataAccess(); 40 | 41 | MapClosable acquireHandle(); 42 | 43 | void initSegmentIndex(int segmentIndex); 44 | 45 | boolean segmentIndexInit(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/ReplicatedChronicleMapHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.chronicle.map.ReplicatedChronicleMap; 20 | import net.openhft.sg.Staged; 21 | 22 | @Staged 23 | public interface ReplicatedChronicleMapHolder extends VanillaChronicleMapHolder { 24 | 25 | @Override 26 | ReplicatedChronicleMap m(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/ReplicatedIterationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | public interface ReplicatedIterationContext extends IterationContext { 20 | 21 | void readExistingEntry(long pos); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/VanillaChronicleMapHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl; 18 | 19 | import net.openhft.chronicle.hash.impl.VanillaChronicleHash; 20 | import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; 21 | import net.openhft.chronicle.map.ChronicleMap; 22 | import net.openhft.chronicle.map.VanillaChronicleMap; 23 | import net.openhft.chronicle.set.ChronicleSet; 24 | import net.openhft.sg.Staged; 25 | 26 | @Staged 27 | public interface VanillaChronicleMapHolder extends VanillaChronicleHashHolder { 28 | 29 | VanillaChronicleMap m(); 30 | 31 | @Override 32 | VanillaChronicleHash h(); 33 | 34 | ChronicleMap map(); 35 | 36 | ChronicleSet set(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

    8 | *
  • Casting to
  • 9 | *
  • Reflection of any kind
  • 10 | *
  • Explicit Serialize/deserialize
  • 11 | *
12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.chronicle.map.impl; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/ret/InstanceReturnValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.ret; 18 | 19 | import net.openhft.chronicle.map.ReturnValue; 20 | 21 | public interface InstanceReturnValue extends ReturnValue { 22 | V returnValue(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/ret/UsableReturnValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.ret; 18 | 19 | public interface UsableReturnValue extends InstanceReturnValue { 20 | Object USING_RETURN_VALUE_UNINIT = new Object(); 21 | 22 | void initUsingReturnValue(V usingValue); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/iter/IterationCheckOnEachPublicOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.iter; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; 20 | import net.openhft.sg.StageRef; 21 | import net.openhft.sg.Staged; 22 | 23 | @Staged 24 | public class IterationCheckOnEachPublicOperation extends CheckOnEachPublicOperation { 25 | 26 | @StageRef 27 | MapSegmentIteration iteration; 28 | 29 | @Override 30 | public void checkOnEachPublicOperation() { 31 | super.checkOnEachPublicOperation(); 32 | iteration.checkEntryNotRemovedOnThisIteration(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/map/DefaultValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.map; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; 21 | import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData; 22 | import net.openhft.sg.StageRef; 23 | import net.openhft.sg.Staged; 24 | import org.jetbrains.annotations.NotNull; 25 | 26 | @Staged 27 | public abstract class DefaultValue { 28 | 29 | @StageRef 30 | CheckOnEachPublicOperation checkOnEachPublicOperation; 31 | @StageRef 32 | DummyValueZeroData zeroValueData; 33 | 34 | @NotNull 35 | public Data defaultValue() { 36 | checkOnEachPublicOperation.checkOnEachPublicOperation(); 37 | return zeroValueData; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/map/ValueBytesInterop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.map; 18 | 19 | import net.openhft.chronicle.hash.serialization.SizedReader; 20 | import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNeeded; 25 | 26 | @Staged 27 | public class ValueBytesInterop { 28 | 29 | @StageRef 30 | VanillaChronicleMapHolder mh; 31 | 32 | public final SizedReader valueReader = copyIfNeeded(mh.m().valueReader); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/query/Absent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.query; 18 | 19 | import net.openhft.chronicle.map.MapAbsentEntry; 20 | import net.openhft.chronicle.set.SetAbsentEntry; 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | public interface Absent extends MapAbsentEntry, SetAbsentEntry { 24 | 25 | @NotNull 26 | @Override 27 | MapAndSetContext context(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/query/AcquireHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; 20 | import net.openhft.chronicle.map.MapClosable; 21 | import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue; 22 | import net.openhft.sg.StageRef; 23 | import net.openhft.sg.Staged; 24 | 25 | @Staged 26 | public class AcquireHandle implements MapClosable { 27 | 28 | @StageRef 29 | CheckOnEachPublicOperation checkOnEachPublicOperation; 30 | @StageRef 31 | MapQuery q; 32 | @StageRef 33 | UsingReturnValue usingReturn; 34 | 35 | @Override 36 | public void close() { 37 | checkOnEachPublicOperation.checkOnEachPublicOperation(); 38 | q.replaceValue(q.entry(), q.wrapValueAsData(usingReturn.returnValue())); 39 | q.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/query/MapAndSetContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.query; 18 | 19 | import net.openhft.chronicle.map.MapContext; 20 | import net.openhft.chronicle.set.SetContext; 21 | 22 | public interface MapAndSetContext extends MapContext, SetContext { 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/query/QueryCheckOnEachPublicOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.query; 18 | 19 | import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; 20 | import net.openhft.chronicle.hash.impl.stage.query.HashQuery; 21 | import net.openhft.sg.StageRef; 22 | import net.openhft.sg.Staged; 23 | 24 | @Staged 25 | @SuppressWarnings({"rawtypes", "unchecked"}) 26 | public class QueryCheckOnEachPublicOperation extends CheckOnEachPublicOperation { 27 | 28 | @StageRef 29 | HashQuery q; 30 | 31 | @Override 32 | public void checkOnEachPublicOperation() { 33 | super.checkOnEachPublicOperation(); 34 | q.dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/impl/stage/ret/DefaultReturnValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.impl.stage.ret; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; 21 | import net.openhft.sg.Staged; 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | @Staged 25 | public abstract class DefaultReturnValue implements InstanceReturnValue { 26 | private V defaultReturnedValue = null; 27 | 28 | abstract boolean defaultReturnedValueInit(); 29 | 30 | private void initDefaultReturnedValue(@NotNull Data value) { 31 | defaultReturnedValue = value.getUsing(null); 32 | } 33 | 34 | @Override 35 | public void returnValue(@NotNull Data value) { 36 | initDefaultReturnedValue(value); 37 | } 38 | 39 | @Override 40 | public V returnValue() { 41 | if (defaultReturnedValueInit()) { 42 | return defaultReturnedValue; 43 | } else { 44 | return null; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/internal/AnalyticsHolder.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.internal; 2 | 3 | import net.openhft.chronicle.core.analytics.AnalyticsFacade; 4 | import net.openhft.chronicle.core.pom.PomProperties; 5 | 6 | public enum AnalyticsHolder { 7 | ; // none 8 | 9 | // Todo: VERSION is "unknown" for some reason 10 | private static final String VERSION = PomProperties.version("net.openhft", "chronicle-map"); 11 | 12 | private static final AnalyticsFacade ANALYTICS = AnalyticsFacade.standardBuilder("G-TDTJG5CT6G", "J8qsWGHgQP6CLs43mQ10KQ", VERSION) 13 | //.withReportDespiteJUnit() 14 | .withDebugLogger(System.out::println) 15 | //.withUrl("https://www.google-analytics.com/debug/mp/collect") 16 | .build(); 17 | 18 | public static AnalyticsFacade instance() { 19 | return ANALYTICS; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/internal/InternalAssertUtil.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.internal; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | 5 | public final class InternalAssertUtil { 6 | 7 | private static final boolean IS_64_BIT = Jvm.is64bit(); 8 | 9 | // Suppresses default constructor, ensuring non-instantiability. 10 | private InternalAssertUtil() { 11 | } 12 | 13 | public static boolean assertAddress(final long address) { 14 | if (Jvm.is64bit()) { 15 | // It is highly unlikely that we would ever address farther than 2^63 16 | assert address > 0 : "address is non positive: " + address; 17 | } else { 18 | // These memory addresses are illegal on a 32-bit machine 19 | assert address != 0 && address != -1 : "address is illegal: " + address; 20 | } 21 | return true; 22 | } 23 | 24 | public static boolean assertPosition(final long position) { 25 | assert position >= 0 : "position is negative: " + position; 26 | return true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

    8 | *
  • Casting to
  • 9 | *
  • Reflection of any kind
  • 10 | *
  • Explicit Serialize/deserialize
  • 11 | *
12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.chronicle.map.internal; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/locks/ChronicleStampedLockVOInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.locks; 18 | 19 | import net.openhft.chronicle.values.Group; 20 | 21 | interface ChronicleStampedLockVOInterface { 22 | 23 | @Group(0) 24 | long getEntryLockState(); 25 | 26 | void setEntryLockState(long entryLockState); 27 | // 28 | // @Group(1) 29 | // long getReaderCount(); 30 | // 31 | // void setReaderCount(long rc); /* time in millis */ 32 | // 33 | // long addAtomicReaderCount(long toAdd); 34 | // 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains {@link net.openhft.chronicle.map.ChronicleMap} interface, {@code ChronicleMap} context 19 | * interfaces, {@link net.openhft.chronicle.map.ChronicleMapBuilder} class and related stuff. 20 | */ 21 | package net.openhft.chronicle.map; -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/map/replication/MapReplicableEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.replication; 18 | 19 | import net.openhft.chronicle.hash.replication.ReplicableEntry; 20 | import net.openhft.chronicle.map.ChronicleMap; 21 | import net.openhft.chronicle.map.MapEntry; 22 | 23 | /** 24 | * A context of a present entry in the replicated {@link ChronicleMap}. 25 | * 26 | * @param the map key type 27 | * @param the map value type 28 | * @see MapRemoteOperations 29 | * @see MapRemoteQueryContext 30 | */ 31 | public interface MapReplicableEntry extends MapEntry, ReplicableEntry { 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/ChronicleSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.ChronicleHash; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * {@code ChronicleSet} provides concurrent access to a Chronicle Map key-value store with 25 | * zero-sized values from a JVM process, wrapped as an extension of {@link Set} interface. 26 | * 27 | * @param the set key type 28 | * @see net.openhft.chronicle.map.ChronicleMap 29 | */ 30 | public interface ChronicleSet 31 | extends Set, ChronicleHash, SetSegmentContext, 32 | ExternalSetQueryContext> { 33 | 34 | /** 35 | * Delegates to {@link ChronicleSetBuilder#of(Class)} for convenience. 36 | * 37 | * @param keyClass class of the key type of the {@code ChronicleSet} to create 38 | * @param the key type of the {@code ChronicleSet} to create 39 | * @return a new {@code ChronicleSetBuilder} for the given key class 40 | */ 41 | static ChronicleSetBuilder of(Class keyClass) { 42 | return ChronicleSetBuilder.of(keyClass); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/DummyValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | enum DummyValue { 20 | DUMMY_VALUE 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/DummyValueData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.bytes.RandomDataInput; 20 | import net.openhft.chronicle.hash.AbstractData; 21 | import net.openhft.chronicle.map.impl.stage.data.ZeroBytesStore; 22 | import org.jetbrains.annotations.Nullable; 23 | 24 | public class DummyValueData extends AbstractData { 25 | 26 | public static final DummyValueData INSTANCE = new DummyValueData(); 27 | 28 | private DummyValueData() { 29 | } 30 | 31 | @Override 32 | public RandomDataInput bytes() { 33 | return ZeroBytesStore.INSTANCE; 34 | } 35 | 36 | @Override 37 | public long offset() { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public long size() { 43 | return 0; 44 | } 45 | 46 | @Override 47 | public DummyValue get() { 48 | return DummyValue.DUMMY_VALUE; 49 | } 50 | 51 | @Override 52 | public DummyValue getUsing(@Nullable DummyValue using) { 53 | return DummyValue.DUMMY_VALUE; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/ExternalSetQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.ExternalHashQueryContext; 20 | 21 | /** 22 | * {@link SetQueryContext} + {@link AutoCloseable}, for external {@link ChronicleSet} queries 23 | * in try-with-resources blocks. 24 | * 25 | * @param the set key type 26 | * @param the return type of {@link SetEntryOperations}, specified for the queried {@code 27 | * ChronicleSet} 28 | * @see ChronicleSet#queryContext(Object) 29 | */ 30 | public interface ExternalSetQueryContext 31 | extends SetQueryContext, ExternalHashQueryContext { 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/SetAbsentEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.HashAbsentEntry; 20 | import org.jetbrains.annotations.NotNull; 21 | 22 | /** 23 | * Low-level operational context for the situations, when the new key is going to be inserted 24 | * into the {@link ChronicleSet}. 25 | * 26 | * @param the set key type 27 | * @see SetEntryOperations 28 | * @see SetQueryContext#absentEntry() 29 | */ 30 | public interface SetAbsentEntry extends HashAbsentEntry { 31 | @NotNull 32 | @Override 33 | SetContext context(); 34 | 35 | /** 36 | * Inserts {@link #absentKey() the new key} into the set. 37 | *

38 | * This method is the default implementation for {@link SetEntryOperations#insert( 39 | *SetAbsentEntry)}, which might be customized over the default. 40 | * 41 | * @throws IllegalStateException if some locking/state conditions required to perform insertion 42 | * operation are not met 43 | * @see SetEntryOperations#insert(SetAbsentEntry) 44 | */ 45 | void doInsert(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/SetContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.ChronicleHash; 20 | import net.openhft.chronicle.hash.HashContext; 21 | 22 | /** 23 | * Context, in which {@link SetEntry SetEntries} are accessed. {@code SetContext} allows to access 24 | * {@link SetEntryOperations}, configured for the accessed {@link ChronicleSet}. {@code SetContext} 25 | * implements {@code SetEntryOperations} by delegation to the configured {@code entryOperations}. 26 | * 27 | * @param the set key type 28 | * @param the return type of {@link SetEntryOperations} specified for the queried set 29 | */ 30 | public interface SetContext extends HashContext, SetEntryOperations { 31 | 32 | /** 33 | * Returns the accessed {@code ChronicleSet}. Synonym to {@link #set()}. 34 | */ 35 | @Override 36 | ChronicleHash hash(); 37 | 38 | /** 39 | * Returns the accessed {@code ChronicleSet}. Synonym to {@link #hash()}. 40 | */ 41 | ChronicleSet set(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/SetEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.HashEntry; 20 | 21 | /** 22 | * A context of a present entry in the {@link ChronicleSet}. 23 | * 24 | * @param the set key type 25 | * @see SetEntryOperations 26 | * @see SetQueryContext#entry() 27 | */ 28 | public interface SetEntry extends HashEntry { 29 | @Override 30 | SetContext context(); 31 | 32 | /** 33 | * Removes the entry from the {@code ChronicleSet}. 34 | *

35 | * This method is the default implementation for {@link SetEntryOperations#remove(SetEntry)}, 36 | * which might be customized over the default. 37 | */ 38 | @Override 39 | void doRemove(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/SetQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.HashQueryContext; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | /** 23 | * A context of {@link ChronicleSet} operations with individual keys 24 | * (most: {@code contains()}, {@code add()}, etc., opposed to bulk operations). 25 | * 26 | * @param the set key type 27 | * @param the return type of {@link SetEntryOperations} specialized for the queried set 28 | * @see ChronicleSet#queryContext(Object) 29 | */ 30 | public interface SetQueryContext extends HashQueryContext, SetContext { 31 | 32 | @Override 33 | @Nullable 34 | SetEntry entry(); 35 | 36 | @Override 37 | @Nullable 38 | SetAbsentEntry absentEntry(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/SetSegmentContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import net.openhft.chronicle.hash.HashSegmentContext; 20 | 21 | /** 22 | * Context of {@link ChronicleSet}'s segment. 23 | * 24 | * @param the key type of accessed {@code ChronicleSet} 25 | * @param the return type of {@link SetEntryOperations} specified for the queried set 26 | * @see ChronicleSet#segmentContext(int) 27 | */ 28 | public interface SetSegmentContext 29 | extends HashSegmentContext>, SetContext { 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

    8 | *
  • Casting to
  • 9 | *
  • Reflection of any kind
  • 10 | *
  • Explicit Serialize/deserialize
  • 11 | *
12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.chronicle.set.internal; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Contains {@link net.openhft.chronicle.set.ChronicleSet} interface, {@code ChronicleSet} context 19 | * interfaces and {@link net.openhft.chronicle.set.ChronicleSetBuilder} class. 20 | */ 21 | package net.openhft.chronicle.set; -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/replication/SetRemoteQueryContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set.replication; 18 | 19 | import net.openhft.chronicle.hash.replication.RemoteOperationContext; 20 | import net.openhft.chronicle.set.ChronicleSet; 21 | import net.openhft.chronicle.set.SetEntryOperations; 22 | import net.openhft.chronicle.set.SetQueryContext; 23 | import org.jetbrains.annotations.Nullable; 24 | 25 | /** 26 | * Context of remote {@link ChronicleSet} queries and internal replication operations. 27 | * 28 | * @param the set key type 29 | * @param the return type of {@link SetEntryOperations} specialized for the queried set 30 | * @see SetRemoteOperations 31 | */ 32 | public interface SetRemoteQueryContext 33 | extends SetQueryContext, RemoteOperationContext { 34 | @Override 35 | @Nullable 36 | SetReplicableEntry entry(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/set/replication/SetReplicableEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set.replication; 18 | 19 | import net.openhft.chronicle.hash.replication.ReplicableEntry; 20 | import net.openhft.chronicle.set.ChronicleSet; 21 | import net.openhft.chronicle.set.SetEntry; 22 | 23 | /** 24 | * A context of a present entry in the replicated {@link ChronicleSet}. 25 | * 26 | * @param the set key type 27 | * @see SetRemoteOperations 28 | * @see SetRemoteQueryContext 29 | */ 30 | public interface SetReplicableEntry extends SetEntry, ReplicableEntry { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/sg/Context.java: -------------------------------------------------------------------------------- 1 | package net.openhft.sg; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.SOURCE) 9 | @Target({ElementType.TYPE}) 10 | public @interface Context { 11 | Class[] topLevel(); 12 | 13 | Class[] nested(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/sg/Stage.java: -------------------------------------------------------------------------------- 1 | package net.openhft.sg; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.FIELD, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Stage { 11 | String value(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/sg/StageRef.java: -------------------------------------------------------------------------------- 1 | package net.openhft.sg; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.FIELD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface StageRef { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/sg/Staged.java: -------------------------------------------------------------------------------- 1 | package net.openhft.sg; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Inherited; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.TYPE}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Inherited 12 | public @interface Staged { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/xstream/converters/StringBuilderConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.xstream.converters; 18 | 19 | import com.thoughtworks.xstream.converters.Converter; 20 | import com.thoughtworks.xstream.converters.MarshallingContext; 21 | import com.thoughtworks.xstream.converters.UnmarshallingContext; 22 | import com.thoughtworks.xstream.io.HierarchicalStreamReader; 23 | import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 24 | 25 | @SuppressWarnings({"rawtypes", "unchecked"}) 26 | public class StringBuilderConverter implements Converter { 27 | 28 | @Override 29 | public void marshal( 30 | Object source, HierarchicalStreamWriter writer, MarshallingContext context) { 31 | writer.setValue(source.toString()); 32 | } 33 | 34 | @Override 35 | public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 36 | return new StringBuilder(reader.getValue()); 37 | } 38 | 39 | @Override 40 | public boolean canConvert(Class type) { 41 | return type == StringBuilder.class; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/xstream/converters/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 3 | * Internal classes shall never be used directly. 4 | *

5 | * Specifically, the following actions (including, but not limited to) are not allowed 6 | * on internal classes and packages: 7 | *

    8 | *
  • Casting to
  • 9 | *
  • Reflection of any kind
  • 10 | *
  • Explicit Serialize/deserialize
  • 11 | *
12 | *

13 | * The classes in this package and any sub-package are subject to 14 | * changes at any time for any reason. 15 | */ 16 | package net.openhft.xstream.converters.internal; 17 | -------------------------------------------------------------------------------- /src/main/resources/map.version: -------------------------------------------------------------------------------- 1 | ${project.version} -------------------------------------------------------------------------------- /src/test/java/eg/TestInstrumentVOInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package eg; 18 | 19 | import net.openhft.chronicle.values.Array; 20 | import net.openhft.chronicle.values.MaxUtf8Length; 21 | 22 | /** 23 | * Created by Vanitha on 12/5/2014. 24 | */ 25 | public interface TestInstrumentVOInterface { 26 | 27 | int getSizeOfInstrumentIDArray(); 28 | 29 | void setSizeOfInstrumentIDArray(int sizeOfInstrumentIDArray); 30 | 31 | String getSymbol(); 32 | 33 | void setSymbol(@MaxUtf8Length(20) String symbol); 34 | 35 | String getCurrencyCode(); 36 | 37 | void setCurrencyCode(@MaxUtf8Length(4) String currencyCode); 38 | 39 | @Array(length = 2) 40 | void setInstrumentIDAt(int location, TestInstrumentIDVOInterface instrumentID); 41 | 42 | TestInstrumentIDVOInterface getInstrumentIDAt(int location); 43 | 44 | interface TestInstrumentIDVOInterface { 45 | 46 | String getIdSource(); 47 | 48 | void setIdSource(@MaxUtf8Length(6) String idSource); 49 | 50 | String getSecurityId(); 51 | 52 | void setSecurityId(@MaxUtf8Length(100) String securityId); 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/examples/portfolio/PortfolioAssetInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package examples.portfolio; 18 | 19 | public interface PortfolioAssetInterface { 20 | public long getAssetId(); 21 | 22 | public void setAssetId(long assetId); 23 | 24 | public int getShares(); 25 | 26 | public void setShares(int shares); 27 | 28 | public double getPrice(); 29 | 30 | public void setPrice(double price); 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/examples/portfolio/PortfolioValueAccumulator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package examples.portfolio; 18 | 19 | import net.openhft.chronicle.core.values.LongValue; 20 | import net.openhft.chronicle.map.MapEntry; 21 | import org.apache.commons.lang3.mutable.MutableDouble; 22 | 23 | import java.util.function.Consumer; 24 | 25 | public final class PortfolioValueAccumulator implements Consumer> { 26 | final MutableDouble total; 27 | final PortfolioAssetInterface asset; 28 | 29 | public PortfolioValueAccumulator(MutableDouble total, PortfolioAssetInterface asset) { 30 | this.total = total; 31 | this.asset = asset; 32 | } 33 | 34 | @Override 35 | public void accept(MapEntry e) { 36 | e.value().getUsing(asset); 37 | total.add(asset.getShares() * asset.getPrice()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/hash/impl/util/CleanerUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.hash.impl.util; 18 | 19 | import org.junit.Test; 20 | 21 | import java.util.concurrent.CountDownLatch; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import static org.junit.Assert.assertTrue; 25 | 26 | public class CleanerUtilsTest { 27 | 28 | @Test 29 | public void testClean() throws InterruptedException { 30 | CountDownLatch latch = new CountDownLatch(1); 31 | Object ob = new Object(); 32 | Cleaner cleaner = CleanerUtils.createCleaner(ob, latch::countDown); 33 | 34 | cleaner.clean(); 35 | 36 | assertTrue(latch.await(1, TimeUnit.SECONDS)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/hash/serialization/impl/SerializableDataAccessTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.hash.serialization.impl; 2 | 3 | import net.openhft.chronicle.map.SerializableTest; 4 | import org.junit.Test; 5 | 6 | import java.util.stream.Collectors; 7 | import java.util.stream.IntStream; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class SerializableDataAccessTest { 12 | 13 | @Test 14 | public void testSerializableDataAccess() { 15 | SerializableDataAccess sda = new SerializableDataAccess<>(); 16 | sda.initTransients(8192); 17 | 18 | String expected = IntStream.range(0, 4096) 19 | .mapToObj(i -> i % 50 == 0 ? String.format("\n%04d", i) : "" + i % 10) 20 | .collect(Collectors.joining("")); 21 | 22 | SerializableTest.Foo value = new SerializableTest.Foo(expected); 23 | sda.getData(value); 24 | SerializableTest.Foo foo = sda.getUsing(null); 25 | assertEquals(expected, foo.x); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/BitUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import junit.framework.TestCase; 20 | 21 | public class BitUnitTest extends TestCase { 22 | 23 | public void testToBits() { 24 | } 25 | 26 | public void testToMegaBits() { 27 | } 28 | 29 | public void testToGigaBits() { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/BloatFactorTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import net.openhft.chronicle.map.example.StringArrayExampleTest; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | 11 | public class BloatFactorTest { 12 | 13 | private static final int EXPECTED_MAX_BLOAT_FACTOR = 100; 14 | 15 | /** 16 | * test that the bloat factor set, remains after a restart 17 | * 18 | * @throws IOException IOException 19 | */ 20 | @Test 21 | public void bloatFactorTest() throws IOException { 22 | 23 | File cmap = File.createTempFile("chron", "cmap"); 24 | 25 | try (ChronicleMap map = ChronicleMapBuilder 26 | .of(Integer.class, StringArrayExampleTest.CharSequenceArray.class) 27 | .entries(100).maxBloatFactor(EXPECTED_MAX_BLOAT_FACTOR) 28 | .createPersistedTo(cmap)) { 29 | 30 | double maxBloatFactor = Jvm.getValue(map, "maxBloatFactor"); 31 | Assert.assertEquals(EXPECTED_MAX_BLOAT_FACTOR, maxBloatFactor, 0.0); 32 | 33 | } 34 | 35 | // if the file already exists it will reuse the existing settings, set above 36 | 37 | try (ChronicleMap map = ChronicleMapBuilder 38 | .of(Integer.class, StringArrayExampleTest.CharSequenceArray.class) 39 | .createPersistedTo(cmap)) { 40 | 41 | double maxBloatFactor = Jvm.getValue(map, "maxBloatFactor"); 42 | Assert.assertEquals(EXPECTED_MAX_BLOAT_FACTOR, maxBloatFactor, 0.0); 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/BooleanValuesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * @author Rob Austin. 26 | */ 27 | public class BooleanValuesTest { 28 | 29 | /** 30 | * see issue here 31 | */ 32 | @Test 33 | public void testTestBooleanValues() throws IOException, InterruptedException { 34 | try (ChronicleMap map = ChronicleMap.of(Integer.class, Boolean.class) 35 | .entries(1).create()) { 36 | map.put(7, true); 37 | Assert.assertEquals(true, map.get(7)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/BuildVersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.impl.util.BuildVersion; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * @author Rob Austin. 27 | */ 28 | public class BuildVersionTest { 29 | 30 | @Test 31 | public void test() throws IOException, InterruptedException { 32 | // checks that we always get a version 33 | Assert.assertNotNull(BuildVersion.version()); 34 | } 35 | 36 | /** 37 | * check that the map records the version 38 | * 39 | */ 40 | @Test 41 | public void testVersion() throws IOException, InterruptedException { 42 | 43 | try (ChronicleMap expected = ChronicleMap.of(Integer.class, Double.class) 44 | .entries(1).create()) { 45 | expected.put(1, 1.0); 46 | 47 | String version = ((VanillaChronicleMap) expected).persistedDataVersion(); 48 | Assert.assertNotNull(BuildVersion.version(), version); 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/BytesMarshallableValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.bytes.BytesMarshallable; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | public class BytesMarshallableValueTest { 24 | 25 | @Test 26 | public void bytesMarshallableValueTest() { 27 | try (ChronicleMap map = ChronicleMap 28 | .of(Integer.class, Value.class) 29 | .averageValue(new Value(1, "foo")) 30 | .entries(10) 31 | .create()) { 32 | map.put(1, new Value(1, "bar")); 33 | Assert.assertEquals("bar", map.replace(1, new Value(2, "baz")).foo); 34 | map.remove(1); 35 | } 36 | } 37 | 38 | public static class Value implements BytesMarshallable { 39 | int x; 40 | String foo; 41 | 42 | public Value(int x, String foo) { 43 | this.x = x; 44 | this.foo = foo; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/ChronicleMapEqualsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Test; 20 | 21 | import java.util.HashMap; 22 | 23 | import static org.junit.Assert.assertTrue; 24 | 25 | public class ChronicleMapEqualsTest { 26 | 27 | @Test 28 | public void test() { 29 | ChronicleMap map = ChronicleMap 30 | .of(String.class, String.class) 31 | .averageKey("a").averageValue("b") 32 | .entries(100) 33 | .create(); 34 | 35 | HashMap refMap = new HashMap<>(); 36 | refMap.put("a", "b"); 37 | map.putAll(refMap); 38 | assertTrue(map.equals(refMap)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/ChronicleMapNameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.set.ChronicleSet; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | public class ChronicleMapNameTest { 24 | 25 | @Test 26 | public void testChronicleMapName() { 27 | ChronicleMap map = ChronicleMap 28 | .of(Integer.class, Integer.class) 29 | .entries(1) 30 | .name("foo") 31 | .create(); 32 | Assert.assertTrue(map.toIdentityString().contains("foo")); 33 | } 34 | 35 | @Test 36 | public void testChronicleSetName() { 37 | ChronicleSet set = ChronicleSet 38 | .of(Integer.class) 39 | .entries(1) 40 | .name("foo") 41 | .create(); 42 | Assert.assertTrue(set.toIdentityString().contains("foo")); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/DeletedSearchStateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | public class DeletedSearchStateTest { 23 | 24 | @Test 25 | public void deletedSearchStateTest() { 26 | ChronicleMap map = 27 | ChronicleMapBuilder.of(Integer.class, Integer.class).entries(100).create(); 28 | 29 | try (ExternalMapQueryContext q = map.queryContext(42)) { 30 | q.updateLock().lock(); 31 | q.insert(q.absentEntry(), q.wrapValueAsData(1)); 32 | q.remove(q.entry()); 33 | q.insert(q.absentEntry(), q.wrapValueAsData(2)); 34 | } 35 | 36 | Assert.assertEquals((Integer) 2, map.get(42)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/GlobalMutableStateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.VanillaGlobalMutableState; 20 | import net.openhft.chronicle.values.Values; 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | public class GlobalMutableStateTest { 26 | 27 | private String dumpCode; 28 | 29 | @Before 30 | public void setDumpCode() { 31 | dumpCode = System.getProperty("dvg.dumpCode"); 32 | System.setProperty("dvg.dumpCode", "true"); 33 | } 34 | 35 | @After 36 | public void unsetDumpCode() { 37 | if (dumpCode != null) 38 | System.setProperty("dvg.dumpCode", dumpCode); 39 | else 40 | System.getProperties().remove("dvg.dumpCode"); 41 | } 42 | 43 | @Test 44 | public void globalMutableStateTest() { 45 | Values.newNativeReference(ReplicatedGlobalMutableStateV2.class); 46 | Values.newNativeReference(VanillaGlobalMutableState.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/HColl423Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Test; 20 | 21 | public class HColl423Test { 22 | 23 | @Test 24 | public void hColl423Test() { 25 | try { 26 | ChronicleMap map = ChronicleMap 27 | .of(String.class, Integer.class) 28 | .averageKeySize(128) 29 | .averageValueSize(100) 30 | .entries(2_000_000L) 31 | .maxBloatFactor(1_000.0) 32 | .create(); 33 | throw new AssertionError("should throw IllegalStateException"); 34 | } catch (IllegalStateException expected) { 35 | // do nothing 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/HistogramTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * Created by peter.lawrey on 28/02/14. 23 | */ 24 | public class HistogramTest { 25 | 26 | @Test 27 | public void testHistogram() { 28 | Histogram hist = new Histogram(); 29 | hist.sample(1); 30 | hist.sample(10); 31 | hist.sample(100); 32 | hist.printResults(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue110Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.values.Array; 20 | import net.openhft.chronicle.values.Values; 21 | import org.junit.Test; 22 | 23 | public class Issue110Test { 24 | @Test 25 | public void testChronicleDoubleArray() { 26 | ChronicleMap map = 27 | ChronicleMapBuilder.of(String.class, IContainer.class) 28 | .entries(1024) 29 | .averageKeySize(9) 30 | .create(); 31 | 32 | map.put("0", Values.newHeapInstance(IContainer.class)); 33 | assert map.get("0") != null; 34 | } 35 | 36 | interface IContainer { 37 | @Array(length = 10) 38 | double getDoubleArrayAt(int i); 39 | 40 | void setDoubleArrayAt(int i, double d); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue125Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.core.OS; 20 | import net.openhft.chronicle.core.util.Time; 21 | import org.junit.Test; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | 26 | /** 27 | * Created by Peter Lawrey on 04/06/17. 28 | */ 29 | public class Issue125Test { 30 | @Test 31 | public void test() throws IOException { 32 | final File cacheRoot = new File(OS.getTarget() + "/test-" + Time.uniqueId() + ".cm3"); 33 | ChronicleMapBuilder shaToNodeBuilder = 34 | ChronicleMapBuilder.of(byte[].class, byte[].class) 35 | // .name("bytes-to-bytes") 36 | .entries(1000000). 37 | averageKeySize(20). 38 | averageValueSize(30); 39 | 40 | ChronicleMap shaToNode = 41 | shaToNodeBuilder.createPersistedTo(cacheRoot); 42 | 43 | shaToNode.put("1".getBytes(), "2".getBytes()); 44 | 45 | shaToNodeBuilder.createPersistedTo(cacheRoot); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue354Test.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.core.values.LongValue; 4 | import org.junit.Test; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | import static org.junit.Assert.assertNotNull; 10 | 11 | public class Issue354Test { 12 | 13 | @Test 14 | public void reproduce() throws IOException { 15 | 16 | final File file = new File("issue354-map"); 17 | file.delete(); 18 | try { 19 | 20 | final ChronicleMapBuilder builder = ChronicleMapBuilder.of(LongValue.class, LongValue.class) 21 | .entries(5); 22 | 23 | try (ChronicleMap map = builder.createPersistedTo(file)) { 24 | assertNotNull(map); 25 | } 26 | 27 | } finally { 28 | file.delete(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue354bTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map; 2 | 3 | import net.openhft.chronicle.core.values.LongValue; 4 | import org.junit.Rule; 5 | import org.junit.Test; 6 | import org.junit.rules.TemporaryFolder; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | 11 | import static org.junit.Assert.assertTrue; 12 | 13 | public class Issue354bTest { 14 | 15 | @Rule 16 | public TemporaryFolder testFolder = new TemporaryFolder(); 17 | 18 | @Test 19 | public void build_toFile() throws IOException { 20 | String baseDirectory = testFolder.getRoot().toString(); 21 | File file = new File(baseDirectory, "chronicle.dat"); 22 | ChronicleMap map = ChronicleMapBuilder.of(LongValue.class, LongValue.class) 23 | .name("test") 24 | .entries(5) 25 | .createPersistedTo(file); 26 | 27 | assertTrue(file.isFile()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue42Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.core.OS; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | 25 | public class Issue42Test { 26 | 27 | @Test 28 | public void crashJVMWindowsTest() throws IOException { 29 | 30 | if (!OS.isWindows()) 31 | return; 32 | 33 | try (final ChronicleMap map = ChronicleMapBuilder 34 | .of(CharSequence.class, CharSequence.class) 35 | .averageKeySize(5.9).averageValueSize(5.9) 36 | .entries(1000000) 37 | .minSegments(128).create()) { 38 | for (int i = 0; i < 1000000; ++i) { 39 | String s = String.valueOf(i); 40 | map.put(s, s); 41 | } 42 | 43 | for (int i = 0; i < 1000000; ++i) { 44 | String s = String.valueOf(i); 45 | Assert.assertEquals(s, map.get(s).toString()); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/Issue62ChronicleClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | public class Issue62ChronicleClient { 20 | 21 | public static void main(String[] args) throws Exception { 22 | /*prepare(MAP_FILE_B); 23 | 24 | ChronicleMapBuilder cityPostalCodesMapBuilder = 25 | ChronicleMapBuilder.of(String.class, Long.class) 26 | //.averageKeySize(100) 27 | .averageKey(Issue62ChronicleServer.STR) 28 | .entries(50_000); 29 | 30 | ((ChronicleHashBuilderPrivateAPI) cityPostalCodesMapBuilder.privateAPI()) 31 | .replication((byte) 2); 32 | 33 | try (ChronicleMap map = 34 | cityPostalCodesMapBuilder.createPersistedTo(MAP_FILE_B)) { 35 | 36 | System.out.println( "Starting"); 37 | Jvm.pause(3000); 38 | 39 | for (Entry entry : map.entrySet()) { 40 | System.out.println(entry); 41 | } 42 | }*/ 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/KeySizesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Test; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.Map; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * Created by peter.lawrey on 28/02/14. 29 | */ 30 | public class KeySizesTest { 31 | @Test 32 | public void testDifferentKeySizes() throws IOException { 33 | 34 | Map map = ChronicleMap.of(String.class, String.class) 35 | .entries(100).averageKeySize(100).averageValueSize(100).create(); 36 | 37 | String k = ""; 38 | for (int i = 0; i < 100; i++) { 39 | map.put(k, k); 40 | String k2 = map.get(k); 41 | assertEquals(k, k2); 42 | k += "a"; 43 | } 44 | k = ""; 45 | for (int i = 0; i < 100; i++) { 46 | String k2 = map.get(k); 47 | assertEquals(k, k2); 48 | k += "a"; 49 | } 50 | 51 | ((Closeable) map).close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.hash.Data; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | class LoggingMapEntryOperations implements MapEntryOperations { 25 | 26 | static final Logger LOG = LoggerFactory.getLogger(LoggingMapEntryOperations.class); 27 | 28 | @Override 29 | public Void replaceValue(@NotNull MapEntry entry, Data newValue) { 30 | LOG.info("replace: old key: {}, old value: {}, new value: {}", 31 | entry.key(), entry.value(), newValue); 32 | entry.doReplaceValue(newValue); 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/NegativeIntegerKeyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | public class NegativeIntegerKeyTest { 26 | 27 | @Test 28 | public void testNegativeIntegerKey() throws IOException { 29 | File file = ChronicleMapTest.getPersistenceFile(); 30 | try (ChronicleMap map = ChronicleMap 31 | .of(Integer.class, Integer.class) 32 | .entries(1) 33 | .createPersistedTo(file)) { 34 | map.put(-1, -1); 35 | } 36 | try (ChronicleMap map = ChronicleMap 37 | .of(Integer.class, Integer.class) 38 | .entries(1) 39 | .recoverPersistedTo(file, true)) { 40 | Assert.assertEquals(Integer.valueOf(-1), map.get(-1)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/NoUpperBoundChunksPerEntryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | public class NoUpperBoundChunksPerEntryTest { 23 | 24 | @Test 25 | public void noUpperBoundChunksPerEntryTest() { 26 | ChronicleMap map = 27 | ChronicleMapBuilder.of(Integer.class, CharSequence.class) 28 | .averageValueSize(2).entries(10000L).actualSegments(1).create(); 29 | String ultraLargeValue = ""; 30 | for (int i = 0; i < 100; i++) { 31 | ultraLargeValue += "Hello"; 32 | } 33 | map.put(1, ultraLargeValue); 34 | Assert.assertEquals(ultraLargeValue, map.get(1).toString()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/PageLatencyMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | /** 20 | * Created by peter.lawrey on 28/02/14. 21 | */ 22 | public class PageLatencyMain { 23 | public static final int PAGES = Integer.getInteger("pages", 1024 * 1024); 24 | public static final int PAGES_SIZE = 512; // longs 25 | public static volatile long b; 26 | 27 | public static void main(String... ignored) { 28 | long[] bytes = new long[PAGES * PAGES_SIZE]; 29 | long maxTime = 0; 30 | for (int j = 0; j < 10; j++) { 31 | for (int i = 0; i < PAGES; i++) { 32 | long start0 = System.nanoTime(); 33 | b = bytes[i * PAGES_SIZE]; 34 | if (b != 0) throw new AssertionError(); 35 | long time = System.nanoTime() - start0; 36 | if (time > maxTime) maxTime = time; 37 | if (time > 1e5) 38 | System.out.println("Page access time was " + time / 100000 / 10.0 + " ms"); 39 | } 40 | } 41 | System.out.println("Longest page access time was " + maxTime / 10000 / 100.0 + " ms"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/SimplePersistedMapOverflowTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import net.openhft.chronicle.set.Builder; 20 | import org.junit.Test; 21 | 22 | import java.io.IOException; 23 | 24 | public class SimplePersistedMapOverflowTest { 25 | 26 | @Test 27 | public void simplePersistedMapOverflowTest() throws IOException { 28 | try (ChronicleMap map = ChronicleMap 29 | .of(Integer.class, Integer.class) 30 | .entries(1_000) 31 | .createPersistedTo(Builder.getPersistenceFile())) { 32 | for (int i = 0; i < 2_000; i++) { 33 | map.put(i, i); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/WarnOnWindowsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map; 18 | 19 | import org.junit.Ignore; 20 | import org.junit.Test; 21 | 22 | public class WarnOnWindowsTest { 23 | 24 | @Test 25 | // TODO this does not emit a proper warning, there are TODOs in ChronicleMapBuilder/VanillaHash 26 | @Ignore("This test results to OOM/jvm crash, run manually to verify warning output") 27 | public void warnOnWindowsTest() { 28 | ChronicleMapBuilder.of(Long.class, Long.class) 29 | .entries(1_000_000_000).create(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/externalizable/SomeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.externalizable; 18 | 19 | import java.io.Externalizable; 20 | import java.io.IOException; 21 | import java.io.ObjectInput; 22 | import java.io.ObjectOutput; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | @SuppressWarnings("serial") 27 | public class SomeClass implements Externalizable { 28 | 29 | final List hits = new ArrayList<>(); 30 | private long id; 31 | 32 | @Override 33 | public void writeExternal(ObjectOutput out) throws IOException { 34 | out.writeLong(id); 35 | out.writeInt(hits.size()); 36 | for (int i = 0; i < hits.size(); i++) { 37 | out.writeObject(hits.get(i)); 38 | } 39 | } 40 | 41 | @Override 42 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 43 | id = in.readLong(); 44 | int size = in.readInt(); 45 | for (int i = 0; i < size; i++) { 46 | hits.add((String) in.readObject()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArraySerializationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs; 18 | 19 | import net.openhft.chronicle.map.ChronicleMap; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | public class CharSequenceArraySerializationTest { 24 | 25 | @Test 26 | public void charSequenceArraySerializationTest() { 27 | try (ChronicleMap map = ChronicleMap 28 | .of(String.class, CharSequence[].class) 29 | .averageKey("fruits") 30 | .valueMarshaller(CharSequenceArrayBytesMarshaller.INSTANCE) 31 | .averageValue(new CharSequence[]{"banana", "pineapple"}) 32 | .entries(2) 33 | .create()) { 34 | map.put("fruits", new CharSequence[]{"banana", "pineapple"}); 35 | map.put("vegetables", new CharSequence[]{"carrot", "potato"}); 36 | Assert.assertEquals(2, map.get("fruits").length); 37 | Assert.assertEquals(2, map.get("vegetables").length); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs; 18 | 19 | public final class Point { 20 | 21 | double x, y; 22 | 23 | public static Point of(double x, double y) { 24 | Point p = new Point(); 25 | p.x = x; 26 | p.y = y; 27 | return p; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolation.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.fromdocs.acid; 2 | 3 | public interface ChronicleAcidIsolation extends java.sql.Connection { 4 | 5 | int LOWEST_LATENCY = ChronicleAcidIsolation.TRANSACTION_NONE; 6 | int DIRTY_READ_OPTIMISTIC = ChronicleAcidIsolation.TRANSACTION_READ_UNCOMMITTED; 7 | int DIRTY_READ_INTOLERANT = ChronicleAcidIsolation.TRANSACTION_READ_COMMITTED; 8 | int REPEATABLE_READS_MANDATORY = ChronicleAcidIsolation.TRANSACTION_REPEATABLE_READ; 9 | int PHANTOM_READ_INTOLERANT = ChronicleAcidIsolation.TRANSACTION_SERIALIZABLE; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleStampedLock.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleStampedLock.pptx -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleStampedLock=WANTED.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleStampedLock=WANTED.png -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/ReadMe.adoc: -------------------------------------------------------------------------------- 1 | image::ChronicleStampedLock=WANTED.png[] -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/ChronicleStampedLockVOInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs.acid.revelations; 18 | 19 | import net.openhft.chronicle.values.Group; 20 | 21 | interface ChronicleStampedLockVOInterface { 22 | 23 | @Group(0) 24 | long getEntryLockState(); 25 | 26 | void setEntryLockState(long entryLockState); 27 | // 28 | // @Group(1) 29 | // long getReaderCount(); 30 | // 31 | // void setReaderCount(long rc); /* time in millis */ 32 | // 33 | // long addAtomicReaderCount(long toAdd); 34 | // 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadTolerance.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.fromdocs.acid.revelations; 2 | 3 | import net.openhft.chronicle.map.ChronicleMap; 4 | import net.openhft.chronicle.map.ChronicleMapBuilder; 5 | import net.openhft.chronicle.map.fromdocs.BondVOInterface; 6 | 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | public class DirtyReadTolerance { 11 | 12 | public static void main(String[] args) throws Exception { 13 | System.out.println("DirtyReadOffender,chrAig[" + args[0] + "]coupon=3.50,DirtyReadVictim"); 14 | String isoLevel = args[0]; 15 | 16 | ChronicleMap chm = 17 | DirtyReadTolerance.offHeap( 18 | args[2] 19 | + "OPERAND_CHRONICLE_MAP" 20 | ); 21 | System.out.println(",Established chm,"); 22 | } 23 | 24 | static ChronicleMap offHeap(String operand) throws IOException { 25 | 26 | return ChronicleMapBuilder.of(String.class, BondVOInterface.class) 27 | .entries(16) 28 | .averageKeySize("123456789".length()) 29 | .createPersistedTo( 30 | new File( 31 | operand 32 | // "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" 33 | ) 34 | ); 35 | //.create(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/Weyuker,E.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/Weyuker,E.pdf -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/clrs=Algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/clrs=Algorithms.pdf -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongAddRight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs.pingpong_latency; 18 | 19 | import net.openhft.chronicle.map.ChronicleMap; 20 | import net.openhft.chronicle.map.fromdocs.BondVOInterface; 21 | 22 | import java.io.IOException; 23 | 24 | import static net.openhft.chronicle.map.fromdocs.pingpong_latency.PingPongAddLeft.playPingPong; 25 | 26 | public class PingPongAddRight { 27 | public static void main(String... ignored) throws IOException { 28 | ChronicleMap chm = PingPongCASLeft.acquireCHM(); 29 | 30 | playPingPong(chm, -1, false, "PingPongAddRIGHT"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASRight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs.pingpong_latency; 18 | 19 | import net.openhft.chronicle.map.ChronicleMap; 20 | import net.openhft.chronicle.map.fromdocs.BondVOInterface; 21 | 22 | import java.io.IOException; 23 | 24 | import static net.openhft.chronicle.map.fromdocs.pingpong_latency.PingPongCASLeft.playPingPong; 25 | 26 | public class PingPongCASRight { 27 | public static void main(String... ignored) throws IOException { 28 | ChronicleMap chm = PingPongCASLeft.acquireCHM(); 29 | 30 | playPingPong(chm, 5, 4, false, "PingPongCASLEFT"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockRight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.fromdocs.pingpong_latency; 18 | 19 | import net.openhft.chronicle.map.ChronicleMap; 20 | import net.openhft.chronicle.map.fromdocs.BondVOInterface; 21 | 22 | import java.io.IOException; 23 | 24 | public class PingPongLockRight { 25 | public static void main(String... ignored) throws IOException, InterruptedException { 26 | ChronicleMap chm = PingPongCASLeft.acquireCHM(); 27 | 28 | //PingPongLockLeft.playPingPong(chm, 5, 4, false, "PingPongLockRIGHT"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/ipc/StateMachineState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.map.ipc; 18 | 19 | /** 20 | * 21 | */ 22 | public enum StateMachineState { 23 | UNKNOWN(-1), 24 | STATE_0(0), 25 | STATE_0_WORKING(1), 26 | STATE_1(10), 27 | STATE_1_WORKING(11), 28 | STATE_2(20), 29 | STATE_2_WORKING(21), 30 | STATE_3(30), 31 | STATE_3_WORKING(31); 32 | 33 | private int state; 34 | 35 | /** 36 | * c-tor 37 | * 38 | */ 39 | StateMachineState(int state) { 40 | this.state = state; 41 | } 42 | 43 | public static StateMachineState fromValue(int value) { 44 | for (StateMachineState sms : StateMachineState.values()) { 45 | if (sms.value() == value) { 46 | return sms; 47 | } 48 | } 49 | 50 | return StateMachineState.UNKNOWN; 51 | } 52 | 53 | /** 54 | */ 55 | public int value() { 56 | return this.state; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/issue/Issue423LockFileRemainsLockedOnWindowsIfBuilderThrowsTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.issue; 2 | 3 | import net.openhft.chronicle.hash.impl.util.CanonicalRandomAccessFiles; 4 | import net.openhft.chronicle.map.ChronicleMap; 5 | import net.openhft.chronicle.map.ChronicleMapBuilder; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.io.RandomAccessFile; 11 | import java.nio.channels.FileChannel; 12 | import java.nio.channels.FileLock; 13 | 14 | import static org.junit.Assert.assertNotNull; 15 | import static org.junit.Assert.assertTrue; 16 | 17 | public class Issue423LockFileRemainsLockedOnWindowsIfBuilderThrowsTest { 18 | 19 | @Test 20 | public void reproduce() throws IOException { 21 | final File file = new File("issue423"); 22 | 23 | try { 24 | ChronicleMap map = ChronicleMapBuilder.of(Integer.class, CharSequence.class) 25 | // This will throw an IllegalArgumentException as the value seize is not known 26 | .entries(100) 27 | .createPersistedTo(file); 28 | 29 | } catch (IllegalStateException ignored) { 30 | // expected path 31 | } 32 | 33 | try (RandomAccessFile raf = CanonicalRandomAccessFiles.acquire(file.getCanonicalFile()); 34 | FileChannel fileChannel = raf.getChannel();) { 35 | 36 | try (FileLock lock = fileChannel.tryLock()) { 37 | // Make sure we can lock (hence the file was not previously locked) 38 | assertNotNull(lock); 39 | } 40 | } 41 | 42 | // Make sure the file can be deleted despite an Exception was thrown by the builder 43 | assertTrue(file.delete()); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/map/locks/DirtyReadTolerance.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.map.locks; 2 | 3 | import net.openhft.chronicle.map.ChronicleMap; 4 | import net.openhft.chronicle.map.ChronicleMapBuilder; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | public class DirtyReadTolerance { 10 | 11 | public static void main(String[] args) throws Exception { 12 | System.out.println("DirtyReadOffender,chrAig[" + args[0] + "]coupon=3.50,DirtyReadVictim"); 13 | String isoLevel = args[0]; 14 | 15 | ChronicleMap chm = 16 | DirtyReadTolerance.offHeap( 17 | args[2] 18 | + "OPERAND_CHRONICLE_MAP" 19 | ); 20 | System.out.println(",Established chm,"); 21 | } 22 | 23 | static ChronicleMap offHeap(String operand) throws IOException { 24 | 25 | return ChronicleMapBuilder.of(String.class, BondVOInterface.class) 26 | .entries(16) 27 | .averageKeySize("123456789".length()) 28 | .createPersistedTo( 29 | new File(operand) 30 | ); 31 | //.create(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/set/ChronicleSetBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Ignore; 21 | import org.junit.Test; 22 | 23 | public class ChronicleSetBuilderTest { 24 | 25 | @Ignore("see https://teamcity.chronicle.software/viewLog.html?buildId=639348&tab=buildResultsDiv&buildTypeId=OpenHFT_BuildAll_BuildJava8compileJava8") 26 | @Test 27 | public void test() { 28 | 29 | try (ChronicleSet integers = ChronicleSet.of(Integer.class).entries(10).create()) { 30 | for (int i = 0; i < 10; i++) { 31 | integers.add(i); 32 | } 33 | 34 | Assert.assertTrue(integers.contains(5)); 35 | Assert.assertEquals(10, integers.size()); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/set/Issue3Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2018 Chronicle Map Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.openhft.chronicle.set; 18 | 19 | import org.junit.Ignore; 20 | import org.junit.Test; 21 | 22 | import java.io.IOException; 23 | import java.util.Random; 24 | 25 | public class Issue3Test { 26 | 27 | @Ignore("https://teamcity.chronicle.software/viewLog.html?buildId=639348&tab=buildResultsDiv&buildTypeId=OpenHFT_BuildAll_BuildJava8compileJava8") 28 | @Test 29 | public void test() throws IOException { 30 | try (ChronicleSet set = ChronicleSetBuilder.of(Long.class) 31 | .actualSegments(1) 32 | .entriesPerSegment(1000) 33 | .create()) { 34 | Random r = new Random(); 35 | for (int i = 0; i < 10; i++) { 36 | for (int j = 0; j < 300; j++) { 37 | set.add(r.nextLong()); 38 | } 39 | set.clear(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/resources/chronicle-map-3-12-no-checksums.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/resources/chronicle-map-3-12-no-checksums.dat -------------------------------------------------------------------------------- /src/test/resources/chronicle-map-3-12-with-checksums.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/resources/chronicle-map-3-12-with-checksums.dat -------------------------------------------------------------------------------- /src/test/resources/input.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/resources/input.txt.gz -------------------------------------------------------------------------------- /src/test/resources/war_and_peace.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Map/0cfd990a50798ffdbc63f8bc656430c9837c8f5c/src/test/resources/war_and_peace.txt.gz -------------------------------------------------------------------------------- /system.properties: -------------------------------------------------------------------------------- 1 | # Tracing if resources are closed/released correctly. 2 | jvm.resource.tracing=false 3 | # for profiling 4 | jvm.safepoint.enabled=false 5 | # for testing sparseFiles 6 | chronicle.map.sparseFile=true 7 | # to speed up tests 8 | net.openhft.chronicle.map.lockTimeoutSeconds=5 --------------------------------------------------------------------------------