Thrift Tserver Class System principle and source code detailed: Server base class Tserver

Source: Internet
Author: User
Tags abstract definition

This part mainly realizes the low-level IO communication, but also involves the communication server's jam, the Non jam, the single thread, the multithreading and so on Operation mode, therefore realizes is quite complex. The diagram of the classes involved in this section is as follows:

From the above class diagram, it can be seen that this part of the class relationship is more complex, complex is not the inheritance relationship, but the interdependence between each other. Because the server needs to handle many tasks, it also needs to handle multiple client connections, which involves multithreaded programming and the communication and concurrency between multithreading. This section of concurrent programming is discussed separately in the following chapters, and this chapter focuses on the specifics of the server model and IO communication.

First section server base class Tserver

All the specific server model implementation classes inherit from a common base class, which is the Tserver class described in this section, which inherits from Runnable, and the Runnable class is an abstract class that implements multithreading, similar to that in Java. The following describes the functionality defined by Tserver from the definition of member variables, constructors, and other related functions.

1. Member Variable definition

The member variable definition of a class can basically reflect the attributes of a class, first look at the definition of the main member variable and its function:

Object Generation Factory Object for boost::shared_ptr<tprocessorfactory> processorfactory_;//processing layer

boost::shared_ptr<tservertransport> servertransport_;//Server Transfer Object

boost::shared_ptr<ttransportfactory> inputtransportfactory_;//Input Transport Layer Factory object

boost::shared_ptr<ttransportfactory> outputtransportfactory_;//output Transport Layer factory object

boost::shared_ptr<tprotocolfactory> inputprotocolfactory_;//Input Protocol layer factory object

boost::shared_ptr<tprotocolfactory> outputprotocolfactory_;//output Protocol Layer factory object

Boost::shared_ptr<tservereventhandler> eventhandler_;//Server event handler object class

The Thrift server class basically combines the functionality of all the other layers, this enables each of the different server model implementations to assemble different processing layer logic (one layer of the Language Code field, based primarily on user-defined logical interfaces), protocol layer, and Transport layer, plus a class that handles events separately. The entire server is quite powerful and flexible. These objects are objects of an abstract base class that need to be implemented by a specific subclass when instantiated.

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.