Class ServerProtocolIO

java.lang.Object
org.apache.tika.pipes.core.server.ServerProtocolIO

public class ServerProtocolIO extends Object
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 Details

    • MIN_FALLBACK_PAYLOAD_BYTES

      public static final int MIN_FALLBACK_PAYLOAD_BYTES
      The minimum value accepted for maxPayloadBytes in the constructor and in PipesConfig.setMaxIpcPayloadBytes(int): the serialized byte length of FALLBACK_PAYLOAD_BYTES. Any configured limit smaller than this cannot carry even the fallback frame.
  • Constructor Details

  • Method Details

    • writeFinished

      public void writeFinished(PipesResult pipesResult) throws IOException
      Writes a FINISHED message with the serialized result and waits for ACK.

      Serialization is streamed into a ServerProtocolIO.BoundedOutputStream capped at maxIpcPayloadBytes. If the payload overflows the cap, the stream aborts before any bytes are sent to the client and a pre-computed PAYLOAD_LIMIT_EXCEEDED frame 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 ACK
      IOException - on serialization or I/O errors
    • writeIntermediate

      public void writeIntermediate(Metadata metadata) throws IOException
      Writes an INTERMEDIATE_RESULT message with the serialized metadata and waits for ACK. If the metadata exceeds maxIpcPayloadBytes, the intermediate is silently skipped (the FINISHED message will still follow).
      Throws:
      ShutDownReceivedException - if SHUT_DOWN is received instead of ACK
      IOException - on serialization or I/O errors
    • writeCrash

      public void writeCrash(PipesMessageType crashType, Throwable t) throws IOException
      Writes a crash message (OOM, TIMEOUT, or UNSPECIFIED_CRASH) with the serialized stack trace and waits for ACK. Serialization is streamed into a ServerProtocolIO.BoundedOutputStream capped at maxIpcPayloadBytes. If the stack trace overflows the cap, an empty payload is sent instead.
      Throws:
      IOException - on serialization, I/O, or unexpected ACK response
    • awaitAck

      public void awaitAck() throws IOException
      Reads a framed message and verifies it is an ACK.
      Throws:
      ShutDownReceivedException - if the message is SHUT_DOWN
      IOException - if the message is any other non-ACK type, or on I/O error
    • validateParseContext

      public static void validateParseContext(ParseContext context) throws TikaConfigException
      Validates a (resolved) ParseContext's configuration. Must be called after ParseContextUtils.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-supplied TimeoutLimits (typed or unresolved timeout-limits JSON) at pipes.maxTotalTaskTimeoutMillis; the server's own tika-config limits are never clamped. Must run after ParseContextUtils.resolveAll and before ParseTimeout is armed.