Model-oriented software architecture 2-for concurrent and networked object models Reading Notes (10)-receiver-connector

Source: Internet
Author: User

3.4 receiver-connector (acceptor-connector)

1. Problem

In a connection-oriented network system, ApplicationsProgramA large number of configuration proxies are usually used to establish connections and initialize services. These configurationsCodeMost services process data exchanged between connection endpoints independently. Therefore, the tight coupling between the configuration code and the Service Processing code is not ideal, because the following four mandatory conditions cannot be solved:

1) It should easily change the connection role to support different application features.

2) the types of services, service implementations, and communication protocols should be easily added without affecting the existing connection establishment and service Initialization Configuration code.

3) connection establishment and service initialization policies change less frequently than communication protocols and services implemented by applications.

4) for large-scale networked systems, advanced operating system features such as Asynchronous connection mechanisms should be used to reduce connection establishment latency.

 

2. Solution

Separate the connection and initialization of Peer services in a networked application from the processes executed by these services after the connection and initialization.

Specifically, the application service is encapsulated in the peer service handler. Each service processing program implements half of the end-to-end services in networked applications. Use two factories to connect and initialize peer services: receivers and connectors. The two factories work together to create a full association between the two peer service handlers and the transport endpoints of their two connections. Each transport endpoint is encapsulated in a transport handle.

The receiver factory stands for the relevant peer service handler and passively establishes a connection after the connection request event sent by the remote peer service handler arrives. In turn, the connector factory indicates that the peer service handler actively establishes a connection with the specified remote peer service handler.

After the connection is established, the receiver and the connector factory initialize the corresponding peer service handler and send their respective transfer handles to them. Then, the peer service processor exchanges data using the transport handle through the connected transport endpoint for application-related processing. Generally, after the connection and initialization, the Service handler does not interact with the receiver and transmitter.

 

3. Structure

A passive transmission endpoint is a factory that listens to connection requests, accepts connection requests, and establishes a transport handle. The transport handle encapsulates the transport endpoint of the new connection. You can read and write the corresponding transfer handle to exchange data through the connected transmission endpoint.

 

The service handler defines half of the end-to-end services in the network system. In this end-to-end service, a specific service handler usually has both a client role and a server role. In peer-to-peer use, it can assume both roles. A service handler provides an activation Hook method to initialize a service handler connected to its peer. In addition, the Service processing program also includes a transfer handle for a closed transmission endpoint, such as a data-mode socket handle. Once connected, the Service handler uses the transport handle to exchange data with the peer service Handler through their connection endpoints.

 

The receiver is a factory that implements functions including passively establishing the connected transport endpoint, creating and initializing the relevant transport handle and service handler. A receiver provides two methods: Connection initialization and connection completion. These two methods implement the above functions with the help of the passive mode transmission endpoint.

When the initialization method is called, the receiver binds the passive mode transmission endpoint to a transmission address, such as a TCP port number and an IP host address, and passively listens for connection requests.

When the connection request arrives, perform the following three steps to complete the connection of the receiver:

· First, it creates a connection transport endpoint in passive mode and encapsulates the endpoint in the transport handle.

· Second, it creates a service processing program to process data requests sent by the peer service processing program through the connected transmission endpoint.

· Third, it stores the transfer handle in the corresponding service handler, and then calls the activation Hook method of the Service handler. This method allows the service handler to complete initialization.

 

The connector is also a factory. Its functions include actively establishing a connection transmission endpoint and initializing its corresponding transmission handle and service processing program. It provides two methods: Connection start and connection completion.

Send the connection start method to an existing service handler, which establishes a connection endpoint with the receiver. As described earlier, the receiver must be listening for connection requests on a certain transport address.

Separate the connection start and completion methods of the connector so that the connector supports transparent synchronous and asynchronous connection establishment.

· For synchronization, the connector that activates the connection request blocks its caller until the transmission endpoint is connected. Later, the connector directly calls the activation Hook method of the Service handler.

· For asynchronous connection requests, the connector activation method is returned immediately. The connection completion method activates the service handler only after the connector receives a notification that the transmission endpoint has completed the connection asynchronously.

Whether it is synchronous or asynchronous connection to the transmission endpoint, the receiver and connector initialize a service handler by calling its activation Hook method. Later, service handlers generally do not need to interact with the connector and receiver factory.

 

