T
- the type of the object being internedpublic abstract class AbstractInterner<T> extends Object
The main usage is to reduce the amount of memory used by creating new objects when the same byte sequence is repeatedly decoded into an object.
This cache only guarantees it will provide a String which matches the decoded bytes.
It doesn't guarantee it will always return the same object, nor that different threads will return the same object, though the contents should always be the same.
While not technically thread safe, it should still behave correctly.
Abstract base class for implementing an interning mechanism, which helps in reusing instances of immutable objects. This class is designed to store objects and return previously stored instances that are equal to the required instance.
Note: The interning cache may not always return the same object instance, but the contents of the instances will be equal. *
Modifier and Type | Field and Description |
---|---|
protected net.openhft.chronicle.bytes.util.AbstractInterner.InternerEntry<T>[] |
entries |
protected int |
mask |
protected int |
shift |
protected boolean |
toggle |
Modifier | Constructor and Description |
---|---|
protected |
AbstractInterner(int capacity)
Constructor for creating an intern cache with the given capacity.
|
Modifier and Type | Method and Description |
---|---|
protected abstract T |
getValue(BytesStore bs,
int length)
Retrieves the value corresponding to the bytes store and length.
|
T |
intern(@NotNull Bytes<?> cs)
Interns the specified Bytes object.
|
T |
intern(@NotNull Bytes<?> cs,
int length)
Interns the specified Bytes object of a given length.
|
T |
intern(@NotNull BytesStore cs)
Interns the specified BytesStore object.
|
T |
intern(@NotNull BytesStore cs,
int length)
Interns the specified Bytes.
|
protected boolean |
toggle()
Toggles the internal toggle state and returns its new value.
|
int |
valueCount()
Returns the number of non-null values in the interner entries.
|
protected final net.openhft.chronicle.bytes.util.AbstractInterner.InternerEntry<T>[] entries
protected final int mask
protected final int shift
protected boolean toggle
protected AbstractInterner(int capacity)
1 << 30
.capacity
- the desired capacity for the intern cachepublic T intern(@NotNull @NotNull Bytes<?> cs) throws net.openhft.chronicle.core.io.IORuntimeException, BufferUnderflowException, IllegalStateException
cs
- the Bytes object to internnet.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occursBufferUnderflowException
- If there is not enough data in the buffernet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalStateException
public T intern(@NotNull @NotNull BytesStore cs) throws net.openhft.chronicle.core.io.IORuntimeException, BufferUnderflowException, IllegalStateException
cs
- the BytesStore object to internnet.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occursBufferUnderflowException
- If there is not enough data in the buffernet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalStateException
public T intern(@NotNull @NotNull Bytes<?> cs, int length) throws net.openhft.chronicle.core.io.IORuntimeException, BufferUnderflowException, IllegalStateException
cs
- the Bytes object to internlength
- the length of the Bytes object to internnet.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occursBufferUnderflowException
- If there is not enough data in the buffernet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalStateException
public T intern(@NotNull @NotNull BytesStore cs, int length) throws net.openhft.chronicle.core.io.IORuntimeException, BufferUnderflowException, IllegalStateException
cs
- the Bytes to internlength
- of bytes to readnet.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occursBufferUnderflowException
- If there is not enough data in the buffernet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalStateException
@NotNull protected abstract T getValue(BytesStore bs, int length) throws net.openhft.chronicle.core.io.IORuntimeException, IllegalStateException, BufferUnderflowException
bs
- the bytes storelength
- the length of the data in the bytes storenet.openhft.chronicle.core.io.IORuntimeException
- If an IO error occursBufferUnderflowException
- If there is not enough data in the buffernet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalStateException
protected boolean toggle()
public int valueCount()
Copyright © 2023. All rights reserved.