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) Deprecated.ServerProtocolIO(DataInputStream input, DataOutputStream output, int maxIpcPayloadBytes, ExceptionReporting exceptionReporting) -
Method Summary
Modifier and TypeMethodDescriptionvoidawaitAck()Reads a framed message and verifies it is an ACK.static voidclampRequestLimits(ParseContext operatorContext, ParseContext merged) A request may tighten the operator'sOutputLimits,EmbeddedLimits, content-handler write limit, metadata limiter andmaxUnpackBytesbut not loosen them.static voidclampRequestTimeoutLimits(ParseContext requestContext, ParseContext operatorContext, ParseContext mergedContext, long maxMillis) Caps request-suppliedTimeoutLimits(typed or unresolvedtimeout-limitsJSON) field by field at the operator's own limits (operatorContext: the server's config plus any preset, or the class defaults) and atpipes.maxTotalTaskTimeoutMillis: a request may shorten a timeout but not extend it.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.voidwriteIntermediate(Metadata metadata, Runnable afterFrameWritten) LikewriteIntermediate(Metadata), but runsafterFrameWrittenonce the frame is flushed to the socket, before waiting for the client's 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
@Deprecated public ServerProtocolIO(DataInputStream input, DataOutputStream output, int maxIpcPayloadBytes) Deprecated.since 4.1, use the overload taking anExceptionReporting -
ServerProtocolIO
public ServerProtocolIO(DataInputStream input, DataOutputStream output, int maxIpcPayloadBytes, ExceptionReporting exceptionReporting)
-
-
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
-
writeIntermediate
LikewriteIntermediate(Metadata), but runsafterFrameWrittenonce the frame is flushed to the socket, before waiting for the client's ACK. Lets the caller unblock the parse worker while the ACK is still in flight -- the ACK round trip would otherwise sit between pre-parse and parse on every request. Not invoked when the oversized intermediate is skipped or the write fails; callers must handle those paths themselves.- Throws:
IOException
-
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 operatorContext, ParseContext mergedContext, long maxMillis) Caps request-suppliedTimeoutLimits(typed or unresolvedtimeout-limitsJSON) field by field at the operator's own limits (operatorContext: the server's config plus any preset, or the class defaults) and atpipes.maxTotalTaskTimeoutMillis: a request may shorten a timeout but not extend it. The operator's limits are never clamped. Must run afterParseContextUtils.resolveAlland beforeParseTimeoutis armed. -
clampRequestLimits
public static void clampRequestLimits(ParseContext operatorContext, ParseContext merged) throws TikaConfigException A request may tighten the operator'sOutputLimits,EmbeddedLimits, content-handler write limit, metadata limiter andmaxUnpackBytesbut not loosen them. Render limits in"pages"are bounded where the parser resolves them, by thePagesConfig.OperatorPagesrecorded here.operatorContextis the server's config plus any preset, before the request was overlaid; entries it already holds are the operator's and are left alone. Must run afterParseContextUtils.resolveAll.- Throws:
TikaConfigException
-
ExceptionReporting