Updated SPI model and added examples

This commit is contained in:
leventov
2015-05-18 13:42:07 +01:00
parent 6c56813b5e
commit 5829cdbfba
10 changed files with 195 additions and 33 deletions
@@ -18,7 +18,6 @@
package net.openhft.chronicle.hash;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.MapEntryOperations;
import org.jetbrains.annotations.NotNull;
@@ -40,14 +39,10 @@ public interface HashEntry<K> {
@NotNull Value<K, ?> key();
/**
* Removes the entry from the {@code ChronicleHash}. Returns {@code true} if the remove was
* successful, {@code false} if it failed for any reason.
*
* <p>This method if the default implementation for {@link MapEntryOperations#remove(MapEntry)},
* which might be customized over the default.
* Removes the entry from the {@code ChronicleHash}.
*
* @throws IllegalStateException if some locking/state conditions required to perform remove
* operation are not met
*/
boolean defaultRemove();
void doRemove();
}
@@ -0,0 +1,32 @@
/*
* 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.hash.replication;
public final class DefaultEventualConsistencyStrategy {
public static boolean shouldApplyRemoteModification(
ReplicatedEntry entry, ReplicationContext context) {
long remoteTimestamp = context.remoteTimestamp();
long originTimestamp = entry.originTimestamp();
return remoteTimestamp > originTimestamp || (remoteTimestamp == originTimestamp &&
context.remoteIdentifier() <= entry.originIdentifier());
}
private DefaultEventualConsistencyStrategy() {}
}
@@ -0,0 +1,26 @@
/*
* 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.hash.replication;
public interface ReplicatedEntry {
byte originIdentifier();
long originTimestamp();
}
@@ -16,7 +16,10 @@
* limitations under the License.
*/
package net.openhft.chronicle.hash;
package net.openhft.chronicle.hash.replication;
import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.HashContext;
/**
* Context of internal replication operation.
@@ -24,4 +27,8 @@ package net.openhft.chronicle.hash;
* @param <K> the key type of accessed {@link ChronicleHash}
*/
public interface ReplicationContext<K> extends HashContext<K> {
byte remoteIdentifier();
long remoteTimestamp();
}