diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2018-09-14 15:40:46 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2018-09-14 15:40:46 +0200 |
commit | 99205db587a3897fb38c685883b5d52161215e71 (patch) | |
tree | b6a9a35f5c6e9e511dda02c428c28844620335ff /container-search/src/main/java/com/yahoo/fs4 | |
parent | d166163770dde9d20975220457f4f6eb45336919 (diff) |
FS4 interfacing code moved to FS4CloseableChannel from FastSearcher
Diffstat (limited to 'container-search/src/main/java/com/yahoo/fs4')
-rw-r--r-- | container-search/src/main/java/com/yahoo/fs4/BasicPacket.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/fs4/BasicPacket.java b/container-search/src/main/java/com/yahoo/fs4/BasicPacket.java index 85e1aef3da0..6f87e45af25 100644 --- a/container-search/src/main/java/com/yahoo/fs4/BasicPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/BasicPacket.java @@ -4,9 +4,11 @@ package com.yahoo.fs4; import com.yahoo.compress.CompressionType; import com.yahoo.compress.Compressor; import com.yahoo.log.LogLevel; +import com.yahoo.prelude.fastsearch.TimeoutException; import net.jpountz.lz4.LZ4Compressor; import net.jpountz.lz4.LZ4Factory; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.Optional; import java.util.logging.Logger; @@ -325,4 +327,20 @@ public abstract class BasicPacket { return false; } + /** + * Throws an IOException if the packet is not of the expected type + */ + public void ensureInstanceOf(Class<? extends BasicPacket> type, String name) throws IOException { + if ((type.isAssignableFrom(getClass()))) return; + + if (this instanceof ErrorPacket) { + ErrorPacket errorPacket = (ErrorPacket) this; + if (errorPacket.getErrorCode() == 8) + throw new TimeoutException("Query timed out in " + name); + else + throw new IOException("Received error from backend in " + name + ": " + this); + } else { + throw new IOException("Received " + this + " when expecting " + type); + } + } } |