Using XML to implement the architecture of multi-channel access Web site

Source: Internet
Author: User
Tags socket

In fact, the most purpose of writing this article is to show the framework that I used last year when I was doing a project in Switzerland. But I am also a little worried that my ability to express can not be used in the inside of the idea of a good performance, so I did not dare to write, and finally made up my mind, wrote it, not in a good change, Of course, I hope members will make some suggestions.

I. BACKGROUND

In the present website, the access channel is more and more, the technology is also more and more advanced, WAP, Sms,email, the traditional web, socket and so on, if even the database and LDAP also calculate access, that in the design need to expand the space to do very good good, To ensure that in the case of adding new channels do not need more changes in the code or even do not change the code. But is it possible? I think it is not possible, but what is the way to better solve this multi-channel access to the framework of the perfection of it?

Two. Framework


"Figure I"

As shown in figure I, in all the existing access has been used, the designers are dazzled, if it is to collections, then these procedures how to write can, but also certainly can be achieved, but maintenance will be more painful, or back to that question, how can achieve more perfect? In the framework discussion of the project team, I proposed the route of gratitude, and got a big


Home unified recognition, as shown in Figure II


"Figure II"

Figure II looks like an octopus with a eight claw, octopus legs are connected to all access channels, connecting all of these channels is the core of this octopus's head xmlrouter,router the role of this is to communicate all channels, the implementation of data routing, gaining system in the framework of scalability and flexibility, the benefits will be many. Xmlrouter is because if you do not use the flexible and normative language of XML as the medium of data transfer, the workload of router will also multiply, and the specification of XML will bring many benefits to future expansion.


Three. Ideas and patterns

Xmlrouter's original idea came from the builder pattern in the motherboard and <<design pattern>> of the computer, and the PCI slots in the computer's motherboard defined the PCI specification, as long as the cards you produce meet the PCI standards, Then you can plug into this motherboard to work, as to how the inside is already encapsulated. Builder pattern is proposed to separate the complex construction, step-by-step implementation. Xmlrouter is the separation of these complex channels, each one to perform.

Services thought: In order to be able to communicate with router, we must define a unified interface when these channels are connected, and as a services, we can access the router and route the data as long as the programs that meet the Services specification.

Factory mode and composite mode


Xmlrouter in the actual design will be produced by the Factory mode, router by the routerfactory production, put into use in the queue, the transfer of data and receive data and return data from the queue to take the corresponding router to invoke, The composite model has been applied.

Four. XML configuration file

The XML file is divided into two parts for use in router, and the first is the router configuration, such as:


  
<?xml version= "1.0"?>
<services>
<!--database Service-->
<service name= "Database" type= "database" class= "Com.web.service.DBService" >
<connector
Driver= "Com.microsoft.jdbc.sqlserver.SQLServerDriver"
Url= "jdbc:microsoft:sqlserver://192.168.0.179:1433" user= "test"
passwd= "Test"/>
</service>
<!--Web service-->
<service name= "web" type= "Web" class= "Com.web.service.WebService" >
<connector/>
</service>
......
</services>

This is the router configuration file, the service node represents the channel that needs to be connected, the service node contains the connector child nodes, the child nodes are configured according to type, and if the database contains the URL, user, passwd, Driver and other properties, if the socket contains port, maxthread and other attributes, property values can be configured according to their own definition.

Another XML file is an XML transaction data file that is used to pass data across all services, each of which includes a corresponding XML file, such as the Webtrans.xml format as follows:

  
<?xml version= "1.0"?>
<transaction>
<trans name= "Adddoc" service= "database" method= "Insert" >
<property name= "Createtime" type= "timestamp"/>
<property name= "Creatorid" type= "Long"/>
<property name= "Doctypeid" type= "int"/>
<property name= "Docstatusid" type= "int"/>
</trans>
</transaction>

The corresponding dbtrans.xml format is as follows

  
<trans name= "Adddoc" table= "Tdoc_docs" method= "Insert" >
<primarykey name= "DocId"/>
<set>
<property name= "Createtime" type= "timestamp"/>
<property name= "Creatorid" type= "Long"/>
<property name= "Doctypeid" type= "int"/>
<property name= "Docstatusid" type= "int"/>
</set>
</trans>

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.