mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Reduce line padding.
This commit is contained in:
@@ -27,10 +27,12 @@ public final class Hasher {
|
||||
// https://github.com/google/guava/blob/fa95e381e665d8ee9639543b99ed38020c8de5ef
|
||||
// /guava/src/com/google/common/hash/Murmur3_128HashFunction.java
|
||||
|
||||
|
||||
private static final long C1 = 0x87c37b91114253d5L;
|
||||
private static final long C2 = 0x4cf5ad432745937fL;
|
||||
|
||||
private Hasher() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code for {@code len} continuous bytes of the given {@code input} object,
|
||||
* starting from the given offset. The abstraction of input as ordered byte sequence and
|
||||
@@ -134,7 +136,6 @@ public final class Hasher {
|
||||
return h1;
|
||||
}
|
||||
|
||||
|
||||
private static long fmix64(long k) {
|
||||
k ^= k >>> 33;
|
||||
k *= 0xff51afd7ed558ccdL;
|
||||
@@ -187,6 +188,4 @@ public final class Hasher {
|
||||
long h2 = 0L;
|
||||
return finalize(8L, h1, h2);
|
||||
}
|
||||
|
||||
private Hasher() {}
|
||||
}
|
||||
|
||||
@@ -128,8 +128,6 @@ public abstract class AbstractReplication implements Serializable {
|
||||
return engineReplicationLangBytesConsumer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
public B tcpTransportAndNetwork(@Nullable TcpTransportAndNetworkConfig tcpConfig) {
|
||||
this.tcpConfig = tcpConfig;
|
||||
@@ -156,14 +154,12 @@ public abstract class AbstractReplication implements Serializable {
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public B connectionListener(@Nullable ConnectionListener connectionListener) {
|
||||
this.connectionListener = connectionListener;
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configures if the node, provided with replication, created by this builder, should
|
||||
* replicate only local data, last updated with own identifier, or all data currently
|
||||
@@ -185,7 +181,6 @@ public abstract class AbstractReplication implements Serializable {
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Replication instance with the given node (server) identifier.
|
||||
*
|
||||
|
||||
@@ -29,7 +29,6 @@ public interface ConnectionListener {
|
||||
*/
|
||||
void onConnect(SocketAddress address, byte identifier, boolean isServer);
|
||||
|
||||
|
||||
/**
|
||||
* @param address the address that we have been disconnected from
|
||||
* @param identifier the identifer the address that we have been disconnected from or Byte
|
||||
@@ -37,5 +36,4 @@ public interface ConnectionListener {
|
||||
*/
|
||||
void onDisconnect(SocketAddress address, byte identifier);
|
||||
|
||||
|
||||
}
|
||||
@@ -51,6 +51,14 @@ import java.util.Arrays;
|
||||
*/
|
||||
public final class ReplicationHub extends AbstractReplication {
|
||||
|
||||
private final ReplicationChannel[] channels;
|
||||
|
||||
private ReplicationHub(byte localIdentifier, Builder builder) {
|
||||
super(localIdentifier, builder);
|
||||
|
||||
channels = new ReplicationChannel[builder.maxNumberOfChannels];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new {@link ReplicationHub.Builder}.
|
||||
*
|
||||
@@ -61,21 +69,12 @@ public final class ReplicationHub extends AbstractReplication {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private final ReplicationChannel[] channels;
|
||||
|
||||
private ReplicationHub(byte localIdentifier, Builder builder) {
|
||||
super(localIdentifier, builder);
|
||||
|
||||
channels = new ReplicationChannel[builder.maxNumberOfChannels];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReplicationHub{" + super.toString() +
|
||||
", channels=" + Arrays.toString(channels) + '}';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maximum number of channels could be {@linkplain #createChannel(int) created} for
|
||||
* this {@code ReplicationHub}.
|
||||
|
||||
-2
@@ -68,7 +68,6 @@ public final class DataValueBytesMarshallers {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T> Class acquireReaderClass(Class<T> tClass) {
|
||||
DataValueClasses.directClassFor(tClass);
|
||||
Class readerClass = readersClassMap.get(tClass);
|
||||
@@ -192,7 +191,6 @@ public final class DataValueBytesMarshallers {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String bytesReaderName(Class type, boolean simple) {
|
||||
return (simple ? type.getSimpleName() : type.getName()) + "$$BytesReader";
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ public enum DoubleMarshaller implements BytesInterop<Double>, BytesReader<Double
|
||||
return 8L;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int minSizeEncodingSize() {
|
||||
return 0;
|
||||
|
||||
@@ -256,7 +256,6 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
LOG.error("", e);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (future != null)
|
||||
future.cancel(true);
|
||||
@@ -461,7 +460,6 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public Bytes resizeBuffer(int size) {
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
@@ -493,7 +491,6 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
return !externalizable.identifierCheck(entry, chronicleId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEntry(@NotNull final Bytes entry,
|
||||
final int chronicleId,
|
||||
@@ -543,7 +540,6 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
long remaining = in.remaining();
|
||||
int entrySize = externalizable.sizeOfEntry(entry, chronicleId);
|
||||
|
||||
|
||||
if (entrySize > remaining) {
|
||||
|
||||
long newSize = start + entrySize;
|
||||
@@ -648,7 +644,6 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setSuccessfullyConnected() {
|
||||
connectionAttempts = 0;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ class BuildVersion {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// another way to get the version is to read it from the manifest
|
||||
final String versionFromManifest = getVersionFromManifest();
|
||||
|
||||
@@ -75,7 +74,6 @@ class BuildVersion {
|
||||
return ChronicleMapBuilder.class.getPackage().getImplementationVersion();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* reads the pom file to get this version, only to be used for development or within the IDE.
|
||||
*
|
||||
@@ -105,5 +103,4 @@ class BuildVersion {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -319,7 +319,6 @@ final class ChannelProvider implements Closeable {
|
||||
return channelProvider;
|
||||
channelProvider = new ChannelProvider(hub);
|
||||
|
||||
|
||||
TcpTransportAndNetworkConfig tcpConfig = hub.tcpTransportAndNetwork();
|
||||
if (tcpConfig != null) {
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ class JsonSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static synchronized <K, V> void putAll(File fromFile, Map<K, V> map, List jsonConverters)
|
||||
throws IOException {
|
||||
final XStream xstream = xStream(map, jsonConverters);
|
||||
@@ -115,4 +114,3 @@ class JsonSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -94,8 +94,6 @@ public interface EngineReplicationLangBytes extends Closeable {
|
||||
|
||||
void setLastModificationTime(byte identifier, long timestamp);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* notifies when there is a changed to the modification iterator
|
||||
*/
|
||||
|
||||
@@ -49,7 +49,6 @@ public interface MapBuilder<C extends MapBuilder<C>> {
|
||||
*/
|
||||
C putReturnsNull(boolean putReturnsNull);
|
||||
|
||||
|
||||
/**
|
||||
* Configures if the maps created by this {@code MapBuilder} should return {@code null}
|
||||
* instead of the last mapped value on {@link ChronicleMap#remove(Object)
|
||||
|
||||
@@ -67,7 +67,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
*/
|
||||
long lastModificationTime(byte remoteIdentifier);
|
||||
|
||||
|
||||
void setLastModificationTime(byte identifier, long timestamp);
|
||||
|
||||
/**
|
||||
@@ -142,7 +141,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
*/
|
||||
int sizeOfEntry(@NotNull Bytes entry, int chronicleId);
|
||||
|
||||
|
||||
/**
|
||||
* check that the identifier in the entry is from this node
|
||||
*
|
||||
@@ -152,7 +150,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
*/
|
||||
boolean identifierCheck(@NotNull Bytes entry, int chronicleId);
|
||||
|
||||
|
||||
/**
|
||||
* The map implements this method to save its contents.
|
||||
* @param entry the byte location of the entry to be stored
|
||||
@@ -182,8 +179,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
@NotNull VanillaChronicleMap.SegmentState segmentState,
|
||||
@NotNull Bytes source);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +247,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
public void onBeforeEntry() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* its possible that the entry should now be ignored, for example although rare its
|
||||
* identifier may have recently been changed by another thread, so its no longer applicable
|
||||
@@ -266,6 +260,5 @@ interface Replica extends Closeable, EngineReplicationLangBytes {
|
||||
public abstract boolean shouldBeIgnored(final Bytes entry, final int chronicleId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -426,7 +426,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
if (remoteIdentifier == 0)
|
||||
throw new IllegalStateException("identifier can't be 0");
|
||||
|
||||
|
||||
if (remoteIdentifier == this.identifier()) {
|
||||
// this may occur when working with UDP, as we may receive our own data
|
||||
return;
|
||||
@@ -451,7 +450,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
key, segmentHash, timestamp, remoteIdentifier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte identifier() {
|
||||
return localIdentifier;
|
||||
@@ -528,7 +526,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -558,7 +555,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void onPut(VanillaChronicleMap<K, KI, MKI, V, VI, MVI>.Segment segment, long pos) {
|
||||
for (long next = modIterSet.nextSetBit(0L); next > 0L;
|
||||
@@ -617,7 +613,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int sizeOfEntry(@NotNull Bytes entry, int chronicleId) {
|
||||
|
||||
long start = entry.position();
|
||||
@@ -654,7 +649,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method does not set a segment lock, A segment lock should be obtained before calling
|
||||
* this method, especially when being used in a multi threaded context.
|
||||
@@ -1810,7 +1804,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
|
||||
public void onRemove(long pos, SharedSegment segment) {
|
||||
changes.set(combine(segment.getIndex(), pos));
|
||||
|
||||
@@ -1842,7 +1835,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
(position > 0L && changes.nextSetBit(0L) != NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entryCallback call this to get an entry, this class will take care of the locking
|
||||
* @return true if an entry was processed
|
||||
|
||||
@@ -68,7 +68,6 @@ final class Replicators {
|
||||
static Replicator tcp(final AbstractReplication replication) {
|
||||
return new Replicator() {
|
||||
|
||||
|
||||
@Override
|
||||
protected Closeable applyTo(@NotNull final ChronicleMapBuilder builder,
|
||||
@NotNull final Replica replica,
|
||||
@@ -132,7 +131,6 @@ final class Replicators {
|
||||
@Override
|
||||
public Bytes resizeBuffer(int newCapacity) {
|
||||
|
||||
|
||||
if (newCapacity < out.capacity())
|
||||
throw new IllegalStateException("it not possible to resize the buffer smaller");
|
||||
|
||||
|
||||
@@ -301,7 +301,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
clientChannel = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,7 +505,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
@Nullable
|
||||
public V getUsing(K key, V usingValue) {
|
||||
|
||||
|
||||
final long startTime = System.currentTimeMillis();
|
||||
ThreadLocalCopies copies;
|
||||
|
||||
@@ -820,7 +818,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> map) {
|
||||
@@ -884,7 +881,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
outBytesLock.unlock();
|
||||
}
|
||||
|
||||
|
||||
if (!putReturnsNull) {
|
||||
inBytesLock.lock();
|
||||
try {
|
||||
@@ -964,7 +960,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
outBytes.writeByte((byte) event.ordinal());
|
||||
|
||||
|
||||
return markSizeLocation();
|
||||
}
|
||||
|
||||
@@ -1038,7 +1033,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
private Bytes blockingFetchReadOnly(long timeoutTime, final long transactionId) {
|
||||
|
||||
|
||||
assert inBytesLock.isHeldByCurrentThread();
|
||||
// assert !outBytesLock.isHeldByCurrentThread();
|
||||
try {
|
||||
@@ -1108,7 +1102,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
NativeBytes.UNSAFE.throwException(throwable);
|
||||
}
|
||||
|
||||
|
||||
return inBytes;
|
||||
}
|
||||
|
||||
@@ -1167,7 +1160,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// time out the old transaction id
|
||||
if (System.currentTimeMillis() - timeoutTime >
|
||||
parkedTransactionTimeStamp) {
|
||||
@@ -1208,7 +1200,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
inBytesLock.lock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* reads up to the number of byte in {@code requiredNumberOfBytes}
|
||||
*
|
||||
@@ -1220,7 +1211,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
private Bytes receiveBytesFromSocket(int requiredNumberOfBytes, long timeoutTime) throws IOException {
|
||||
|
||||
|
||||
// assert !outBytesLock.isHeldByCurrentThread();
|
||||
assert inBytesLock.isHeldByCurrentThread();
|
||||
|
||||
@@ -1269,14 +1259,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
limitOfLast = outBuffer.limit();
|
||||
|
||||
|
||||
while (outBuffer.remaining() > 0) {
|
||||
|
||||
int len = clientChannel.write(outBuffer);
|
||||
if (len == -1)
|
||||
throw new IORuntimeException("Disconnection to server");
|
||||
|
||||
|
||||
// if we have queued threads then we don't have to write all the bytes as the other
|
||||
// threads will write the remains bytes.
|
||||
if (outBuffer.remaining() > 0 && outBytesLock.hasQueuedThreads() &&
|
||||
@@ -1306,7 +1294,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
assert outBytes.readByte(locationOfSize - 1) >= LONG_SIZE.ordinal();
|
||||
|
||||
|
||||
final long size = outBytes.position() - locationOfSize;
|
||||
final long pos = outBytes.position();
|
||||
outBytes.position(locationOfSize);
|
||||
@@ -1372,7 +1359,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
assert !inBytesLock.isHeldByCurrentThread();
|
||||
long start = outBytes.position();
|
||||
|
||||
|
||||
assert outBytes.position() == start;
|
||||
outBytes.limit(outBytes.capacity());
|
||||
return valueWriterWithSize.writeInLoop(outBytes, value, writer, copies);
|
||||
@@ -1489,7 +1475,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
outBytesLock.unlock();
|
||||
}
|
||||
|
||||
|
||||
return readBoolean(transactionId, startTime);
|
||||
|
||||
}
|
||||
@@ -1505,7 +1490,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
try {
|
||||
final long sizeLocation = writeEventAnSkip(eventId);
|
||||
|
||||
|
||||
copies = writeKey(key);
|
||||
copies = writeValue(value1, copies);
|
||||
writeValue(value2, copies);
|
||||
@@ -1514,7 +1498,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
outBytesLock.unlock();
|
||||
}
|
||||
|
||||
|
||||
return readBoolean(transactionId, startTime);
|
||||
|
||||
}
|
||||
@@ -1679,7 +1662,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
outBytesLock.unlock();
|
||||
}
|
||||
|
||||
|
||||
if (eventReturnsNull(eventId))
|
||||
return null;
|
||||
|
||||
|
||||
@@ -394,7 +394,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
// null check (Attached)key.attachment();
|
||||
// connectionListener.onDiconnect( ((SocketChannel)key.channel()).socket().getInetAddress(), ((Attached)key.attachment()).remoteIdentifier);
|
||||
|
||||
|
||||
closeEarlyAndQuietly(key.channel());
|
||||
}
|
||||
|
||||
@@ -533,7 +532,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
final String localVersion = BuildVersion.version();
|
||||
final String remoteVersion = attached.serverVersion;
|
||||
|
||||
|
||||
if (!remoteVersion.equals(localVersion)) {
|
||||
byte remoteIdentifier = attached.remoteIdentifier;
|
||||
LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS : " +
|
||||
@@ -582,7 +580,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
|
||||
attached.remoteIdentifier = remoteIdentifier;
|
||||
|
||||
|
||||
// todo OZAN : add call to onConnectedListener.
|
||||
//connectionListener. onConnected(channel.socket().getInetAddress() , attached
|
||||
// .remoteIdentifier, attached.isServer );
|
||||
@@ -1058,7 +1055,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
*/
|
||||
class TcpSocketChannelEntryWriter {
|
||||
|
||||
|
||||
@NotNull
|
||||
private final EntryCallback entryCallback;
|
||||
// if uncompletedWork is set ( not null ) , this must be completed before any further work
|
||||
@@ -1227,7 +1223,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* used to send an single zero byte if we have not send any data for up to the
|
||||
* localHeartbeatInterval
|
||||
@@ -1244,7 +1239,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
in().writeLong(localHeartbeatInterval);
|
||||
}
|
||||
|
||||
|
||||
public boolean doWork() {
|
||||
return uncompletedWork != null && uncompletedWork.doWork(in());
|
||||
}
|
||||
@@ -1467,7 +1461,6 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public long readRemoteHeartbeatIntervalFromBuffer() {
|
||||
return (out.remaining() >= 8) ? out.readLong() : Long.MIN_VALUE;
|
||||
}
|
||||
@@ -1504,7 +1497,6 @@ class StatelessServerConnector<K, V> {
|
||||
private final SerializationBuilder<V> valueSerializationBuilder;
|
||||
private final int tcpBufferSize;
|
||||
|
||||
|
||||
StatelessServerConnector(
|
||||
@NotNull VanillaChronicleMap<K, ?, ?, V, ?, ?> map,
|
||||
@NotNull final BufferResizer bufferResizer, int tcpBufferSize,
|
||||
@@ -1535,7 +1527,6 @@ class StatelessServerConnector<K, V> {
|
||||
int headerSize = reader.readInt();
|
||||
reader.skip(headerSize);
|
||||
|
||||
|
||||
// these methods don't return a result to the client or don't return a result to the
|
||||
// client immediately
|
||||
switch (event) {
|
||||
@@ -1560,7 +1551,6 @@ class StatelessServerConnector<K, V> {
|
||||
|
||||
final long sizeLocation = reflectTransactionId(writer.in(), transactionId);
|
||||
|
||||
|
||||
// these methods return a result
|
||||
|
||||
switch (event) {
|
||||
@@ -1664,7 +1654,6 @@ class StatelessServerConnector<K, V> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Work mapForKey(@NotNull ByteBufferBytes reader, @NotNull TcpReplicator.TcpSocketChannelEntryWriter writer,
|
||||
long sizeLocation) {
|
||||
@@ -1769,11 +1758,9 @@ class StatelessServerConnector<K, V> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Work applicationVersion(@NotNull TcpReplicator.TcpSocketChannelEntryWriter writer, final long sizeLocation) {
|
||||
|
||||
|
||||
final long remaining = writer.in().remaining();
|
||||
try {
|
||||
String result = map.applicationVersion();
|
||||
@@ -1788,11 +1775,9 @@ class StatelessServerConnector<K, V> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Work persistedDataVersion(@NotNull TcpReplicator.TcpSocketChannelEntryWriter writer, final long sizeLocation) {
|
||||
|
||||
|
||||
final long remaining = writer.in().remaining();
|
||||
try {
|
||||
String result = map.persistedDataVersion();
|
||||
@@ -2132,7 +2117,6 @@ class StatelessServerConnector<K, V> {
|
||||
out.position(pos);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void writeException(@NotNull TcpReplicator.TcpSocketChannelEntryWriter out, Throwable e) {
|
||||
|
||||
@@ -102,7 +102,6 @@ class UdpChannelReplicator extends AbstractChannelReplicator implements Replica.
|
||||
* binds to the server socket and process data This method will block until interrupted
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
void processEvent() {
|
||||
try {
|
||||
|
||||
@@ -59,7 +59,6 @@ final class UdpReplicator extends UdpChannelReplicator implements Replica.Modifi
|
||||
|
||||
private static class UdpSocketChannelEntryWriter implements EntryWriter {
|
||||
|
||||
|
||||
private final EntryCallback entryCallback;
|
||||
private final UdpChannelReplicator udpReplicator;
|
||||
private final Replicators.OutBuffer outBuffer;
|
||||
|
||||
@@ -1697,7 +1697,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dontPutOnClose() {
|
||||
if (removed)
|
||||
@@ -1943,7 +1942,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
long lockTime = System.nanoTime() - startWriteLock;
|
||||
|
||||
|
||||
if (lockTime > 1e8 && LOG.isInfoEnabled())
|
||||
LOG.info("Thread took " + lockTime / 1000000 + "ms to release the lock, (Was there a GC?)");
|
||||
}
|
||||
@@ -1959,7 +1957,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
"replicated map");
|
||||
}
|
||||
|
||||
|
||||
final MultiStoreBytes reuse(MultiStoreBytes entry, long offset) {
|
||||
entry.setBytesOffset(bytes, offset);
|
||||
entry.position(metaDataBytes);
|
||||
|
||||
@@ -27,6 +27,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.BufferOverflowException;
|
||||
|
||||
interface BufferResizer {
|
||||
|
||||
/**
|
||||
* @param newCapacity
|
||||
* @return the newly resize buffer
|
||||
*/
|
||||
Bytes resizeBuffer(int newCapacity);
|
||||
}
|
||||
|
||||
final class WriterWithSize<T> {
|
||||
private final SizeMarshaller sizeMarshaller;
|
||||
private final Object originalWriter;
|
||||
@@ -73,7 +82,6 @@ final class WriterWithSize<T> {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public ThreadLocalCopies writeNullable(Bytes out, T t, @Nullable ThreadLocalCopies copies) {
|
||||
out.writeBoolean(t == null);
|
||||
if (t == null)
|
||||
@@ -106,12 +114,3 @@ final class WriterWithSize<T> {
|
||||
return writeInLoop(out, t, writer, copies);
|
||||
}
|
||||
}
|
||||
|
||||
interface BufferResizer {
|
||||
|
||||
/**
|
||||
* @param newCapacity
|
||||
* @return the newly resize buffer
|
||||
*/
|
||||
Bytes resizeBuffer(int newCapacity);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.Map;
|
||||
*/
|
||||
class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
|
||||
|
||||
private final Map<K, V> map;
|
||||
private final Class mapClazz;
|
||||
|
||||
@@ -41,6 +40,50 @@ class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
this.mapClazz = map.getClass();
|
||||
}
|
||||
|
||||
private static <E> E deserialize(@NotNull UnmarshallingContext unmarshallingContext,
|
||||
@NotNull HierarchicalStreamReader reader) {
|
||||
|
||||
switch (reader.getNodeName()) {
|
||||
|
||||
case "java.util.Collections$EmptySet":
|
||||
return (E) Collections.EMPTY_SET;
|
||||
|
||||
case "java.util.Collections$EmptyList":
|
||||
return (E) Collections.EMPTY_LIST;
|
||||
|
||||
case "java.util.Collections$EmptyMap":
|
||||
case "java.util.Collections.EmptyMap":
|
||||
return (E) Collections.EMPTY_MAP;
|
||||
|
||||
}
|
||||
|
||||
return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName()));
|
||||
}
|
||||
|
||||
private static Class forName(String clazz) {
|
||||
|
||||
try {
|
||||
return Class.forName(clazz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
boolean isNative = clazz.endsWith("$$Native");
|
||||
boolean isHeap = clazz.endsWith("$$Heap");
|
||||
|
||||
if (!isNative && !isHeap)
|
||||
throw new ConversionException("class=" + clazz, e);
|
||||
|
||||
final String nativeInterface = isNative ? clazz.substring(0, clazz.length() -
|
||||
"$$Native".length()) : clazz.substring(0, clazz.length() -
|
||||
"$$Heap".length());
|
||||
try {
|
||||
DataValueClasses.newDirectInstance(Class.forName(clazz));
|
||||
return Class.forName(nativeInterface);
|
||||
} catch (Exception e1) {
|
||||
throw new ConversionException("class=" + clazz, e1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class aClass) {
|
||||
@@ -48,7 +91,6 @@ class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
return mapClazz.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext
|
||||
marshallingContext) {
|
||||
@@ -109,50 +151,5 @@ class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <E> E deserialize(@NotNull UnmarshallingContext unmarshallingContext,
|
||||
@NotNull HierarchicalStreamReader reader) {
|
||||
|
||||
switch (reader.getNodeName()) {
|
||||
|
||||
case "java.util.Collections$EmptySet":
|
||||
return (E) Collections.EMPTY_SET;
|
||||
|
||||
case "java.util.Collections$EmptyList":
|
||||
return (E) Collections.EMPTY_LIST;
|
||||
|
||||
case "java.util.Collections$EmptyMap":
|
||||
case "java.util.Collections.EmptyMap":
|
||||
return (E) Collections.EMPTY_MAP;
|
||||
|
||||
}
|
||||
|
||||
return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName()));
|
||||
}
|
||||
|
||||
private static Class forName(String clazz) {
|
||||
|
||||
try {
|
||||
return Class.forName(clazz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
boolean isNative = clazz.endsWith("$$Native");
|
||||
boolean isHeap = clazz.endsWith("$$Heap");
|
||||
|
||||
if (!isNative && !isHeap)
|
||||
throw new ConversionException("class=" + clazz, e);
|
||||
|
||||
final String nativeInterface = isNative ? clazz.substring(0, clazz.length() -
|
||||
"$$Native".length()) : clazz.substring(0, clazz.length() -
|
||||
"$$Heap".length());
|
||||
try {
|
||||
DataValueClasses.newDirectInstance(Class.forName(clazz));
|
||||
return Class.forName(nativeInterface);
|
||||
} catch (Exception e1) {
|
||||
throw new ConversionException("class=" + clazz, e1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,17 +42,14 @@ public class ByteBufferConverter implements Converter {
|
||||
marshallingContext.convertAnother(buffer.position());
|
||||
writer.endNode();
|
||||
|
||||
|
||||
writer.startNode("capacity");
|
||||
marshallingContext.convertAnother(buffer.capacity());
|
||||
writer.endNode();
|
||||
|
||||
|
||||
writer.startNode("limit");
|
||||
marshallingContext.convertAnother(buffer.limit());
|
||||
writer.endNode();
|
||||
|
||||
|
||||
writer.startNode("isDirect");
|
||||
marshallingContext.convertAnother(buffer.isDirect());
|
||||
writer.endNode();
|
||||
@@ -74,7 +71,6 @@ public class ByteBufferConverter implements Converter {
|
||||
throw new ConversionException("", e);
|
||||
}
|
||||
|
||||
|
||||
writer.endNode();
|
||||
|
||||
buffer.limit(limit);
|
||||
@@ -88,7 +84,6 @@ public class ByteBufferConverter implements Converter {
|
||||
int position = (Integer) unmarshallingContext.convertAnother(null, int.class);
|
||||
reader.moveUp();
|
||||
|
||||
|
||||
reader.moveDown();
|
||||
int capacity = (Integer) unmarshallingContext.convertAnother(null, int.class);
|
||||
reader.moveUp();
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
@@ -45,6 +44,45 @@ public class DataValueConverter implements Converter {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DataValueConverter.class);
|
||||
|
||||
private static Object toNativeValueObjects(HierarchicalStreamReader reader,
|
||||
final Class aClass,
|
||||
UnmarshallingContext context) {
|
||||
|
||||
final Object o = DataValueClasses.newDirectInstance(aClass);
|
||||
|
||||
try {
|
||||
|
||||
final BeanInfo info = Introspector.getBeanInfo(o.getClass()); // new BeanGenerator
|
||||
|
||||
for (PropertyDescriptor p : info.getPropertyDescriptors()) {
|
||||
|
||||
if (!p.getName().equals("value"))
|
||||
continue;
|
||||
|
||||
final String value = reader.getValue();
|
||||
|
||||
if (StringValue.class.isAssignableFrom(o.getClass())) {
|
||||
((StringValue) o).setValue(value);
|
||||
return o;
|
||||
}
|
||||
|
||||
final Class<?> propertyType = p.getPropertyType();
|
||||
|
||||
final Object o1 = context.convertAnother(value, propertyType);
|
||||
p.getWriteMethod().invoke(o, o1);
|
||||
|
||||
return o;
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ConversionException("class=" + aClass.getName(), e);
|
||||
}
|
||||
|
||||
throw new ConversionException("setValue(..) method not found in class=" +
|
||||
aClass.getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
|
||||
@@ -78,7 +116,6 @@ public class DataValueConverter implements Converter {
|
||||
throw new ConversionException("class=" + canonicalName);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
DataValueModel<?> dataValueModel = DataValueModels.acquireModel(interfaceClass(o.getClass()));
|
||||
|
||||
@@ -138,7 +175,6 @@ public class DataValueConverter implements Converter {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
final Method readMethod = fileModel.getter();
|
||||
@@ -161,7 +197,6 @@ public class DataValueConverter implements Converter {
|
||||
LOG.error("class=" + fileModel.name(), e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
@@ -188,7 +223,6 @@ public class DataValueConverter implements Converter {
|
||||
return Class.forName(nodeName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader,
|
||||
UnmarshallingContext context) {
|
||||
@@ -289,46 +323,6 @@ public class DataValueConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Object toNativeValueObjects(HierarchicalStreamReader reader,
|
||||
final Class aClass,
|
||||
UnmarshallingContext context) {
|
||||
|
||||
final Object o = DataValueClasses.newDirectInstance(aClass);
|
||||
|
||||
try {
|
||||
|
||||
final BeanInfo info = Introspector.getBeanInfo(o.getClass()); // new BeanGenerator
|
||||
|
||||
for (PropertyDescriptor p : info.getPropertyDescriptors()) {
|
||||
|
||||
if (!p.getName().equals("value"))
|
||||
continue;
|
||||
|
||||
final String value = reader.getValue();
|
||||
|
||||
if (StringValue.class.isAssignableFrom(o.getClass())) {
|
||||
((StringValue) o).setValue(value);
|
||||
return o;
|
||||
}
|
||||
|
||||
final Class<?> propertyType = p.getPropertyType();
|
||||
|
||||
final Object o1 = context.convertAnother(value, propertyType);
|
||||
p.getWriteMethod().invoke(o, o1);
|
||||
|
||||
return o;
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ConversionException("class=" + aClass.getName(), e);
|
||||
}
|
||||
|
||||
throw new ConversionException("setValue(..) method not found in class=" +
|
||||
aClass.getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
final String canonicalName = clazz.getCanonicalName();
|
||||
|
||||
@@ -73,9 +73,7 @@ public class StatelessChronicleMapConverter<K, V> extends AbstractChronicleMapCo
|
||||
throw new ConversionException("", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user