16.3. The ReceivingMailServer

The ReceivingMailServer creates a ConnectionHandler for every SendingMailServer that connects to it. The ConnectionHandler directs the overall flow of the command/response operation. Commands are both used as the event that determines the next state and processed. We separate these actions by having both a state processor and a command processor. The state processor ensures that the commands are presented in a valid order, according to the state table (Figure 16-2). The command processor interprets the command, which for the most part involves updating the MailDTO, to be discussed shortly. The overall view of ConnectionHandler appears in Figure 16-3.

Figure 16-3. ConnectionHandler communication diagram

The ConnectionHandler class looks like this:

    class ConnectionHandler
        Connection connection
        ReceivedMailExaminer received_mail_examiner
        StateProcessor state_processor
        MailDTO mail_dto
        MailReport mail_report
        handle(  )
        send_greeting(  )
        Command receive_command(  )
        write_mail(  )
        process_command(Command command)

The Connection class represents the connection to the SendingMailServer. It looks like this:

    class Connection
        CommonString read_line(  ) throws ConnectionException
        write_line(CommonString line) throws ConnectionException
        drop(  )

Both read_line( ) and write_line( ) throw ConnectionException if an error occurred when sending or receiving characters. ...

Get Prefactoring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.