Merge branch '2.1' of github.com:OpenHFT/Chronicle-Map into 2.1

This commit is contained in:
Rob Austin
2015-02-05 18:52:08 +00:00
6 changed files with 52 additions and 33 deletions
+1 -1
View File
@@ -53,7 +53,7 @@
<dependency>
<groupId>net.openhft</groupId>
<artifactId>affinity</artifactId>
<version>2.1.4</version>
<version>2.2</version>
</dependency>
<dependency>
@@ -28,7 +28,7 @@ import java.io.Serializable;
public abstract class CopyingMetaBytesInterop<E, W> extends BasicCopyingMetaBytesInterop<E, W> {
private static final long serialVersionUID = 1L;
private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(512L);
private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(16L);
public static void checkMaxSizeStillReasonable(long maxSize, Exception ex) {
if (maxSize > MAX_REASONABLE_SERIALIZED_SIZE) {
@@ -34,7 +34,7 @@ public abstract class DataValueMetaBytesInterop<E>
}
void init(BytesWriter<E> writer, E e, long size) {
Bytes buffer = this.buffer.obtain(size, false);
Bytes buffer = this.buffer.obtain(size, true);
writer.write(buffer, e);
buffer.flip();
assert buffer.remaining() == size;
@@ -17,7 +17,6 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.lang.io.BoundsCheckingNativeBytes;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.DirectBytes;
import net.openhft.lang.io.DirectStore;
@@ -34,7 +33,6 @@ class DirectBytesBuffer
private static final long serialVersionUID = 0L;
private final Serializable identity;
transient DirectBytes buffer;
transient BoundsCheckingNativeBytes checkingBuffer;
transient ForBytesMarshaller forBytesMarshaller;
transient ForBytesWriter forBytesWriter;
@@ -60,29 +58,16 @@ class DirectBytesBuffer
DirectBytes buf;
if ((buf = buffer) != null) {
if (maxSize <= buf.capacity()) {
if (!boundsChecking)
return buf.clear();
Bytes checkingBuf;
if ((checkingBuf = checkingBuffer) != null) {
return checkingBuf.clear();
} else {
return (checkingBuffer = new BoundsCheckingNativeBytes(buf)).clear();
}
return buf.clear();
} else {
DirectStore store = (DirectStore) buf.store();
store.resize(maxSize, true);
buf = buffer = store.bytes();
if (!boundsChecking)
return buf;
return (checkingBuffer = new BoundsCheckingNativeBytes(buf));
store.resize(maxSize, false);
return buffer = store.bytes();
}
} else {
buf = buffer = new DirectStore(JDKObjectSerializer.INSTANCE,
// don't allocate 0 bytes
Math.max(1, maxSize), true).bytes();
if (!boundsChecking)
return buf;
return (checkingBuffer = new BoundsCheckingNativeBytes(buf));
buffer = new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, maxSize), true)
.bytes();
return buffer;
}
}
@@ -140,7 +125,7 @@ class DirectBytesBuffer
this.writer = writer;
cur = e;
long size = writer.size(e);
Bytes buffer = this.buffer.obtain(size, false);
Bytes buffer = this.buffer.obtain(size, true);
writer.write(buffer, e);
buffer.flip();
this.size = size;
@@ -34,9 +34,7 @@ import net.openhft.lang.threadlocal.ThreadLocalCopies;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Externalizable;
import java.io.IOException;
import java.io.Serializable;
import java.io.*;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -50,6 +48,7 @@ import static net.openhft.chronicle.hash.serialization.SizeMarshallers.stopBit;
import static net.openhft.chronicle.map.Objects.hash;
final class SerializationBuilder<E> implements Cloneable, Serializable {
private static final long serialVersionUID = 0L;
private static final Bytes EMPTY_BYTES = new ByteBufferBytes(ByteBuffer.allocate(0));
@@ -88,6 +87,8 @@ final class SerializationBuilder<E> implements Cloneable, Serializable {
private long maxSize;
final boolean sizeIsStaticallyKnown;
boolean serializesGeneratedClasses = false;
@SuppressWarnings("unchecked")
SerializationBuilder(Class<E> eClass, Role role) {
@@ -112,10 +113,12 @@ final class SerializationBuilder<E> implements Cloneable, Serializable {
metaInterop((MetaBytesInterop<E, ?>) DataValueMetaBytesInterop.forIdentity(role));
metaInteropProvider(DataValueMetaBytesInterop.interopProvider(eClass));
sizeMarshaller(constant((long) size));
serializesGeneratedClasses = true;
return;
} catch (Exception e) {
try {
eClass = DataValueClasses.directClassFor(eClass);
serializesGeneratedClasses = true;
} catch (Exception ex) {
// ignore, fall through
}
@@ -173,6 +176,25 @@ final class SerializationBuilder<E> implements Cloneable, Serializable {
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeBoolean(serializesGeneratedClasses);
if (serializesGeneratedClasses) {
out.writeObject(eClass);
out.writeObject(role);
}
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
boolean generatedClassesSerialized = in.readBoolean();
if (generatedClassesSerialized) {
Class eClass = (Class) in.readObject();
Role role = (Role) in.readObject();
new SerializationBuilder(eClass, role);
}
in.defaultReadObject();
}
boolean possibleOffHeapReferences() {
if (reader instanceof CharSequenceReader)
return false;
@@ -50,12 +50,18 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
public long addValue(long $) {
return _bytes.addLong(_offset + VALUE, $);
} public long addAtomicValue(long $) {
}
public long addAtomicValue(long $) {
return _bytes.addAtomicLong(_offset + VALUE, $);
} public boolean compareAndSwapValue(long _1, long _2) {
}
public boolean compareAndSwapValue(long _1, long _2) {
return _bytes.compareAndSwapLong(_offset + VALUE, _1, _2);
} @Override
public void copyFrom(net.openhft.lang.values.LongValue from) {
}
@Override
public void copyFrom(net.openhft.lang.values.LongValue from) {
setValue(from.getValue());
}
@@ -63,27 +69,33 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
public void writeMarshallable(Bytes out) {
out.writeLong(getValue());
}
@Override
public void readMarshallable(Bytes in) {
setValue(in.readLong());
}
@Override
public void bytes(Bytes bytes, long offset) {
this._bytes = bytes;
this._offset = offset;
}
@Override
public Bytes bytes() {
return _bytes;
}
@Override
public long offset() {
return _offset;
}
@Override
public int maxSize() {
return 8;
}
public int hashCode() {
long lhc = longHashCode();
return (int) ((lhc >>> 32) ^ lhc);
@@ -98,7 +110,7 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
if (!(o instanceof LongValue)) return false;
LongValue that = (LongValue) o;
if(!isEqual(getValue(), that.getValue())) return false;
if (!isEqual(getValue(), that.getValue())) return false;
return true;
}