Esframework introduction (3)-message processor and processor Factory

Source: Internet
Author: User
Whether it is a server or a client To process all received messages. Esframework In the Framework, the message processing component is called a message processor, and all message processors implement interfaces. Idatadealer :

1 Public   Interface Idatadealer
2 {
3 Netmessage dealrequestmessage (netmessage reqmsg );
4 }


Slave Dealrequestmessage Method signature. Netmessage The subject (byte stream) is parsed Icontract The object is completed by the message processor. This is also very practical. The message processor must be able to parse and process the messages it cares about, while the framework and other parts of the application do not have to worry about. Here, we first moved the message parsing task from the framework to the application. Here, we moved the task to the message processor. In this way, each message processor only needs to parse the messages it cares about. On this basis, we can make the message processor into a plug-in ( Addin And dynamically load the plug-in.
now let's look at the message processor plug-in (also known as "function plug-in")
//


// basic interface of the ifunaddin function plug-in.
//
Public interface ifunaddin: iaddin, idatadealer
{< br>
}

IaddinIs the Basic interface of the plug-in, inEnterprise-level server design and implementation experience-plugin System Basics A brief introduction has been made in this article.
For different types of messages (different message types are embodied in this messageHeaderInServicekeyDifferent), which must be processed and managed by different message processors./The factory that creates all these message processors, called the processor factory idatadealerfactory.

Public   Interface Idatadealerfactory
{
Idatadealer createdealer ( Int Requesttype, Int Servertypekey ); // Servertypekey, for example, city code
}

Idatadealerfactory creates a processor based on the message type. Createdealer The second parameter in the Method Servertypekey Do not worry about it for the time being.
As we have mentioned earlier, we have used plug-ins to Implement Message processors. Esframework The framework provides a plug-in-based Processor factory. Funaddindealerfactory The implementation of this factory requires the help of the plug-in Manager Iaddinmanagement For more information about plug-in manager, seeEnterprise-level server design and implementation experience-plugin System BasicsArticle. Funaddindealerfactory The implementation is as follows:
Funaddindealerfactory
1 Public   Class Funaddindealerfactory: idatadealerfactory
2 {
3 Private Iaddinmanagement addinmanagement;
4
5 Public Funaddindealerfactory ()
6 {
7 }
8
9 # Region Property
10 Public Iaddinmanagement addinmanagement
11 {
12 Set
13 {
14 This . Addinmanagement = Value;
15 }
16 }
17 # Endregion
18
19 # Region Idatadealerfactory Member
20 Public Idatadealer createdealer ( Int Requesttype, Int Servertypekey)
21 {
22 Foreach (Iaddin addin In   This . Addinmanagement. addinlist)
23 {
24 If (Addin. servicekey = Requesttype) && (Addin. enabled ))
25 {
26 Return (Idatadealer) addin;
27 }
28 }
29
30 Return   Null ;
31 }
32
33 # Endregion
34 }

The above is a plug-in-based Processor factory, followedArticleWe will also provideTCPConnection Pool processor factory :)

Sometimes, an application often needs to intercept and intercept a certain type of message or a specific message, and then perform some deformation (such as compression and encryption) on it, these functions will be passedHookMechanism implementation,HookFollow the steps below to see how the mechanism works. 

EsframeworkIntroduction (4)―Message interceptorInetmessagehook

Previous Article: esframework introduction (2)-network communication message netmessage

Go to: esframework reusable Communication Framework (sequence)

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.