3 minute read

Table of Contents

Overview

This post covers the following topics:

Simplified Acceptor-Connector framework implementation

I built a small, learning-oriented Acceptor-Connector framework to understand how the pattern works and how it fits into a layered design.

This version keeps the core architectural ideas from ACE while intentionally skipping production-level complexity.

The source code is available at https://github.com/yjung93/study_ACE_design_pattern

Structure

The implementation is organized into three layers:

  • Event infrastructure layer classes
  • Connection management layer classes
  • Application layer classes

The relationships between classes in this framework are shown below.
Class diagram — Acceptor-Connector framework (v1.1)

Event infrastructure layer classes

This simplified framework is built on top of a Reactor framework that provides event demultiplexing and dispatching. For details, see the previous post: Reactor Pattern.

Connection management layer classes

This layer provides generic, application-independent connection and initialization services. It consists of:

  • ServiceHandler
  • Acceptor
  • Connector

ServiceHandler

  • Defines the interfaces needed by an application service implementation.
  • Concrete services typically act as a client, a server, or both in a peer-to-peer system.
  • Created by an Acceptor or Connector when a connection is established.
  • Provides a hook that the Acceptor/Connector calls to activate the service once the connection is ready.
  • Exposes a transport endpoint used by the application service to communicate with its peer. The endpoint type is parameterized (template) so the OS-specific I/O implementation stays separate from application logic.

Class diagram — ServiceHandler

Acceptor

  • Passively establishes a connected transport endpoint.
  • Creates and initializes the associated ServiceHandler when a connection is accepted.
  • Decouples acceptance/initialization from the ServiceHandler that runs application logic.

Class diagram — Acceptor

Interaction sequence
Sequence — connection acceptance via Acceptor

Connector

  • Actively establishes a connected transport endpoint.
  • Creates and initializes the associated ServiceHandler when the connection completes.
  • Decouples initiation/initialization from the ServiceHandler that runs application logic.
  • Supports synchronous and asynchronous connection.

Class diagram — Connector

Interaction sequence (synchronous)
Sequence — synchronous connect with Connector

Interaction sequence (asynchronous)
Sequence — asynchronous connect with Connector

Application layer classes

This layer customizes the generic strategies from the infrastructure and connection layers (via subclassing, composition, and/or template instantiation) to create concrete components that establish connections, exchange data, and implement service behavior.

Server application

Demonstration server: waits for client connections, accepts them, and echoes messages received from clients.

Component diagram — example server (Acceptor-Connector)

AcceptorImpl
  • Concrete subclass of Acceptor.
  • Plays the acceptor role by deriving from the Acceptor class.
InputHandler
  • Concrete subclass of ServiceHandler.
  • Handles client I/O and echoes back received messages.

Client application

Demonstration client: sends user-typed messages to the server and displays the responses.

Component diagram — example client (Acceptor-Connector)

Client
  • A facade that composes a Connector and a ServiceHandler.
ConnectorImpl
  • Concrete subclass of Connector.
  • Plays the connector role by deriving from the Connector class.
OutputHandler
  • Concrete subclass of ServiceHandler.
  • Forwards user-typed messages to the server and prints replies.
Dynamics

This diagram shows how the client and server components interact to establish connections and run the service logic.

Sequence — end-to-end example (client ↔ server)

Directory and file structure

Related source files:

├── applications
│   ├── example_acceptor_connector
│   │   ├── AcceptorImpl.cpp
│   │   ├── AcceptorImpl.hpp
│   │   ├── Client.cpp
│   │   ├── Client.hpp
│   │   ├── ConnectorImpl.cpp
│   │   ├── ConnectorImpl.hpp
│   │   ├── InputHandler.cpp
│   │   ├── InputHandler.hpp
│   │   ├── MainClient.cpp
│   │   ├── MainServer.cpp
│   │   ├── OutputHandler.cpp
│   │   └── OutputHandler.hpp
├── framework
│   ├── acceptor_connector
│   │   └── 1_0
│   │       ├── Acceptor.cpp
│   │       ├── Acceptor.hpp
│   │       ├── Config.hpp
│   │       ├── Connector.cpp
│   │       ├── Connector.hpp
│   │       ├── ServiceHandler.cpp
│   │       ├── ServiceHandler.hpp
│   │       ├── SockAcceptor.cpp
│   │       ├── SockAcceptor.hpp
│   │       ├── SockConnector.cpp
│   │       ├── SockConnector.hpp
│   │       ├── SockStream.cpp
│   │       └── SockStream.hpp