HCOLL-81 simplified code by using lookupUsing

This commit is contained in:
Rob Austin
2014-11-14 15:05:07 +00:00
parent e772737f36
commit 54b5412e53
3 changed files with 10 additions and 45 deletions
@@ -1348,21 +1348,12 @@ class StatelessServerConnector<K, V> {
final ThreadLocalCopies local = keyValueSerializer.threadLocalCopies();
final K key = readKey(reader, local);
V value = using.getAndSet(null);
if (value == null) {
//value = map.createValueInstance();
// todo replace this
value = map.acquireUsing(key, null);
}
final V value = using.getAndSet(null);
final Function<V, ?> o = (Function<V, ?>) reader.readObject();
try (WriteContext<K, V> wc = map.acquireUsingLocked(key, value)) {
Object result = o.apply(value);
try (WriteContext<K, V> wc = map.lookupUsing(key, value, VanillaChronicleMap.LockType.WRITE_LOCK,
false)) {
Object result = o.apply(wc.value());
keyValueSerializer.writeObject(result, writer);
} catch (RuntimeException e) {
@@ -29,10 +29,7 @@ import net.openhft.lang.collection.DirectBitSet;
import net.openhft.lang.collection.SingleThreadedDirectBitSet;
import net.openhft.lang.io.*;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.impl.AllocateInstanceObjectFactory;
import net.openhft.lang.io.serialization.impl.VanillaBytesMarshallerFactory;
import net.openhft.lang.model.Byteable;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.model.constraints.Nullable;
import net.openhft.lang.threadlocal.Provider;
import net.openhft.lang.threadlocal.ThreadLocalCopies;
@@ -353,30 +350,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
}
V createValueInstance() {
if (vClass.isAssignableFrom(Byteable.class))
return DataValueClasses.newDirectReference(vClass);
else {
try {
return vClass.newInstance();
} catch (InstantiationException e) {
try {
return (V) (new AllocateInstanceObjectFactory<V>(vClass)).create();
} catch (Exception e1) {
LOG.error("", e);
return null;
}
} catch (IllegalAccessException e) {
LOG.error("", e);
return null;
}
}
}
enum LockType {READ_LOCK, WRITE_LOCK}