Class ServerEngine<Q extends MessageHeader,R extends MessageHeader>
- Type Parameters:
Q
- the message header type handled by the decoder (the request)R
- the message header type handled be the encoder (the response)
It has an associated
request decoder and response encoder. Using a ServerEngine
has two main advantages over using an encoder and decoder
directly. It links encoder and decoder (see
Encoder.setPeerDecoder(Decoder)
and
Decoder.setPeerEncoder(Encoder)
) and it replaces the encoder
and decoder if the encoded result indicates a switch.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the last fully decoded request if it exists.decode
(ByteBuffer in, Buffer out, boolean endOfInput) Decodes a request sent to the server.Class<? extends MessageHeader>
decoding()
Returns the type of the messages decoded by this server.encode
(Buffer in, ByteBuffer out, boolean endOfInput) Invokes the encoder’s encode method.encode
(ByteBuffer out) Invokes the encoder’s encode method.void
Encodes a response generated by the server.Class<? extends MessageHeader>
encoding()
Returns the type of the messages encoded by this server.Returns the request decoder.Returns the response encoder.Methods inherited from class org.jdrupes.httpcodec.Engine
setSwitchedTo, switchedTo
-
Constructor Details
-
ServerEngine
Creates a new instance.- Parameters:
requestDecoder
- the decoder for the requestresponseEncoder
- the encoder for the response
-
-
Method Details
-
requestDecoder
Returns the request decoder.- Returns:
- the request decoder
-
responseEncoder
Returns the response encoder.- Returns:
- the response encoder
-
decoding
Returns the type of the messages decoded by this server.- Returns:
- the value
-
encoding
Returns the type of the messages encoded by this server.- Returns:
- the value
-
decode
public Decoder.Result<R> decode(ByteBuffer in, Buffer out, boolean endOfInput) throws ProtocolException Decodes a request sent to the server.- Parameters:
in
- the data to decodeout
- the decoded dataendOfInput
- true if this invocation finishes the message- Returns:
- the result
- Throws:
ProtocolException
- if the input violates the protocol
-
encode
Encodes a response generated by the server.This method must be used instead of the encoder’s method if the encoder and decoder should adapt to a protocol switch automatically.
- Parameters:
messageHeader
- the message header- See Also:
-
encode
Invokes the encoder’s encode method.This method must be used instead of encoder’s method if the encoder and decoder should adapt to a protocol switch automatically.
- Parameters:
out
- the decoded data- Returns:
- the result
- See Also:
-
encode
Invokes the encoder’s encode method.This method must be used instead of decoding the encoder’s method directly to allow derived server classes to adapt to any information contained in the message.
- Parameters:
in
- the data to encodeout
- the encoded dataendOfInput
- true if this invocation finishes the message- Returns:
- the result
- See Also:
-
currentRequest
Returns the last fully decoded request if it exists.- Returns:
- the request
-