Package com.example.server.handler
Class ResponseHandler
java.lang.Object
com.example.server.handler.ResponseHandler
- All Implemented Interfaces:
MessageHandler<BodyMessage>
This class is responsible for handling outgoing responses to be sent to clients.
It receives a BodyMessage object containing the response message, and uses a ChatInterface
and TransportFactory to create a connection and send the response to the specified client.
-
Constructor Summary
ConstructorsConstructorDescriptionResponseHandler
(ChatInterface chatInterface, TransportFactory transportFactory) Constructor for ResponseHandler class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
handle
(BodyMessage message) Handles the outgoing response message to be sent to a client.
-
Constructor Details
-
ResponseHandler
Constructor for ResponseHandler class.- Parameters:
chatInterface
- The interface for managing client communication in the server.transportFactory
- The factory for creating TransportConnections.
-
-
Method Details
-
handle
Handles the outgoing response message to be sent to a client. It creates a TransportConnection using the TransportFactory, and sends the response message to the client. If there is an IOException, it logs an error message and removes the user from the chatInterface.- Specified by:
handle
in interfaceMessageHandler<BodyMessage>
- Parameters:
message
- The BodyMessage object containing the response message, IP, and port.
-