The distributor is responsible for multi-channel decomposition of indicator events that indicate different types of service requests (such as connection requests and data requests.

· For the receiver, the splitter breaks down the connection indication events received from one or more transport handles of the encapsulated transport endpoint. Multiple receivers can register the same distributor to listen for connection requests from the peer connector.

· For connectors, the distributor can break down the completion events that have arrived in response to asynchronous activation connections. To handle this situation, the connector registers itself with a distributor to receive these connection completion events and then runs its event loop. When the completion event arrives, it notifies the corresponding connector. Then the connector calls the activation Hook method of the specified service handler to let the service handler initialize itself. Therefore, a distributor and connector can represent multiple service handlers asynchronously activating and completing connections.

Note that the allocator is not required to establish an asynchronous connection, because the thread that starts the connection will be blocked by waiting for the connection to complete the event. Therefore, this thread can directly activate the service handler.

 

The specific service handler defines some end-to-end services related to the application and is activated by a specific receiver or connector. A specific receiver uses a specific service handler. The transport endpoint and the transport handle used by these service handlers instantiate the universal receiver. Similarly, a specific connector also instantiates a universal connector.

 

4. Implementation

The components in the receiver-connector mode can be divided into the following three layers:

· Multi-path decomposition/allocation of infrastructure layer components. This layer executes common event allocation policies unrelated to applications.

· Connect to the management layer components. This layer performs common application-independent connections and initialization services.

· Application Layer components. This layer is customized for the general policies of the upper two layers. It uses methods such as subclass derivation, object combination, and/or parameterization type Instantiation to create specific components. These specific components are used to establish connections, exchange data and perform service-related processing.

 

1) Implement Multi-path decomposition/allocation of infrastructure component layers.

1.1) Select transmission mechanisms, including:

· Passive mode transmission endpoint component.

· Connected transmission endpoint component.

· Transfer address component.

· Transfer handle component.

1.2) Implement the allocation mechanism. These mechanisms are composed of a distributor and an event handler component. The distributor is responsible for connecting requests with the corresponding receiver, connector and service handler. An event handler defines the event processing interfaces provided by services in an event-driven application.

2) Implement the connection management component layer. This layer is responsible for creating service handlers, actively or passively connecting service handlers to remote service handlers, and activating service handlers after the connection. All components at this layer are generic and dependent on specific IPC Mechanisms, specific service handlers, specific receivers, and specific connectors. There are three main components in the connection management layer: Service handlers, receivers and connectors.

2.1) define common service handler interfaces. A service handler provides a common interface defined by clients, servers, and end-to-end services (clients and servers. This interface includes initializing the Service Processing Program, executing the services it defines, and maintaining the IPC Mechanism for communication.

2.2) define a common receiver interface. The receiver component implements a general policy used to passively establish connections and initialize specific service handlers, these specific service handlers use these connections to exchange data with the peer service handler. The receiver also defines an initialization method, which is called by a program to notify other applications in the network of its passive mode transmission endpoint.

2.3) implement common receiver methods. The application initializes the receiver by calling its initialization method. When calling the initialization method, you must have a parameter that specifies the transmission address (such as the IP address and TCP port number of the local host. The receiver uses this address parameter to listen for connection requests initiated by the peer connector. It passes the address to the specific IPC Connection Mechanism configured to the universal receiver through the receiver's specific receiver subclass or by the typed parameter. Then, the IPC Connection Mechanism initializes the passive mode transmission endpoint of the receiver, and notifies the Remote Application of its address to establish a connection with the receiver.

2.4) define common connector interfaces. The connector component implements general policies for actively establishing connections and initializing service handlers that process connection requests and response events.

2.5) implement the general connector method. The application uses the connect () method of the connector to start a connection. The specific connector can use this template method to transparently modify the active connection policy without changing the connector interface and implementation. Therefore, connect () will hand over the specific steps in its connection policy to the hook method to complete, the specific connector can reload these hook methods for personalized operations.

3) Implement the application layer components. This layer implements specific service handlers, specific receivers, and specific connectors.

 

5. Conclusion

Advantages:

1) reusability, portability, and scalability. The receiver-connector mode separates the mechanism for connecting and initializing the service handler from the subsequent service processing. Application-independent mechanisms in receivers and connectors are reusable components.

2) robustness. Receiver-connector mode separates the service handler from the receiver. This separation ensures that the passive transmission endpoint cannot be used to read/write data. This increases type security and eliminates a type of errors that often occur when weak network programming interfaces are used.

3) high efficiency. Receiver-connector mode can be asynchronously and efficiently connected to a large number of hosts in a wide area network with high latency.

 

Disadvantages:

1) added the indirect property. Compared with the underlying network programming interface, the receiver-connector mode is not straightforward.

2) added complexity. For simple client applications that connect to only one server and use a single network programming interface to execute a service, the receiver-connector mode adds unnecessary complexity. However, the use of general receivers and connector wrappers can simplify the design of applications without worrying about the annoying, error-prone, and unportable low-layer network programming mechanism.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.