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:
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 super ReplicableEntry> action);
28 |
29 | boolean forEachSegmentReplicableEntryWhile(Predicate super ReplicableEntry> 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 | *
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.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 extends T> 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 | *
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.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