mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-349 HCOLL-350 stage compilation via annotation processing
This commit is contained in:
@@ -17,9 +17,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.impl.hashlookup.HashLookupIteration;
|
||||
import net.openhft.chronicle.hash.impl.util.CharSequences;
|
||||
import net.openhft.chronicle.map.impl.CompiledMapIterationContext;
|
||||
import net.openhft.chronicle.map.impl.IterationContextInterface;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ import net.openhft.chronicle.hash.replication.AbstractReplication;
|
||||
import net.openhft.chronicle.hash.replication.ReplicableEntry;
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.*;
|
||||
import net.openhft.chronicle.map.impl.CompiledReplicatedMapIterationContext;
|
||||
import net.openhft.chronicle.map.impl.CompiledReplicatedMapQueryContext;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteOperations;
|
||||
import net.openhft.chronicle.map.replication.MapReplicableEntry;
|
||||
import net.openhft.lang.Maths;
|
||||
@@ -522,7 +523,8 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
}
|
||||
|
||||
void raiseChange(long segmentIndex, long pos) {
|
||||
LOG.debug("raise change: id {}, segment {}, pos {}", localIdentifier, segmentIndex, pos);
|
||||
LOG.debug("raise change: id {}, segment {}, pos {}",
|
||||
localIdentifier, segmentIndex, pos);
|
||||
changesForUpdates.set(combine(segmentIndex, pos));
|
||||
modificationNotifier.onChange();
|
||||
}
|
||||
@@ -620,10 +622,12 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
c.key(), c.value());
|
||||
}
|
||||
MapReplicableEntry re = (MapReplicableEntry) entry;
|
||||
assert re.originTimestamp() > 0L;
|
||||
// Bizarrely the next line line cause NPE in JDT compiler
|
||||
//assert re.originTimestamp() > 0L;
|
||||
if (debugEnabled) {
|
||||
LOG.debug("Bootstrap decision: bs ts: {}, entry ts: {}, entry id: {}, " +
|
||||
"local id: {}", fromTimeStamp, re.originTimestamp(),
|
||||
LOG.debug("Bootstrap decision: bs ts: {}, entry ts: {}, " +
|
||||
"entry id: {}, local id: {}",
|
||||
fromTimeStamp, re.originTimestamp(),
|
||||
re.originIdentifier(), localIdentifier);
|
||||
}
|
||||
if (re.originTimestamp() >= fromTimeStamp &&
|
||||
|
||||
@@ -24,11 +24,9 @@ import net.openhft.chronicle.hash.replication.RemoteNodeValidator;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.hash.replication.ThrottlingConfig;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.internal.ReaderWithSize;
|
||||
import net.openhft.chronicle.hash.serialization.internal.SerializationBuilder;
|
||||
import net.openhft.chronicle.map.impl.CompiledReplicatedMapQueryContext;
|
||||
import net.openhft.chronicle.map.impl.QueryContextInterface;
|
||||
import net.openhft.lang.io.AbstractBytes;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.KeyContext;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.KeyContext;
|
||||
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
@@ -27,6 +27,8 @@ import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaProvider;
|
||||
import net.openhft.chronicle.hash.serialization.internal.SerializationBuilder;
|
||||
import net.openhft.chronicle.map.impl.*;
|
||||
import net.openhft.chronicle.map.impl.CompiledMapIterationContext;
|
||||
import net.openhft.chronicle.map.impl.CompiledMapQueryContext;
|
||||
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
@@ -265,11 +267,13 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
", Note : its more efficient if your chronicle map is configured with " +
|
||||
"interface key " +
|
||||
"and value types rather than classes, as this method is able to use " +
|
||||
"interfaces to generate off heap proxies that point straight at your data. " +
|
||||
"interfaces to generate off heap proxies that point straight at your " +
|
||||
"data. " +
|
||||
"In this case you have used a class and chronicle is unable to create an " +
|
||||
"instance of this class has it does not have a default constructor. " +
|
||||
"If your class is mutable, we " +
|
||||
"recommend you create and instance of your class=" + aClass.getSimpleName() +
|
||||
"recommend you create and instance of your class=" +
|
||||
aClass.getSimpleName() +
|
||||
" in the usual way, rather than using this method.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class CompilationAnchor {
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
-2559
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.*;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.DeprecatedMapKeyContextOnIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.IterationCheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.MapSegmentIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.stage.map.VanillaChronicleMapHolderImpl;
|
||||
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
|
||||
import net.openhft.sg.Context;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
@Context(topLevel = {
|
||||
CompilationAnchor.class,
|
||||
OwnerThreadHolder.class,
|
||||
ThreadLocalCopiesHolder.class,
|
||||
VanillaChronicleMapHolderImpl.class,
|
||||
|
||||
MapSegmentIteration.class,
|
||||
|
||||
HashLookup.class,
|
||||
KeyBytesInterop.class,
|
||||
SegmentStages.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
MapEntryStages.class,
|
||||
ValueBytesInterop.class,
|
||||
MapEntryOperationsDelegation.class,
|
||||
}, nested = {
|
||||
ReadLock.class,
|
||||
UpdateLock.class,
|
||||
WriteLock.class,
|
||||
|
||||
EntryKeyBytesData.class,
|
||||
EntryValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
|
||||
DeprecatedMapKeyContextOnIteration.class,
|
||||
})
|
||||
public class MapIterationContext {
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupPos;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QuerySegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.InputFirstValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.InputSecondValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.InputValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.stage.map.VanillaChronicleMapHolderImpl;
|
||||
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.query.*;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.DefaultReturnValue;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
|
||||
import net.openhft.sg.Context;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
@Context(topLevel = {
|
||||
CompilationAnchor.class,
|
||||
OwnerThreadHolder.class,
|
||||
ThreadLocalCopiesHolder.class,
|
||||
|
||||
VanillaChronicleMapHolderImpl.class,
|
||||
|
||||
HashLookup.class,
|
||||
KeyBytesInterop.class,
|
||||
QuerySegmentStages.class,
|
||||
|
||||
HashLookupSearch.class,
|
||||
QueryHashLookupPos.class,
|
||||
|
||||
QueryCheckOnEachPublicOperation.class,
|
||||
SearchAllocatedChunks.class,
|
||||
|
||||
MapEntryStages.class,
|
||||
MapEntryOperationsDelegation.class,
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
MapQuery.class,
|
||||
MapAbsent.class,
|
||||
ValueBytesInterop.class,
|
||||
MapAbsentHolder.class,
|
||||
|
||||
HashInputBytes.class,
|
||||
MapInputBytesValues.class,
|
||||
},
|
||||
nested = {
|
||||
ReadLock.class,
|
||||
UpdateLock.class,
|
||||
WriteLock.class,
|
||||
|
||||
EntryKeyBytesData.class,
|
||||
EntryValueBytesData.class,
|
||||
|
||||
InputKeyInstanceData.class,
|
||||
InputValueInstanceData.class,
|
||||
|
||||
InputKeyBytesData.class,
|
||||
InputFirstValueBytesData.class,
|
||||
InputSecondValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
DeprecatedMapKeyContextOnQuery.class,
|
||||
DeprecatedMapAcquireContextOnQuery.class,
|
||||
DefaultReturnValue.class,
|
||||
UsingReturnValue.class,
|
||||
})
|
||||
public class MapQueryContext {
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.*;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.DeprecatedMapKeyContextOnIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.IterationCheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.ReplicatedMapSegmentIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ReplicatedChronicleMapHolderImpl;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.sg.Context;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
@Context(topLevel = {
|
||||
CompilationAnchor.class,
|
||||
OwnerThreadHolder.class,
|
||||
ThreadLocalCopiesHolder.class,
|
||||
ReplicatedChronicleMapHolderImpl.class,
|
||||
|
||||
ReplicatedMapSegmentIteration.class,
|
||||
|
||||
HashLookup.class,
|
||||
KeyBytesInterop.class,
|
||||
SegmentStages.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
ReplicatedMapEntryStages.class,
|
||||
ValueBytesInterop.class,
|
||||
MapEntryOperationsDelegation.class,
|
||||
|
||||
ReplicationUpdate.class,
|
||||
}, nested = {
|
||||
ReadLock.class,
|
||||
UpdateLock.class,
|
||||
WriteLock.class,
|
||||
|
||||
EntryKeyBytesData.class,
|
||||
EntryValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
|
||||
DeprecatedMapKeyContextOnIteration.class,
|
||||
|
||||
DummyValueZeroData.class,
|
||||
})
|
||||
public class ReplicatedMapIterationContext {
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.LogHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupPos;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QuerySegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.*;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.InputValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
|
||||
import net.openhft.chronicle.map.impl.stage.input.ReplicatedInput;
|
||||
import net.openhft.chronicle.map.impl.stage.map.*;
|
||||
import net.openhft.chronicle.map.impl.stage.query.*;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.BytesReturnValue;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.DefaultReturnValue;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
|
||||
import net.openhft.sg.Context;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
@Context(topLevel = {
|
||||
CompilationAnchor.class,
|
||||
OwnerThreadHolder.class,
|
||||
ThreadLocalCopiesHolder.class,
|
||||
|
||||
LogHolder.class,
|
||||
|
||||
ReplicatedChronicleMapHolderImpl.class,
|
||||
|
||||
HashLookup.class,
|
||||
KeyBytesInterop.class,
|
||||
QuerySegmentStages.class,
|
||||
|
||||
HashLookupSearch.class,
|
||||
QueryHashLookupPos.class,
|
||||
|
||||
QueryCheckOnEachPublicOperation.class,
|
||||
SearchAllocatedChunks.class,
|
||||
|
||||
ReplicatedMapEntryStages.class,
|
||||
MapEntryOperationsDelegation.class,
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
ReplicatedMapQuery.class,
|
||||
ReplicatedMapAbsent.class,
|
||||
ValueBytesInterop.class,
|
||||
ReplicatedMapAbsentHolder.class,
|
||||
ReplicationUpdate.class,
|
||||
ReplicatedInput.class,
|
||||
|
||||
HashInputBytes.class,
|
||||
MapInputBytesValues.class,
|
||||
},
|
||||
nested = {
|
||||
ReadLock.class,
|
||||
UpdateLock.class,
|
||||
WriteLock.class,
|
||||
|
||||
EntryKeyBytesData.class,
|
||||
EntryValueBytesData.class,
|
||||
|
||||
InputKeyInstanceData.class,
|
||||
InputValueInstanceData.class,
|
||||
BytesReturnValue.class,
|
||||
|
||||
InputKeyBytesData.class,
|
||||
InputFirstValueBytesData.class,
|
||||
InputSecondValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
DeprecatedMapKeyContextOnQuery.class,
|
||||
DeprecatedMapAcquireContextOnQuery.class,
|
||||
DefaultReturnValue.class,
|
||||
UsingReturnValue.class,
|
||||
|
||||
ReplicatedMapAbsentDelegating.class,
|
||||
|
||||
ReplicatedInputKeyBytesData.class,
|
||||
ReplicatedInputValueBytesData.class,
|
||||
|
||||
DummyValueZeroData.class,
|
||||
})
|
||||
public class ReplicatedMapQueryContext {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.bytes.ZeroRandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class DummyValueZeroData<V> extends AbstractData<V> {
|
||||
@StageRef
|
||||
VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return ZeroRandomDataInput.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return mh.m().valueSizeMarshaller.minEncodableSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingInstance) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class EntryValueBytesData<V> extends AbstractData<V> {
|
||||
|
||||
@StageRef ValueBytesInterop<V, ?, ?> vi;
|
||||
@StageRef MapEntryStages<?, V> entry;
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
|
||||
|
||||
@Stage("CachedEntryValue") private V cachedEntryValue;
|
||||
@Stage("CachedEntryValue") private boolean cachedEntryValueRead = false;
|
||||
|
||||
private void initCachedEntryValue() {
|
||||
cachedEntryValue = innerGetUsing(cachedEntryValue);
|
||||
cachedEntryValueRead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entry.entryBS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entry.valueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entry.valueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return cachedEntryValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return innerGetUsing(usingValue);
|
||||
}
|
||||
|
||||
private V innerGetUsing(V usingValue) {
|
||||
entry.entryBytes.position(entry.valueOffset);
|
||||
return vi.valueReader.read(entry.entryBytes, size(), usingValue);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
|
||||
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class InputFirstValueBytesData<V> extends AbstractData<V> {
|
||||
|
||||
@StageRef HashInputBytes in;
|
||||
@StageRef MapInputBytesValues values;
|
||||
@StageRef ValueBytesInterop<V, ?, ?> vi;
|
||||
|
||||
@Stage("CachedBytesInputFirstValue") private V cachedBytesInputFirstValue;
|
||||
@Stage("CachedBytesInputFirstValue") private boolean cachedBytesInputFirstValueRead = false;
|
||||
|
||||
private void initCachedBytesInputFirstValue() {
|
||||
cachedBytesInputFirstValue = getUsing(cachedBytesInputFirstValue);
|
||||
cachedBytesInputFirstValueRead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return in.inputStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return values.firstInputValueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return values.firstInputValueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
return cachedBytesInputFirstValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
in.inputBytes.position(values.firstInputValueOffset);
|
||||
return vi.valueReader.read(in.inputBytes, size(), usingValue);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
|
||||
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class InputSecondValueBytesData<V> extends AbstractData<V> {
|
||||
|
||||
@StageRef HashInputBytes in;
|
||||
@StageRef MapInputBytesValues values;
|
||||
@StageRef ValueBytesInterop<V, ?, ?> vi;
|
||||
|
||||
@Stage("CachedBytesInputSecondValue") private V cachedBytesInputSecondValue;
|
||||
@Stage("CachedBytesInputSecondValue") private boolean cachedBytesInputSecondValueRead = false;
|
||||
|
||||
private void initCachedBytesInputSecondValue() {
|
||||
cachedBytesInputSecondValue = getUsing(cachedBytesInputSecondValue);
|
||||
cachedBytesInputSecondValueRead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return in.inputStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return values.secondInputValueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return values.secondInputValueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
return cachedBytesInputSecondValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
in.inputBytes.position(values.secondInputValueOffset);
|
||||
return vi.valueReader.read(in.inputBytes, size(), usingValue);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.stage.input.ReplicatedInput;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
|
||||
@Staged
|
||||
public class ReplicatedInputKeyBytesData<K> extends AbstractData<K> {
|
||||
@StageRef ReplicatedInput<K, ?, ?> in;
|
||||
@StageRef KeyBytesInterop<K, ?, ?> ki;
|
||||
|
||||
@Stage("CachedBytesReplicatedInputKey") private K cachedBytesReplicatedInputKey;
|
||||
@Stage("CachedBytesReplicatedInputKey") private boolean cachedBytesReplicatedInputKeyRead =
|
||||
false;
|
||||
|
||||
private void initCachedBytesReplicatedInputKey() {
|
||||
cachedBytesReplicatedInputKey = getUsing(cachedBytesReplicatedInputKey);
|
||||
cachedBytesReplicatedInputKeyRead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return in.replicatedInputStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return in.riKeyOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return in.riKeySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K get() {
|
||||
return cachedBytesReplicatedInputKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getUsing(K usingKey) {
|
||||
Bytes inputBytes = in.replicatedInputBytes;
|
||||
inputBytes.position(in.riKeyOffset);
|
||||
return ki.keyReader.read(inputBytes, size(), usingKey);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.map.impl.stage.input.ReplicatedInput;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
|
||||
@Staged
|
||||
public class ReplicatedInputValueBytesData<V> extends AbstractData<V> {
|
||||
@StageRef ReplicatedInput<?, V, ?> in;
|
||||
@StageRef ValueBytesInterop<V, ?, ?> ki;
|
||||
|
||||
@Stage("CachedBytesReplicatedInputValue") private V cachedBytesReplicatedInputValue;
|
||||
@Stage("CachedBytesReplicatedInputValue") private boolean cachedBytesReplicatedInputValueRead =
|
||||
false;
|
||||
|
||||
private void initCachedBytesReplicatedInputValue() {
|
||||
cachedBytesReplicatedInputValue = getUsing(cachedBytesReplicatedInputValue);
|
||||
cachedBytesReplicatedInputValueRead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return in.replicatedInputStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return in.riValueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return in.riValueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
return cachedBytesReplicatedInputValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
Bytes inputBytes = in.replicatedInputBytes;
|
||||
inputBytes.position(in.riValueOffset);
|
||||
return ki.valueReader.read(inputBytes, size(), usingValue);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.CopyingInstanceData;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitableData;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public abstract class InputValueInstanceData<V, VI, MVI extends MetaBytesInterop<V, ? super VI>>
|
||||
extends CopyingInstanceData<V> implements ValueInitableData<V> {
|
||||
|
||||
@StageRef ValueBytesInterop<V, VI, MVI> vi;
|
||||
|
||||
private V value = null;
|
||||
|
||||
@Override
|
||||
public void initValue(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V instance() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Stage("Buffer") private DirectBytes buffer;
|
||||
@Stage("Buffer") private boolean marshalled = false;
|
||||
|
||||
private void initBuffer() {
|
||||
MVI mvi = vi.valueMetaInterop(value);
|
||||
long size = mvi.size(vi.valueInterop, value);
|
||||
buffer = getBuffer(this.buffer, size);
|
||||
mvi.write(vi.valueInterop, buffer, value);
|
||||
buffer.flip();
|
||||
marshalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
buffer.position(0);
|
||||
return vi.valueReader.read(buffer, buffer.limit(), usingValue);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.data.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.CopyingInstanceData;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class WrappedValueInstanceData<
|
||||
V, VI, MVI extends MetaBytesInterop<V, ? super VI>>
|
||||
extends CopyingInstanceData<V> {
|
||||
|
||||
@StageRef VanillaChronicleMapHolder<?, ?, ?, V, VI, MVI, ?> mh;
|
||||
@StageRef ValueBytesInterop<V, VI, MVI> vi;
|
||||
|
||||
private WrappedValueInstanceData<V, VI, MVI> next;
|
||||
|
||||
boolean nextInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void closeNext() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Stage("Next")
|
||||
public WrappedValueInstanceData getUnusedWrappedValue() {
|
||||
if (!valueInit())
|
||||
return this;
|
||||
if (next == null)
|
||||
next = new WrappedValueInstanceData<>();
|
||||
return next.getUnusedWrappedValue();
|
||||
}
|
||||
|
||||
private V value;
|
||||
|
||||
public boolean valueInit() {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public void initValue(V value) {
|
||||
mh.m().checkValue(value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void closeValue() {
|
||||
value = null;
|
||||
if (next != null)
|
||||
next.closeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V instance() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Stage("Buffer") private DirectBytes buf;
|
||||
@Stage("Buffer") private boolean marshalled = false;
|
||||
|
||||
private void initBuffer() {
|
||||
MVI mvi = vi.valueMetaInterop(value);
|
||||
long size = mvi.size(vi.valueInterop, value);
|
||||
buf = getBuffer(this.buf, size);
|
||||
mvi.write(vi.valueInterop, buf, value);
|
||||
buf.flip();
|
||||
marshalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectBytes buffer() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
buf.position(0);
|
||||
return vi.valueReader.read(buf, buf.limit(), usingValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.entry;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.AllocatedChunks;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.HashEntryStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.VanillaChronicleMap;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
implements MapEntry<K, V> {
|
||||
|
||||
@StageRef VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
@StageRef AllocatedChunks allocatedChunks;
|
||||
@StageRef HashLookup hashLookup;
|
||||
|
||||
long countValueSizeOffset() {
|
||||
return keyEnd();
|
||||
}
|
||||
|
||||
public long valueSizeOffset = -1;
|
||||
|
||||
void initValueSizeOffset() {
|
||||
valueSizeOffset = countValueSizeOffset();
|
||||
}
|
||||
|
||||
@Stage("ValSize") public long valueSize = -1;
|
||||
@Stage("ValSize") public long valueOffset;
|
||||
|
||||
@Stage("ValSize") private void countValueOffset() {
|
||||
mh.m().alignment.alignPositionAddr(entryBytes);
|
||||
valueOffset = entryBytes.position();
|
||||
}
|
||||
|
||||
void initValSize(long valueSize) {
|
||||
this.valueSize = valueSize;
|
||||
entryBytes.position(valueSizeOffset);
|
||||
mh.m().valueSizeMarshaller.writeSize(entryBytes, valueSize);
|
||||
countValueOffset();
|
||||
}
|
||||
|
||||
void initValSize() {
|
||||
entryBytes.position(valueSizeOffset);
|
||||
valueSize = mh.m().readValueSize(entryBytes);
|
||||
countValueOffset();
|
||||
}
|
||||
|
||||
void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) {
|
||||
valueSize = oldValueSize;
|
||||
valueOffset = valueSizeOffset + (oldValueOffset - oldValueSizeOffset);
|
||||
}
|
||||
|
||||
public void initValue(Data<?> value) {
|
||||
entryBytes.position(valueSizeOffset);
|
||||
initValSize(value.size());
|
||||
writeValue(value);
|
||||
}
|
||||
|
||||
public void writeValue(Data<?> value) {
|
||||
value.writeTo(entryBS, valueOffset);
|
||||
}
|
||||
|
||||
public void initValueWithoutSize(
|
||||
Data<?> value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) {
|
||||
assert oldValueSize == value.size();
|
||||
initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset);
|
||||
writeValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long entryEnd() {
|
||||
return valueOffset + valueSize;
|
||||
}
|
||||
|
||||
@StageRef public EntryValueBytesData<V> entryValue;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<V> value() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entryValue;
|
||||
}
|
||||
|
||||
public void putValueDeletedEntry(Data<V> newValue) {
|
||||
assert s.innerUpdateLock.isHeldByCurrentThread();
|
||||
|
||||
int newSizeInChunks;
|
||||
long entryStartOffset = keySizeOffset;
|
||||
long newSizeOfEverythingBeforeValue = -1;
|
||||
boolean newValueSizeIsDifferent = newValue.size() != valueSize;
|
||||
if (newValueSizeIsDifferent) {
|
||||
newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue);
|
||||
long newValueOffset = mh.m().alignment.alignAddr(
|
||||
entryStartOffset + newSizeOfEverythingBeforeValue);
|
||||
long newEntrySize = newValueOffset + newValue.size() - entryStartOffset;
|
||||
newSizeInChunks = mh.m().inChunks(newEntrySize);
|
||||
} else {
|
||||
newSizeInChunks = entrySizeInChunks;
|
||||
}
|
||||
if (pos + newSizeInChunks < s.freeList.size() &&
|
||||
s.freeList.allClear(pos, pos + newSizeInChunks)) {
|
||||
s.freeList.set(pos, pos + newSizeInChunks);
|
||||
s.innerWriteLock.lock();
|
||||
allocatedChunks.incrementSegmentEntriesIfNeeded();
|
||||
if (newValueSizeIsDifferent) {
|
||||
initValue(newValue);
|
||||
} else {
|
||||
writeValue(newValue);
|
||||
}
|
||||
} else {
|
||||
if (newValueSizeIsDifferent) {
|
||||
assert newSizeOfEverythingBeforeValue >= 0;
|
||||
} else {
|
||||
newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue);
|
||||
}
|
||||
long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size());
|
||||
if (newValueSizeIsDifferent) {
|
||||
allocatedChunks.initEntryAndKeyCopying(entrySize, valueSizeOffset - entryStartOffset);
|
||||
initValue(newValue);
|
||||
} else {
|
||||
long oldValueSizeOffset = valueSizeOffset;
|
||||
long oldValueSize = valueSize;
|
||||
long oldValueOffset = valueOffset;
|
||||
allocatedChunks.initEntryAndKeyCopying(entrySize, valueOffset - entryStartOffset);
|
||||
initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset);
|
||||
}
|
||||
freeExtraAllocatedChunks();
|
||||
}
|
||||
hashLookup.putValueVolatile(hlp.hashLookupPos, pos);
|
||||
}
|
||||
|
||||
public void writeValueAndPutPos(Data<V> value) {
|
||||
initValue(value);
|
||||
freeExtraAllocatedChunks();
|
||||
hashLookup.putValueVolatile(hlp.hashLookupPos, pos);
|
||||
}
|
||||
|
||||
public long newSizeOfEverythingBeforeValue(Data<V> newValue) {
|
||||
return valueSizeOffset + mh.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()) -
|
||||
keySizeOffset;
|
||||
}
|
||||
|
||||
public void innerDefaultReplaceValue(Data<V> newValue) {
|
||||
assert s.innerUpdateLock.isHeldByCurrentThread();
|
||||
|
||||
boolean newValueSizeIsDifferent = newValue.size() != this.valueSize;
|
||||
if (newValueSizeIsDifferent) {
|
||||
long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue);
|
||||
long entryStartOffset = keySizeOffset;
|
||||
VanillaChronicleMap<?, ?, ?, ?, ?, ?, ?> m = mh.m();
|
||||
long newValueOffset = m.alignment.alignAddr(
|
||||
entryStartOffset + newSizeOfEverythingBeforeValue);
|
||||
long newEntrySize = newValueOffset + newValue.size() - entryStartOffset;
|
||||
int newSizeInChunks = m.inChunks(newEntrySize);
|
||||
newValueDoesNotFit:
|
||||
if (newSizeInChunks > entrySizeInChunks) {
|
||||
if (newSizeInChunks > m.maxChunksPerEntry) {
|
||||
throw new IllegalArgumentException("Value too large: " +
|
||||
"entry takes " + newSizeInChunks + " chunks, " +
|
||||
m.maxChunksPerEntry + " is maximum.");
|
||||
}
|
||||
if (s.freeList.allClear(pos + entrySizeInChunks, pos + newSizeInChunks)) {
|
||||
s.freeList.set(pos + entrySizeInChunks, pos + newSizeInChunks);
|
||||
break newValueDoesNotFit;
|
||||
}
|
||||
relocation(newValue, newSizeOfEverythingBeforeValue);
|
||||
return;
|
||||
} else if (newSizeInChunks < entrySizeInChunks) {
|
||||
// Freeing extra chunks
|
||||
s.freeList.clear(pos + newSizeInChunks, pos + entrySizeInChunks);
|
||||
// Do NOT reset nextPosToSearchFrom, because if value
|
||||
// once was larger it could easily became larger again,
|
||||
// But if these chunks will be taken by that time,
|
||||
// this entry will need to be relocated.
|
||||
}
|
||||
// new size != old size => size is not constant => size is actually written =>
|
||||
// to prevent (at least) this execution:
|
||||
// 1. concurrent reader thread reads the size
|
||||
// 2. this thread updates the size and the value
|
||||
// 3. concurrent reader reads the value
|
||||
// We MUST upgrade to exclusive lock
|
||||
} else {
|
||||
// TODO to turn the following block on, JLANG-46 is required. Also unclear what happens
|
||||
// if the value is DataValue generated with 2, 4 or 8 distinct bytes, putting on-heap
|
||||
// implementation of such value is also not atomic currently, however there is a way
|
||||
// to make it atomic, we should identify such cases and make a single write:
|
||||
// state = UNSAFE.getLong(onHeapValueObject, offsetToTheFirstField);
|
||||
// bytes.writeLong(state);
|
||||
// boolean newValueSizeIsPowerOf2 = ((newValueSize - 1L) & newValueSize) != 0;
|
||||
// if (!newValueSizeIsPowerOf2 || newValueSize > 8L) {
|
||||
// // if the new value size is 1, 2, 4, or 8, it is written not atomically only if
|
||||
// // the user provided own marshaller and writes value byte-by-byte, that is very
|
||||
// // unlikely. in this case the user should update acquire write lock before write
|
||||
// // updates himself
|
||||
// upgradeToWriteLock();
|
||||
// }
|
||||
}
|
||||
s.innerWriteLock.lock();
|
||||
|
||||
if (newValueSizeIsDifferent) {
|
||||
initValue(newValue);
|
||||
} else {
|
||||
writeValue(newValue);
|
||||
}
|
||||
hashLookup.putValueVolatile(hlp.hashLookupPos, pos);
|
||||
}
|
||||
|
||||
protected void relocation(Data<V> newValue, long newSizeOfEverythingBeforeValue) {
|
||||
s.free(pos, entrySizeInChunks);
|
||||
long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size());
|
||||
allocatedChunks.initEntryAndKeyCopying(entrySize, valueSizeOffset - keySizeOffset);
|
||||
writeValueAndPutPos(newValue);
|
||||
}
|
||||
|
||||
public final long entrySize(long keySize, long valueSize) {
|
||||
long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize);
|
||||
return innerEntrySize(sizeOfEverythingBeforeValue, valueSize);
|
||||
}
|
||||
|
||||
public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) {
|
||||
if (mh.m().constantlySizedEntry) {
|
||||
return mh.m().alignment.alignAddr(sizeOfEverythingBeforeValue + valueSize);
|
||||
} else if (mh.m().couldNotDetermineAlignmentBeforeAllocation) {
|
||||
return sizeOfEverythingBeforeValue + mh.m().worstAlignment + valueSize;
|
||||
} else {
|
||||
return mh.m().alignment.alignAddr(sizeOfEverythingBeforeValue) + valueSize;
|
||||
}
|
||||
}
|
||||
|
||||
long sizeOfEverythingBeforeValue(long keySize, long valueSize) {
|
||||
return mh.m().metaDataBytes +
|
||||
mh.m().keySizeMarshaller.sizeEncodingSize(keySize) + keySize +
|
||||
mh.m().valueSizeMarshaller.sizeEncodingSize(valueSize);
|
||||
}
|
||||
|
||||
public final void freeExtraAllocatedChunks() {
|
||||
// fast path
|
||||
if (!mh.m().constantlySizedEntry && mh.m().couldNotDetermineAlignmentBeforeAllocation &&
|
||||
entrySizeInChunks < allocatedChunks.allocatedChunks) {
|
||||
s.free(pos + entrySizeInChunks, allocatedChunks.allocatedChunks - entrySizeInChunks);
|
||||
} else {
|
||||
initTheEntrySizeInChunks(allocatedChunks.allocatedChunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.entry;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.chronicle.map.replication.MapReplicableEntry;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
import static net.openhft.chronicle.map.ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES;
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K, V>
|
||||
implements MapReplicableEntry<K, V> {
|
||||
|
||||
@StageRef ReplicatedChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
@StageRef ReplicationUpdate ru;
|
||||
|
||||
@Stage("ReplicationState") long replicationBytesOffset = -1;
|
||||
|
||||
void initReplicationState() {
|
||||
replicationBytesOffset = keyEnd();
|
||||
}
|
||||
|
||||
void updateReplicationState(long timestamp, byte identifier) {
|
||||
entryBytes.position(replicationBytesOffset);
|
||||
entryBytes.writeLong(timestamp);
|
||||
entryBytes.writeByte(identifier);
|
||||
}
|
||||
|
||||
private long timestampOffset() {
|
||||
return replicationBytesOffset;
|
||||
}
|
||||
|
||||
public long timestamp() {
|
||||
return entryBS.readLong(replicationBytesOffset);
|
||||
}
|
||||
|
||||
private long identifierOffset() {
|
||||
return replicationBytesOffset + 8L;
|
||||
}
|
||||
|
||||
byte identifier() {
|
||||
return entryBS.readByte(identifierOffset());
|
||||
}
|
||||
|
||||
private long entryDeletedOffset() {
|
||||
return replicationBytesOffset + 9L;
|
||||
}
|
||||
|
||||
public boolean entryDeleted() {
|
||||
return entryBS.readBoolean(entryDeletedOffset());
|
||||
}
|
||||
|
||||
public void writeEntryPresent() {
|
||||
entryBS.writeBoolean(entryDeletedOffset(), false);
|
||||
}
|
||||
|
||||
public void writeEntryDeleted() {
|
||||
entryBS.writeBoolean(entryDeletedOffset(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte originIdentifier() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return identifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long originTimestamp() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return timestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
long countValueSizeOffset() {
|
||||
return super.countValueSizeOffset() + ADDITIONAL_ENTRY_BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOrigin(byte newIdentifier, long newTimestamp) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerWriteLock.lock();
|
||||
updateReplicationState(newTimestamp, newIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropChanged() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerUpdateLock.lock();
|
||||
ru.dropChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void raiseChanged() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerUpdateLock.lock();
|
||||
ru.raiseChange();
|
||||
}
|
||||
|
||||
public void updatedReplicationStateOnPresentEntry() {
|
||||
if (!ru.replicationUpdateInit()) {
|
||||
s.innerWriteLock.lock();
|
||||
long timestamp;
|
||||
if (identifier() != mh.m().identifier()) {
|
||||
timestamp = Math.max(timestamp() + 1, mh.m().timeProvider.currentTime());
|
||||
} else {
|
||||
timestamp = mh.m().timeProvider.currentTime();
|
||||
}
|
||||
updateReplicationState(timestamp, mh.m().identifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void updatedReplicationStateOnAbsentEntry() {
|
||||
if (!ru.replicationUpdateInit()) {
|
||||
s.innerWriteLock.lock();
|
||||
updateReplicationState(mh.m().timeProvider.currentTime(), mh.m().identifier());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void relocation(Data<V> newValue, long newSizeOfEverythingBeforeValue) {
|
||||
long oldPos = pos;
|
||||
super.relocation(newValue, newSizeOfEverythingBeforeValue);
|
||||
ru.moveChange(oldPos, pos);
|
||||
}
|
||||
|
||||
private boolean testTimeStampInSensibleRange() {
|
||||
if (mh.m().timeProvider == TimeProvider.SYSTEM) {
|
||||
long currentTime = TimeProvider.SYSTEM.currentTime();
|
||||
assert Math.abs(currentTime - timestamp()) <= 100000000 :
|
||||
"unrealistic timestamp: " + timestamp();
|
||||
assert Math.abs(currentTime - ru.innerRemoteTimestamp) <= 100000000 :
|
||||
"unrealistic innerRemoteTimestamp: " + ru.innerRemoteTimestamp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
long sizeOfEverythingBeforeValue(long keySize, long valueSize) {
|
||||
return super.sizeOfEverythingBeforeValue(keySize, valueSize) + ADDITIONAL_ENTRY_BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValueDeletedEntry(Data<V> newValue) {
|
||||
throw new AssertionError("Replicated Map doesn't remove entries truly, yet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.input;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class MapInputBytesValues {
|
||||
|
||||
@StageRef HashInputBytes in;
|
||||
@StageRef VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
|
||||
@Stage("FirstInputValueOffsets") public long firstInputValueSize = -1;
|
||||
@Stage("FirstInputValueOffsets") public long firstInputValueOffset;
|
||||
|
||||
private void initFirstInputValueOffsets() {
|
||||
in.inputBytes.position(in.inputKeyOffset + in.inputKeySize);
|
||||
firstInputValueSize = mh.m().valueSizeMarshaller.readSize(in.inputBytes);
|
||||
firstInputValueOffset = in.inputBytes.position();
|
||||
}
|
||||
|
||||
@Stage("SecondInputValueOffsets") public long secondInputValueSize = -1;
|
||||
@Stage("SecondInputValueOffsets") public long secondInputValueOffset;
|
||||
|
||||
private void initSecondInputValueOffsets() {
|
||||
in.inputBytes.position(firstInputValueOffset + firstInputValueSize);
|
||||
secondInputValueSize = mh.m().valueSizeMarshaller.readSize(in.inputBytes);
|
||||
secondInputValueOffset = in.inputBytes.position();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package net.openhft.chronicle.map.impl.stage.input;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.JavaLangBytesReusableBytesStore;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.LogHolder;
|
||||
import net.openhft.chronicle.hash.replication.RemoteOperationContext;
|
||||
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.ReplicatedInputKeyBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.ReplicatedInputValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.query.ReplicatedMapQuery;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteQueryContext;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicatedInput<K, V, R>
|
||||
implements RemoteOperationContext<K>, MapRemoteQueryContext<K, V, R> {
|
||||
|
||||
@StageRef ReplicatedChronicleMapHolder<K, ?, ?, V, ?, ?, R> mh;
|
||||
@StageRef ReplicationUpdate<K> ru;
|
||||
@StageRef LogHolder lh;
|
||||
@StageRef ReplicatedInputKeyBytesData<K> replicatedInputKeyBytesValue;
|
||||
@StageRef ReplicatedInputValueBytesData<V> replicatedInputValueBytesValue;
|
||||
@StageRef ReplicatedMapQuery<K, V, ?> q;
|
||||
@StageRef SegmentStages s;
|
||||
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
|
||||
@StageRef DummyValueZeroData<V> dummyValue;
|
||||
|
||||
@Override
|
||||
public Data<V> dummyZeroValue() {
|
||||
return dummyValue;
|
||||
}
|
||||
|
||||
public Bytes replicatedInputBytes = null;
|
||||
public final JavaLangBytesReusableBytesStore replicatedInputStore =
|
||||
new JavaLangBytesReusableBytesStore();
|
||||
|
||||
public void initReplicatedInputBytes(Bytes replicatedInputBytes) {
|
||||
this.replicatedInputBytes = replicatedInputBytes;
|
||||
replicatedInputStore.setBytes(replicatedInputBytes);
|
||||
}
|
||||
|
||||
@Stage("ReplicationInput") public long riKeySize = -1;
|
||||
@Stage("ReplicationInput") public long riValueSize;
|
||||
|
||||
@Stage("ReplicationInput") public long riKeyOffset;
|
||||
@Stage("ReplicationInput") public long riValueOffset;
|
||||
|
||||
@Stage("ReplicationInput") public long riTimestamp;
|
||||
@Stage("ReplicationInput") public byte riId;
|
||||
@Stage("ReplicationInput") public boolean isDeleted;
|
||||
|
||||
|
||||
public void initReplicationInput(Bytes replicatedInputBytes) {
|
||||
initReplicatedInputBytes(replicatedInputBytes);
|
||||
riKeySize = mh.m().keySizeMarshaller.readSize(replicatedInputBytes);
|
||||
riValueSize = mh.m().valueSizeMarshaller.readSize(replicatedInputBytes);
|
||||
|
||||
riTimestamp = replicatedInputBytes.readStopBit();
|
||||
riId = replicatedInputBytes.readByte();
|
||||
ru.initReplicationUpdate(riTimestamp, riId);
|
||||
|
||||
isDeleted = replicatedInputBytes.readBoolean();
|
||||
|
||||
riKeyOffset = replicatedInputBytes.position();
|
||||
riValueOffset = riKeyOffset + riKeySize;
|
||||
}
|
||||
|
||||
public void processReplicatedEvent() {
|
||||
if (riId == mh.m().identifier()) {
|
||||
// this may occur when working with UDP, as we may receive our own data
|
||||
return;
|
||||
}
|
||||
|
||||
q.initInputKey(replicatedInputKeyBytesValue);
|
||||
|
||||
boolean debugEnabled = lh.LOG.isDebugEnabled();
|
||||
|
||||
s.innerUpdateLock.lock();
|
||||
if (isDeleted) {
|
||||
if (debugEnabled) {
|
||||
lh.LOG.debug("READING FROM SOURCE - into local-id={}, remote={}, remove(key={})",
|
||||
mh.m().identifier(), riId, q.inputKey);
|
||||
}
|
||||
mh.m().remoteOperations.remove(this);
|
||||
mh.m().setLastModificationTime(riId, riTimestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
String message = null;
|
||||
if (debugEnabled) {
|
||||
message = String.format(
|
||||
"READING FROM SOURCE - into local-id=%d, remote-id=%d, put(key=%s,",
|
||||
mh.m().identifier(), riId, q.inputKey);
|
||||
}
|
||||
|
||||
|
||||
mh.m().remoteOperations.put(this, replicatedInputValueBytesValue);
|
||||
mh.m().setLastModificationTime(riId, riTimestamp);
|
||||
|
||||
if (debugEnabled) {
|
||||
lh.LOG.debug(message + "value=" + replicatedInputValueBytesValue + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package net.openhft.chronicle.map.impl.stage.iter;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.locks.InterProcessLock;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class DeprecatedMapKeyContextOnIteration<K, V> implements MapKeyContext<K, V> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef SegmentStages s;
|
||||
@StageRef MapSegmentIteration<K, V> it;
|
||||
@StageRef MapEntryOperationsDelegation<K, V, ?> ops;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
|
||||
@Override
|
||||
public long valueOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long valueSize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valueEqualTo(V value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return Data.bytesEquivalent(e.entryValue, it.context().wrapValueAsValue(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.value().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.value().getUsing(usingValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean put(V newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
ops.replaceValue(it, it.context().wrapValueAsValue(newValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K key() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.key().get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Bytes entry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.entryBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keyOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keyOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keySize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
ops.remove(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("close() is not supported during iteration");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock readLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock updateLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock writeLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private UnsupportedOperationException unsupportedLocks() {
|
||||
return new UnsupportedOperationException(
|
||||
"Lock operations are not supported (and not needed!) during iteration");
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.iter;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class IterationCheckOnEachPublicOperation extends CheckOnEachPublicOperation {
|
||||
|
||||
@StageRef MapSegmentIteration<?, ?> iteration;
|
||||
|
||||
@Override
|
||||
public void checkOnEachPublicOperation() {
|
||||
super.checkOnEachPublicOperation();
|
||||
iteration.checkEntryNotRemovedOnThisIteration();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.iter;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.iter.HashSegmentIteration;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.impl.IterationContextInterface;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class MapSegmentIteration<K, V> extends HashSegmentIteration<K, MapEntry<K, V>>
|
||||
implements MapEntry<K, V>, IterationContextInterface<K, V> {
|
||||
|
||||
@StageRef MapEntryStages<K, V> entry;
|
||||
@StageRef public DeprecatedMapKeyContextOnIteration<K, V> deprecatedMapKeyContextOnIteration;
|
||||
@StageRef WrappedValueInstanceValueHolder<K, V, ?> wrappedValueInstanceValueHolder;
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapContext<K, V, ?> context() {
|
||||
return wrappedValueInstanceValueHolder;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package net.openhft.chronicle.map.impl.stage.iter;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.replication.ReplicableEntry;
|
||||
import net.openhft.chronicle.map.impl.ReplicatedIterationContextInterface;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicatedMapSegmentIteration<K, V> extends MapSegmentIteration<K, V>
|
||||
implements ReplicatedIterationContextInterface<K, V>, ReplicableEntry {
|
||||
|
||||
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
|
||||
@StageRef ReplicationUpdate<K> ru;
|
||||
@StageRef DummyValueZeroData<V> dummyValue;
|
||||
|
||||
@Override
|
||||
public boolean entryIsPresent() {
|
||||
return !e.entryDeleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachReplicableEntry(Consumer<? super ReplicableEntry> action) {
|
||||
s.innerUpdateLock.lock();
|
||||
try {
|
||||
long entries = s.entries();
|
||||
if (entries == 0)
|
||||
return;
|
||||
long startPos = 0L;
|
||||
while (!hashLookup.empty(hashLookup.readEntry(startPos))) {
|
||||
startPos = hashLookup.step(startPos);
|
||||
}
|
||||
hlp.initHashLookupPos(startPos);
|
||||
do {
|
||||
hlp.setHashLookupPos(hashLookup.step(hlp.hashLookupPos));
|
||||
long entry = hashLookup.readEntry(hlp.hashLookupPos);
|
||||
if (!hashLookup.empty(entry)) {
|
||||
e.readExistingEntry(hashLookup.value(entry));
|
||||
action.accept(this);
|
||||
if (--entries == 0)
|
||||
break;
|
||||
}
|
||||
} while (hlp.hashLookupPos != startPos);
|
||||
} finally {
|
||||
s.innerReadLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void doRemove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
initEntryRemovedOnThisIteration(true);
|
||||
try {
|
||||
if (e.valueSize > dummyValue.size())
|
||||
e.innerDefaultReplaceValue(dummyValue);
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.writeEntryDeleted();
|
||||
ru.updateChange();
|
||||
s.deleted(s.deleted() + 1);
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package net.openhft.chronicle.map.impl.stage.map;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class MapEntryOperationsDelegation<K, V, R> implements MapContext<K, V, R> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, R> mh;
|
||||
|
||||
|
||||
@Override
|
||||
public R replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return mh.m().entryOperations.replaceValue(entry, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R remove(@NotNull MapEntry<K, V> entry) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return mh.m().entryOperations.remove(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data<V> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return mh.m().entryOperations.defaultValue(absentEntry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V> value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return mh.m().entryOperations.insert(absentEntry, value);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.map;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ReplicatedChronicleMap;
|
||||
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class ReplicatedChronicleMapHolderImpl<
|
||||
K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
V, VI, MVI extends MetaBytesInterop<V, ? super VI>, R
|
||||
>
|
||||
extends Chaining
|
||||
implements ReplicatedChronicleMapHolder<K, KI, MKI, V, VI, MVI, R> {
|
||||
|
||||
private final ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R> m;
|
||||
|
||||
public ReplicatedChronicleMapHolderImpl(ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R> m) {
|
||||
super();
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public ReplicatedChronicleMapHolderImpl(ReplicatedChronicleMapHolderImpl c) {
|
||||
super(c);
|
||||
this.m = (ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R>) c.m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chaining createChaining() {
|
||||
return new ReplicatedChronicleMapHolderImpl(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R> m() {
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMap<K, V> map() {
|
||||
return m();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.map;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class ValueBytesInterop<V, VI, MVI extends MetaBytesInterop<V, ? super VI>> {
|
||||
@StageRef VanillaChronicleMapHolder<?, ?, ?, V, VI, MVI, ?> mh;
|
||||
@StageRef ThreadLocalCopiesHolder ch;
|
||||
|
||||
public final BytesReader<V> valueReader =
|
||||
mh.m().valueReaderProvider.get(ch.copies, mh.m().originalValueReader);
|
||||
public final VI valueInterop =
|
||||
mh.m().valueInteropProvider.get(ch.copies, mh.m().originalValueInterop);
|
||||
|
||||
public MVI valueMetaInterop(V value) {
|
||||
return mh.m().metaValueInteropProvider.get(
|
||||
ch.copies, mh.m().originalMetaValueInterop, valueInterop, value);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.map;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.VanillaChronicleMap;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class VanillaChronicleMapHolderImpl<
|
||||
K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
V, VI, MVI extends MetaBytesInterop<V, ? super VI>, R
|
||||
>
|
||||
extends Chaining
|
||||
implements VanillaChronicleMapHolder<K, KI, MKI, V, VI, MVI, R> {
|
||||
|
||||
private final VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R> m;
|
||||
|
||||
public VanillaChronicleMapHolderImpl(VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R> m) {
|
||||
super();
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public VanillaChronicleMapHolderImpl(VanillaChronicleMapHolderImpl c) {
|
||||
super(c);
|
||||
this.m = (VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R>) c.m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chaining createChaining() {
|
||||
return new VanillaChronicleMapHolderImpl(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R> m() {
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMap<K, V> map() {
|
||||
return m();
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package net.openhft.chronicle.map.impl.stage.map;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public abstract class WrappedValueInstanceValueHolder<K, V, R> implements MapContext<K, V, R> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef WrappedValueInstanceData<V, ?, ?> wrappedValueInstanceValue;
|
||||
|
||||
|
||||
@Override
|
||||
public Data<V> wrapValueAsValue(V value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
WrappedValueInstanceData<V, ?, ?> wrapped = this.wrappedValueInstanceValue;
|
||||
wrapped = wrapped.getUnusedWrappedValue();
|
||||
wrapped.initValue(value);
|
||||
return wrapped;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.locks.InterProcessLock;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class DeprecatedMapAcquireContextOnQuery<K, V> implements MapKeyContext<K, V> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
@StageRef UsingReturnValue<V> usingReturn;
|
||||
|
||||
@Override
|
||||
public long valueOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long valueSize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valueEqualTo(V value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return Data.bytesEquivalent(e.entryValue, q.wrapValueAsValue(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
assert containsKey();
|
||||
return usingReturn.returnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
return containsKey() ? q.value().getUsing(usingValue) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean put(V newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
updateLock().lock();
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
q.replaceValue(entry, q.wrapValueAsValue(newValue));
|
||||
} else {
|
||||
q.insert(q.absentEntry(), q.wrapValueAsValue(newValue));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K key() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.queriedKey().get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Bytes entry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.entryBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keyOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keyOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keySize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.entry() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
updateLock().lock();
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
q.remove(entry);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
put(usingReturn.returnValue());
|
||||
q.close();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock readLock() {
|
||||
return q.readLock();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock updateLock() {
|
||||
return q.updateLock();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock writeLock() {
|
||||
return q.writeLock();
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.locks.InterProcessLock;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class DeprecatedMapKeyContextOnQuery<K, V> implements MapKeyContext<K, V> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
|
||||
@Override
|
||||
public long valueOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long valueSize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valueEqualTo(V value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return Data.bytesEquivalent(e.entryValue, q.wrapValueAsValue(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
return containsKey() ? q.value().get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
return containsKey() ? q.value().getUsing(usingValue) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean put(V newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
updateLock().lock();
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
q.replaceValue(entry, q.wrapValueAsValue(newValue));
|
||||
} else {
|
||||
q.insert(q.absentEntry(), q.wrapValueAsValue(newValue));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K key() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.queriedKey().get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Bytes entry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.entryBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keyOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keyOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keySize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.entry() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
updateLock().lock();
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
q.remove(entry);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
q.close();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock readLock() {
|
||||
return q.readLock();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock updateLock() {
|
||||
return q.updateLock();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock writeLock() {
|
||||
return q.writeLock();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.openhft.chronicle.hash.impl.stage.query.HashQuery.SearchState.PRESENT;
|
||||
|
||||
@Staged
|
||||
public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
|
||||
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef public HashLookupSearch hashLookupSearch;
|
||||
@StageRef public CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef public SegmentStages s;
|
||||
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, ?> mh;
|
||||
@StageRef public DeprecatedMapKeyContextOnQuery<K, V> deprecatedMapKeyContext;
|
||||
|
||||
void putEntry(Data<V> value) {
|
||||
assert q.searchStateAbsent();
|
||||
long entrySize = e.entrySize(q.inputKey.size(), value.size());
|
||||
q.allocatedChunks.initEntryAndKey(entrySize);
|
||||
e.initValue(value);
|
||||
e.freeExtraAllocatedChunks();
|
||||
hashLookupSearch.putNewVolatile(e.pos);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapContext<K, V, ?> context() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<K> absentKey() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.inputKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInsert(Data<V> value) {
|
||||
q.putPrefix();
|
||||
if (!q.searchStatePresent()) {
|
||||
if (q.searchStateDeleted()) {
|
||||
e.putValueDeletedEntry(value);
|
||||
} else {
|
||||
putEntry(value);
|
||||
}
|
||||
s.incrementModCount();
|
||||
q.setSearchState(PRESENT);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Entry is present in the map when doInsert() is called");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<V> defaultValue() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return q.wrapValueAsValue(mh.m().defaultValue(deprecatedMapKeyContext));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.impl.MapAbsentEntryHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class MapAbsentHolder<K, V> implements MapAbsentEntryHolder<K, V> {
|
||||
|
||||
@StageRef MapAbsent<K, V> ab;
|
||||
|
||||
@Override
|
||||
public MapAbsentEntry<K, V> absent() {
|
||||
return ab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashQuery;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
|
||||
import net.openhft.chronicle.map.ExternalMapQueryContext;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.impl.MapAbsentEntryHolder;
|
||||
import net.openhft.chronicle.map.impl.QueryContextInterface;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.InputFirstValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.InputSecondValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.InputValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.DefaultReturnValue;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.openhft.chronicle.hash.impl.stage.query.HashQuery.SearchState.PRESENT;
|
||||
|
||||
@Staged
|
||||
public abstract class MapQuery<K, V, R> extends HashQuery<K>
|
||||
implements MapEntry<K, V>, ExternalMapQueryContext<K, V, R>,
|
||||
QueryContextInterface<K, V, R> {
|
||||
|
||||
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, R> mh;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef SearchAllocatedChunks allocatedChunks;
|
||||
@StageRef public DeprecatedMapKeyContextOnQuery<K, V> deprecatedMapKeyContext;
|
||||
@StageRef public DeprecatedMapAcquireContextOnQuery<K, V> deprecatedMapAcquireContext;
|
||||
|
||||
@StageRef public InputValueInstanceData<V, ?, ?> inputValueInstanceValue;
|
||||
|
||||
@StageRef public InputFirstValueBytesData<V> inputFirstValueBytesValue;
|
||||
@StageRef public InputSecondValueBytesData<V> inputSecondValueBytesValue;
|
||||
|
||||
@StageRef public DefaultReturnValue<V> defaultReturnValue;
|
||||
@StageRef public UsingReturnValue<V> usingReturnValue;
|
||||
|
||||
@StageRef public MapAbsentEntryHolder<K, V> absent;
|
||||
|
||||
@Override
|
||||
public MapEntry<K, V> entry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entryPresent() ? this : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MapAbsentEntry<K, V> absentEntry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entryPresent() ? null : absent.absent();
|
||||
}
|
||||
|
||||
protected void putPrefix() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
boolean underUpdatedLockIsHeld = !s.innerUpdateLock.isHeldByCurrentThread();
|
||||
if (underUpdatedLockIsHeld)
|
||||
s.innerUpdateLock.lock();
|
||||
boolean searchResultsNotTrusted = underUpdatedLockIsHeld ||
|
||||
s.concurrentSameThreadContexts;
|
||||
if (hlp.hashLookupPosInit() && searchStateAbsent() && searchResultsNotTrusted)
|
||||
hlp.closeHashLookupPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
putPrefix();
|
||||
if (searchStatePresent()) {
|
||||
e.innerDefaultReplaceValue(newValue);
|
||||
s.incrementModCount();
|
||||
setSearchState(PRESENT);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Entry is absent in the map when doReplaceValue() is called");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapContext<K, V, ?> context() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashQuery;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class QueryCheckOnEachPublicOperation extends CheckOnEachPublicOperation {
|
||||
|
||||
@StageRef HashQuery q;
|
||||
|
||||
@Override
|
||||
public void checkOnEachPublicOperation() {
|
||||
super.checkOnEachPublicOperation();
|
||||
q.dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashQuery;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
|
||||
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
|
||||
@StageRef ReplicationUpdate<K> ru;
|
||||
|
||||
@Override
|
||||
public void doInsert(Data<V> value) {
|
||||
q.putPrefix();
|
||||
if (!q.entryPresent()) {
|
||||
if (!q.searchStatePresent()) {
|
||||
putEntry(value);
|
||||
q.setSearchState(HashQuery.SearchState.PRESENT);
|
||||
} else {
|
||||
e.innerDefaultReplaceValue(value);
|
||||
s.deleted(s.deleted() - 1);
|
||||
}
|
||||
s.incrementModCount();
|
||||
e.writeEntryPresent();
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnAbsentEntry();
|
||||
} else {
|
||||
throw new IllegalStateException("Entry is absent in the map when doInsert() is called");
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class ReplicatedMapAbsentDelegating<K, V> implements MapAbsentEntry<K, V> {
|
||||
|
||||
@StageRef ReplicatedMapAbsent<K, V> delegate;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapContext<K, V, ?> context() {
|
||||
return delegate.context();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInsert(Data<V> value) {
|
||||
delegate.doInsert(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<V> defaultValue() {
|
||||
return delegate.defaultValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<K> absentKey() {
|
||||
return delegate.absentKey();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.impl.MapAbsentEntryHolder;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public class ReplicatedMapAbsentHolder<K, V> implements MapAbsentEntryHolder<K, V> {
|
||||
|
||||
@StageRef ReplicatedMapAbsent<K, V> ab;
|
||||
|
||||
@Override
|
||||
public MapAbsentEntry<K, V> absent() {
|
||||
return ab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.chronicle.map.impl.stage.ret.BytesReturnValue;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteQueryContext;
|
||||
import net.openhft.chronicle.map.replication.MapReplicableEntry;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
|
||||
implements MapRemoteQueryContext<K, V, R> {
|
||||
|
||||
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
|
||||
@StageRef ReplicationUpdate ru;
|
||||
|
||||
@StageRef BytesReturnValue<V> bytesReturnValue;
|
||||
|
||||
@StageRef ReplicatedMapAbsentDelegating<K, V> absentDelegating;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MapAbsentEntry<K, V> absentEntry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
if (entryPresent()) {
|
||||
return null;
|
||||
} else {
|
||||
if (!searchStatePresent()) {
|
||||
return absentDelegating;
|
||||
} else {
|
||||
assert e.entryDeleted();
|
||||
return absent.absent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean entryPresent() {
|
||||
return super.entryPresent() && !e.entryDeleted();
|
||||
}
|
||||
|
||||
@StageRef DummyValueZeroData<V> dummyValue;
|
||||
|
||||
@Override
|
||||
public MapReplicableEntry<K, V> entry() {
|
||||
return (MapReplicableEntry<K, V>) super.entry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRemove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerUpdateLock.lock();
|
||||
if (entryPresent()) {
|
||||
if (e.valueSize > dummyValue.size())
|
||||
e.innerDefaultReplaceValue(dummyValue);
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.writeEntryDeleted();
|
||||
ru.updateChange();
|
||||
s.deleted(s.deleted() + 1);
|
||||
} else {
|
||||
throw new IllegalStateException("Entry is absent in the map when doRemove() is called");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
super.doReplaceValue(newValue);
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map.impl.stage.replication;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.replication.RemoteOperationContext;
|
||||
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicationUpdate<K> implements RemoteOperationContext<K> {
|
||||
@StageRef SegmentStages s;
|
||||
@StageRef ReplicatedMapEntryStages<K, ?, ?> e;
|
||||
@StageRef ReplicatedChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
|
||||
@Stage("ReplicationUpdate") public long innerRemoteTimestamp;
|
||||
@Stage("ReplicationUpdate") public byte innerRemoteIdentifier = (byte) 0;
|
||||
|
||||
public abstract boolean replicationUpdateInit();
|
||||
|
||||
public void initReplicationUpdate(long timestamp, byte identifier) {
|
||||
innerRemoteTimestamp = timestamp;
|
||||
if (identifier == 0)
|
||||
throw new IllegalStateException("identifier can't be 0");
|
||||
innerRemoteIdentifier = identifier;
|
||||
}
|
||||
|
||||
public void dropChange() {
|
||||
mh.m().dropChange(s.segmentIndex, e.pos);
|
||||
}
|
||||
|
||||
public void moveChange(long oldPos, long newPos) {
|
||||
mh.m().moveChange(s.segmentIndex, oldPos, newPos);
|
||||
}
|
||||
|
||||
public void updateChange() {
|
||||
if (!replicationUpdateInit()) {
|
||||
raiseChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void raiseChange() {
|
||||
mh.m().raiseChange(s.segmentIndex, e.pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long remoteTimestamp() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return innerRemoteTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte remoteIdentifier() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return innerRemoteIdentifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.openhft.chronicle.map.impl.stage.ret;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.JavaLangBytesReusableBytesStore;
|
||||
import net.openhft.chronicle.map.ReturnValue;
|
||||
import net.openhft.chronicle.map.TcpReplicator.TcpSocketChannelEntryWriter;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.Stage;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class BytesReturnValue<V> implements ReturnValue<V>, AutoCloseable {
|
||||
|
||||
@StageRef
|
||||
VanillaChronicleMapHolder<?, ?, ?, V, ?, ?, ?> mh;
|
||||
|
||||
private final JavaLangBytesReusableBytesStore outputStore =
|
||||
new JavaLangBytesReusableBytesStore();
|
||||
|
||||
@Stage("Output") TcpSocketChannelEntryWriter output = null;
|
||||
@Stage("Output") long startOutputPos;
|
||||
|
||||
public void initOutput(TcpSocketChannelEntryWriter output) {
|
||||
this.output = output;
|
||||
startOutputPos = output.in().position();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnValue(@NotNull Data<V> value) {
|
||||
long valueSize = value.size();
|
||||
long totalSize = 1L + mh.m().valueSizeMarshaller.sizeEncodingSize(valueSize) + valueSize;
|
||||
output.ensureBufferSize(totalSize);
|
||||
Bytes out = output.in();
|
||||
out.writeBoolean(false);
|
||||
mh.m().valueSizeMarshaller.writeSize(out, valueSize);
|
||||
long outPosition = out.position();
|
||||
out.skip(valueSize);
|
||||
outputStore.setBytes(out);
|
||||
value.writeTo(outputStore, outPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (output.in().position() == startOutputPos) {
|
||||
output.ensureBufferSize(1L);
|
||||
output.in().writeBoolean(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.openhft.chronicle.map.impl.stage.ret;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class DefaultReturnValue<V> implements InstanceReturnValue<V> {
|
||||
private V defaultReturnedValue = null;
|
||||
|
||||
abstract boolean defaultReturnedValueInit();
|
||||
|
||||
private void initDefaultReturnedValue(@NotNull Data<V> value) {
|
||||
defaultReturnedValue = value.getUsing(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnValue(@NotNull Data<V> value) {
|
||||
initDefaultReturnedValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V returnValue() {
|
||||
if (defaultReturnedValueInit()) {
|
||||
return defaultReturnedValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.openhft.chronicle.map.impl.stage.ret;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.map.impl.ret.UsableReturnValue;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class UsingReturnValue<V> implements UsableReturnValue<V> {
|
||||
|
||||
private V usingReturnValue = (V) USING_RETURN_VALUE_UNINT;
|
||||
|
||||
@Override
|
||||
public void initUsingReturnValue(V usingReturnValue) {
|
||||
this.usingReturnValue = usingReturnValue;
|
||||
}
|
||||
|
||||
private V returnedValue = null;
|
||||
|
||||
abstract boolean returnedValueInit();
|
||||
|
||||
private void initReturnedValue(@NotNull Data<V> value) {
|
||||
returnedValue = value.getUsing(usingReturnValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnValue(@NotNull Data<V> value) {
|
||||
initReturnedValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V returnValue() {
|
||||
if (returnedValueInit()) {
|
||||
return returnedValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user