Class ServerProtocolIO
java.lang.Object
org.apache.tika.pipes.core.server.ServerProtocolIO
Centralizes protocol I/O operations shared by
PipesServer and
ConnectionHandler.
This class handles the pure protocol mechanics — serialization, framing, and ACK exchange. It does not make lifecycle decisions (exit vs. return, close connection vs. shut down JVM). Callers are responsible for catching exceptions and responding according to their own lifecycle policy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe minimum value accepted formaxPayloadBytesin the constructor and inPipesConfig.setMaxIpcPayloadBytes(int): the serialized byte length ofFALLBACK_PAYLOAD_BYTES. -
Constructor Summary
ConstructorsConstructorDescriptionServerProtocolIO(DataInputStream input, DataOutputStream output, int maxIpcPayloadBytes) -
Method Summary
Modifier and TypeMethodDescriptionvoidawaitAck()Reads a framed message and verifies it is an ACK.static voidclampRequestTimeoutLimits(ParseContext requestContext, ParseContext mergedContext, long maxMillis) Trust boundary: caps request-suppliedTimeoutLimits(typed or unresolvedtimeout-limitsJSON) atpipes.maxTotalTaskTimeoutMillis; the server's own tika-config limits are never clamped.static voidvalidateParseContext(ParseContext context) Validates a (resolved) ParseContext's configuration.voidwriteCrash(PipesMessageType crashType, Throwable t) Writes a crash message (OOM, TIMEOUT, or UNSPECIFIED_CRASH) with the serialized stack trace and waits for ACK.voidwriteFinished(PipesResult pipesResult) Writes a FINISHED message with the serialized result and waits for ACK.voidwriteIntermediate(Metadata metadata) Writes an INTERMEDIATE_RESULT message with the serialized metadata and waits for ACK.
-
Field Details
-
MIN_FALLBACK_PAYLOAD_BYTES
public static final int MIN_FALLBACK_PAYLOAD_BYTESThe minimum value accepted formaxPayloadBytesin the constructor and inPipesConfig.setMaxIpcPayloadBytes(int): the serialized byte length ofFALLBACK_PAYLOAD_BYTES. Any configured limit smaller than this cannot carry even the fallback frame.
-
-
Constructor Details
-
ServerProtocolIO
-
-
Method Details
-
writeFinished
Writes a FINISHED message with the serialized result and waits for ACK.Serialization is streamed into a
ServerProtocolIO.BoundedOutputStreamcapped atmaxIpcPayloadBytes. If the payload overflows the cap, the stream aborts before any bytes are sent to the client and a pre-computedPAYLOAD_LIMIT_EXCEEDEDframe is sent instead. This keeps the original result status intact when the payload fits, avoids unbounded heap allocation, and prevents wire desynchronization on the client side.- Throws:
ShutDownReceivedException- if SHUT_DOWN is received instead of ACKIOException- on serialization or I/O errors
-
writeIntermediate
Writes an INTERMEDIATE_RESULT message with the serialized metadata and waits for ACK. If the metadata exceedsmaxIpcPayloadBytes, the intermediate is silently skipped (the FINISHED message will still follow).- Throws:
ShutDownReceivedException- if SHUT_DOWN is received instead of ACKIOException- on serialization or I/O errors
-
writeCrash
Writes a crash message (OOM, TIMEOUT, or UNSPECIFIED_CRASH) with the serialized stack trace and waits for ACK. Serialization is streamed into aServerProtocolIO.BoundedOutputStreamcapped atmaxIpcPayloadBytes. If the stack trace overflows the cap, an empty payload is sent instead.- Throws:
IOException- on serialization, I/O, or unexpected ACK response
-
awaitAck
Reads a framed message and verifies it is an ACK.- Throws:
ShutDownReceivedException- if the message is SHUT_DOWNIOException- if the message is any other non-ACK type, or on I/O error
-
validateParseContext
Validates a (resolved) ParseContext's configuration. Must be called afterParseContextUtils.resolveAll(org.apache.tika.parser.ParseContext, java.lang.ClassLoader), since configs are lazy and only populated once resolved.- Throws:
TikaConfigException
-
clampRequestTimeoutLimits
public static void clampRequestTimeoutLimits(ParseContext requestContext, ParseContext mergedContext, long maxMillis) Trust boundary: caps request-suppliedTimeoutLimits(typed or unresolvedtimeout-limitsJSON) atpipes.maxTotalTaskTimeoutMillis; the server's own tika-config limits are never clamped. Must run afterParseContextUtils.resolveAlland beforeParseTimeoutis armed.
-