added exception handling

This commit is contained in:
Rob Austin
2015-05-03 18:16:24 +01:00
parent d4a3242826
commit 2a32e426ef
3 changed files with 17 additions and 45 deletions
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub;
import net.openhft.chronicle.wire.CoreFields;
import net.openhft.chronicle.wire.ParameterizeWireKey;
import net.openhft.chronicle.wire.WireKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -33,32 +32,10 @@ public abstract class MapStatelessClient< E extends ParameterizeWireKey> extends
@Nullable Object... args) {
return proxyReturnWireConsumerInOut(eventId,
toParameters(eventId, args),
f -> f.read(CoreFields.reply)
.object(resultType));
CoreFields.reply, toParameters(eventId, args),
f -> f.object(resultType));
}
/*
protected <E, O> E proxyReturnE(@NotNull final WireKey eventId,
@Nullable final O arg,
@NotNull final Class<E> eClass) {
return proxyReturnWireConsumerInOut(eventId,
valueOut -> valueOut.object(arg),
f -> f.read(CoreFields.reply)
.object(eClass));
}
protected <E> E proxyReturnE(@NotNull final WireKey eventId,
@NotNull final Class<E> eClass) {
return proxyReturnWireConsumer(eventId,
f -> f.read(CoreFields.reply)
.object(eClass));
} */
}
@@ -209,7 +209,7 @@ public class MapWireHandlerProcessor<K, V> implements
if (clear.contentEquals(eventName)) {
map.clear();
outWire.writeEventName(reply).marshallable(AbstactStatelessClient.EMPTY);
return;
}
@@ -223,7 +223,6 @@ public class MapWireHandlerProcessor<K, V> implements
}
map.putAll(data);
outWire.writeEventName(reply).marshallable(AbstactStatelessClient.EMPTY);
return;
}
@@ -436,31 +435,26 @@ public class MapWireHandlerProcessor<K, V> implements
*/
private void writeData(@NotNull Consumer<WireOut> c) {
final long position = outWire.bytes().position();
outWire.writeDocument(false, out -> {
start = outWire.bytes().position();
final long position = outWire.bytes().position();
try {
c.accept(outWire);
} catch (Exception e) {
LOG.error("", e);
out.getValueOut()
.type(e.getClass().getSimpleName())
.writeValue().text(e.getMessage());
} catch (Exception exception) {
outWire.bytes().position(position);
outWire.writeEventName(() -> "exception").marshallable(
new net.openhft.chronicle.wire.util.ExceptionMarshaller(exception));
}
// write 'reply : {} ' if no data was sent
if (position == outWire.bytes().position()) {
outWire.writeEventName(reply).marshallable(AbstactStatelessClient.EMPTY);
}
});
// rollback if no data was written
if (start == outWire.bytes().position()) {
if (outWire.bytes().position() == start) {
outWire.bytes().position(position);
}
}
}