Merge remote-tracking branch 'origin/2.1' into 2.1

This commit is contained in:
Rob Austin
2015-02-02 08:29:32 +00:00
17 changed files with 79 additions and 76 deletions
@@ -65,6 +65,6 @@ public abstract class BasicCopyingMetaBytesInterop<E, W> implements MetaBytesInt
@Override
public void write(W writer, Bytes bytes, E e) {
bytes.write(buffer.buffer);
bytes.write(buffer.buffer, buffer.buffer.position(), buffer.buffer.remaining());
}
}
@@ -44,6 +44,6 @@ public enum BytesBytesInterop implements BytesInterop<Bytes> {
@Override
public void write(Bytes bytes, Bytes e) {
bytes.write(e);
bytes.write(e, e.position(), e.remaining());
}
}
@@ -44,11 +44,13 @@ public abstract class BytesMapEventListener implements Serializable {
// do nothing
}
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) {
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added,
boolean replicationEvent) {
// do nothing
}
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) {
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos,
boolean replicationEvent) {
// do nothing
}
}
@@ -504,7 +504,7 @@ final class ChannelProvider implements Closeable {
@Override
public void writeExternalEntry(@NotNull Bytes entry, @NotNull Bytes destination,
int na) {
destination.write(entry);
destination.write(entry, entry.position(), entry.remaining());
}
@Override
@@ -81,12 +81,12 @@ public abstract class MapEventListener<K, V> implements Serializable {
}
@Override
public void onPut(Object key, Object value, Object replacedValue) {
public void onPut(Object key, Object value, Object replacedValue, boolean replicationEvent) {
LOGGER.info("{} put {} => {}", prefix, key, value);
}
@Override
public void onRemove(Object key, Object value) {
public void onRemove(Object key, Object value, boolean replicationEvent) {
LOGGER.info("{} remove {} was {}", prefix, key, value);
}
}
@@ -112,24 +112,24 @@ public abstract class MapEventListener<K, V> implements Serializable {
* as well.
*
* <p>This method is called when put is already happened.
*
* @param key the key the given value is put for
* @param key the key the given value is put for
* @param newValue the value which is now associated with the given key
* @param replacedValue the value which was replaced by {@code newValue}, {@code null} if the
* key was absent in the map before current {@code ChronicleMap}
* key was absent in the map before current {@code ChronicleMap}
* @param replicationEvent
*/
public void onPut(K key, V newValue, @Nullable V replacedValue) {
public void onPut(K key, V newValue, @Nullable V replacedValue, boolean replicationEvent) {
// do nothing
}
/**
* This is called when an entry is removed. Misses, i. e. when {@code map.remove(key)} is
* called, but key is already absent in the map, are not notified.
*
* @param key the key removed from the map
* @param key the key removed from the map
* @param value the value which was associated with the given key
* @param replicationEvent
*/
public void onRemove(K key, V value) {
public void onRemove(K key, V value, boolean replicationEvent) {
// do nothing
}
}
@@ -21,7 +21,7 @@ package net.openhft.chronicle.map;
import net.openhft.lang.Maths;
import net.openhft.lang.collection.ATSDirectBitSet;
import net.openhft.lang.io.DirectStore;
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.NativeBytesI;
import static net.openhft.lang.Maths.isPowerOf2;
import static net.openhft.lang.MemoryUnit.*;
@@ -39,7 +39,7 @@ enum MultiMapFactory {
}
@Override
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
return new ShortShortMultiMap(bytes, bitSetBytes);
}
},
@@ -50,7 +50,7 @@ enum MultiMapFactory {
}
@Override
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
return new Int24Int24MultiMap(bytes, bitSetBytes);
}
},
@@ -61,7 +61,7 @@ enum MultiMapFactory {
}
@Override
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
return new IntIntMultiMap(bytes, bitSetBytes);
}
};
@@ -104,5 +104,5 @@ enum MultiMapFactory {
public abstract long sizeInBytes(long minCapacity);
public abstract MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes);
public abstract MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes);
}
@@ -755,7 +755,7 @@ class DiscoveryNodeBytesMarshallable implements BytesMarshallable {
return false;
BOOTSTRAP_BYTES.clear();
out.write(BOOTSTRAP_BYTES);
out.write(BOOTSTRAP_BYTES, BOOTSTRAP_BYTES.position(), BOOTSTRAP_BYTES.remaining());
ourProposedIdentifier.writeMarshallable(out);
return true;
@@ -30,7 +30,7 @@ import net.openhft.lang.Maths;
import net.openhft.lang.collection.ATSDirectBitSet;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.MultiStoreBytes;
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.NativeBytesI;
import net.openhft.lang.threadlocal.ThreadLocalCopies;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -126,7 +126,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
@Override
VanillaChronicleMap<K, KI, MKI, V, VI, MVI>.Segment createSegment(
NativeBytes segmentHeader, NativeBytes bytes, int index) {
NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
return new Segment(segmentHeader, bytes, index);
}
@@ -514,7 +514,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
// write the key
entry.position(keyPosition);
entry.limit(keyLimit);
destination.write(entry);
destination.write(entry, entry.position(), entry.remaining());
boolean debugEnabled = LOG.isDebugEnabled();
String message = null;
@@ -539,7 +539,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
// writes the value
entry.limit(entry.position() + valueSize);
destination.write(entry);
destination.write(entry, entry.position(), entry.remaining());
if (debugEnabled) {
LOG.debug(message + "value=" + entry.toString().trim() + ")");
@@ -678,7 +678,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
class Segment extends VanillaChronicleMap<K, KI, MKI, V, VI, MVI>.Segment {
Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
super(segmentHeader, bytes, index);
}
@@ -766,11 +766,11 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
// put callbacks
onPut(this, pos);
if (bytesEventListener != null) {
bytesEventListener.onPut(entry, 0L, metaDataBytes, valuePos, true);
bytesEventListener.onPut(entry, 0L, metaDataBytes, valuePos, true, false);
}
if (eventListener != null) {
V valueInstance = toValue.toInstance(copies, v, valueSize);
eventListener.onPut(keyInstance, valueInstance, null);
eventListener.onPut(keyInstance, valueInstance, null, false);
}
entryCreated(lock);
return v;
@@ -974,10 +974,10 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
onPutMaybeRemote(segmentState.pos, remote);
if (bytesEventListener != null)
bytesEventListener.onPut(entry, 0L, metaDataBytes,
segmentState.valueSizePos, true);
segmentState.valueSizePos, true, remote);
if (eventListener != null)
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), null);
toValue.toInstance(copies, value, valueSize), null, remote);
return resultUnused ? null : readValue.readNull();
}
@@ -993,7 +993,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
* @param identifier the unique identifier relating to this map
* @return true if the entry should not be processed
*/
private boolean shouldIgnore(@NotNull final NativeBytes entry, final long timestamp,
private boolean shouldIgnore(@NotNull final NativeBytesI entry, final long timestamp,
final byte identifier) {
final long lastModifiedTimeStamp = entry.readLong();
@@ -1262,7 +1262,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
hashLookup().forEach(new MultiMap.EntryConsumer() {
@Override
public void accept(long hash, long pos) {
final NativeBytes entry = reuse(tmpBytes, offsetFromPos(pos));
final NativeBytesI entry = reuse(tmpBytes, offsetFromPos(pos));
long keySize = keySizeMarshaller.readSize(entry);
entry.skip(keySize);
@@ -1335,7 +1335,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
Segment segment = (Segment) seg;
final long offset = segment.offsetFromPos(pos);
final NativeBytes entry = segment.reuse(this.entry, offset);
final NativeBytesI entry = segment.reuse(this.entry, offset);
final long keySize = keySizeMarshaller.readSize(entry);
long keyPosition = entry.position();
@@ -1490,7 +1490,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
entryCallback.onBeforeEntry();
final long segmentPos = position & posMask;
final NativeBytes entry =
final NativeBytesI entry =
segment.reuse(tmpBytes, segment.offsetFromPos(segmentPos));
// if the entry should be ignored, we'll move the next entry
@@ -57,8 +57,8 @@ class ReplicationHubFindByName<K> implements FindByName {
// creates a map based on the details that are sent to the map of builders
@Override
public void onPut(CharSequence key, MapInstanceBuilder value,
MapInstanceBuilder replacedValue) {
super.onPut(key, value, replacedValue);
MapInstanceBuilder replacedValue, boolean replicationEvent) {
super.onPut(key, value, replacedValue, replicationEvent);
boolean added = replacedValue == null;
if (!added || value == null)
return;
@@ -230,7 +230,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
final long createMappedStoreAndSegments(BytesStore bytesStore) throws IOException {
this.ms = bytesStore;
// checks the the store has not been closed
// todo remove the CheckedBytesStore before the release
this.ms = new CheckedBytesStore(bytesStore);
onHeaderCreated();
@@ -242,9 +244,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
long segmentSize = segmentSize();
long headerOffset = 0;
for (int i = 0; i < this.segments.length; i++) {
NativeBytes segmentHeader =
(NativeBytes) segmentHeaders.bytes(headerOffset, segmentHeaderSize);
NativeBytes segmentData = (NativeBytes) ms.bytes(offset, segmentSize);
NativeBytesI segmentHeader =
(NativeBytesI) segmentHeaders.bytes(headerOffset, segmentHeaderSize);
NativeBytesI segmentData = (NativeBytesI) ms.bytes(offset, segmentSize);
this.segments[i] = createSegment(segmentHeader, segmentData, i);
headerOffset += segmentHeaderSize;
offset += segmentSize;
@@ -306,7 +308,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
return segmentHeaderSize;
}
Segment createSegment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
Segment createSegment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
return new Segment(segmentHeader, bytes, index);
}
@@ -973,7 +975,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
@Override
public void write(Void writer, Bytes bytes, Bytes value) {
bytes.write(value);
bytes.write(value, value.position(), value.remaining());
}
}
@@ -1411,8 +1413,8 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
*/
static final long LOCK_OFFSET = 0L; // 64-bit
static final long SIZE_OFFSET = LOCK_OFFSET + 8L; // 32-bit
final NativeBytes segmentHeader;
final NativeBytes bytes;
final NativeBytesI segmentHeader;
final NativeBytesI bytes;
final long entriesOffset;
private final int index;
private final SingleThreadedDirectBitSet freeList;
@@ -1426,7 +1428,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
/**
* @param index the index of this segment held by the map
*/
Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
this.segmentHeader = segmentHeader;
this.bytes = bytes;
this.index = index;
@@ -1435,7 +1437,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
hashLookup = createMultiMap(start);
start += CACHE_LINES.align(sizeOfMultiMap() + sizeOfMultiMapBitSet(), BYTES)
* multiMapsPerSegment();
final NativeBytes bsBytes = new NativeBytes(ms.objectSerializer(),
final NativeBytesI bsBytes = new NativeBytes(ms.objectSerializer(),
start,
start + MultiMapFactory.sizeOfBitSetInBytes(actualChunksPerSegment),
null);
@@ -1453,11 +1455,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
private MultiMap createMultiMap(long start) {
final NativeBytes multiMapBytes =
final NativeBytesI multiMapBytes =
new NativeBytes((ObjectSerializer) null, start,
start = start + sizeOfMultiMap(), null);
final NativeBytes sizeOfMultiMapBitSetBytes =
final NativeBytesI sizeOfMultiMapBitSetBytes =
new NativeBytes((ObjectSerializer) null, start,
start + sizeOfMultiMapBitSet(), null);
// multiMapBytes.load();
@@ -1628,7 +1630,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (lockTime > 1e8 && LOG.isInfoEnabled())
LOG.info("Thread took %,d ms to release lock%n", lockTime / 1000000 + "(Was there a GC?)");
LOG.info("Thread took " + lockTime / 1000000 + "ms to release the lock, (Was there a GC?)");
}
@Override
@@ -1769,11 +1771,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
onPut(this, segmentState.pos);
if (bytesEventListener != null) {
long keyPos = metaDataBytes;
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true);
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false);
}
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, v, valueSize), null);
toValue.toInstance(copies, v, valueSize), null, false);
}
return v;
@@ -1877,10 +1879,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
onPut(this, segmentState.pos);
if (bytesEventListener != null)
bytesEventListener.onPut(entry, 0L, metaDataBytes,
segmentState.valueSizePos, true);
segmentState.valueSizePos, true, false);
if (eventListener != null)
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), null);
toValue.toInstance(copies, value, valueSize), null, false);
return resultUnused ? null : readValue.readNull();
}
@@ -1924,10 +1926,10 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// put callbacks
onPutMaybeRemote(segmentState.pos, remote);
if (bytesEventListener != null)
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false);
bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, remote);
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), prevValueInstance);
toValue.toInstance(copies, value, valueSize), prevValueInstance, remote);
}
return resultUnused ? null : prevValue;
@@ -2164,12 +2166,12 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// remove callbacks
onRemoveMaybeRemote(pos, remote);
if (bytesEventListener != null)
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos);
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, remote);
if (eventListener != null) {
V removedValueForEventListener =
toValue.toInstance(copies, removedValue, valueSize);
eventListener.onRemove(toKey.toInstance(copies, key, keySize),
removedValueForEventListener);
removedValueForEventListener, remote);
}
return booleanResult ? Boolean.TRUE : removedValue;
@@ -2303,12 +2305,12 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
onPut(this, segmentState.pos);
if (bytesEventListener != null) {
long keyPos = metaDataBytes;
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true);
bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false);
}
if (eventListener != null)
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, newValue, newValueSize),
toValue.toInstance(copies, prevValue, valueSize));
toValue.toInstance(copies, prevValue, valueSize), false);
return expectedValue == null ? prevValue : Boolean.TRUE;
}
@@ -2574,7 +2576,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// of returnedEntry.getKey(), but it seems rather wasteful to workaround so rare
// case.
final long offset = segment.offsetFromPos(pos);
final NativeBytes entry = segment.reuse(this.entry, offset);
final NativeBytesI entry = segment.reuse(this.entry, offset);
final long keySize = keySizeMarshaller.readSize(entry);
long position = entry.position();
@@ -2583,7 +2585,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
removePresent(segment, pos, entry, keySize, segmentHash, true);
}
final void removePresent(Segment segment, long pos, NativeBytes entry, long keySize,
final void removePresent(Segment segment, long pos, NativeBytesI entry, long keySize,
long segmentHash, boolean removeFromMultiMap) {
entry.skip(keySize);
segment.manageReplicationBytes(entry, true, true);
@@ -2601,9 +2603,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
// remove callbacks
onRemove(segment, pos);
if (bytesEventListener != null)
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos);
bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, false);
if (eventListener != null)
eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue());
eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue(), false);
}
}