Some personal understanding of the framework

Source: Internet
Author: User

Many times, why feel a book difficult to chew, two words, abstract, so-called abstract, but their own on these concepts do not understand, the program software design is the thing from the reality of the extraction, not big we restore into the inside is.

Here, I take the restaurant to eat to do than, when the HTTP this guest received reception, the front desk will be according to your request will be room number of rooms to you, you used to, this room is a servlet, and then through the menu à la carte, the menu is the Servlet method annotation, mapping the process of each dish production, No need to show on the display, only the guests to see the final dishes can be achieved, thus achieving the effect of isolation security, the table is a template, each different request returned results can be in this template to focus on the display, Modelandview and view parser also come in handy.

Then carefully decomposition of the process, when the HTTP reception, the hotel will be limited by the configuration, That is, your Web. XML will be set up for this hotel, that is, containers, when you enter the hotel, interception processing, often will confirm that you are booking and other matters, here take Struts2 dispatcher to explain, through the pretreatment of these requests, here is Prepareoperations's Like to deal with, in fact, it is a proxy object, serious implementation or dispatcher itself, by its forwarding processing, here do not paste the source code, you can open the IDE himself to see, think of the front desk waiter is not can be all kinds of change, and then its implementation of the task is not always the same, By processing the information provided by the guest, as the room number is the same as the one you put in a map, you can also see where struts and xwork converge, Is Dispatcher's Serviceaction method can see here is the dispatcher object's core logical dispatch method, plays the role of the transit station

* @since 2.3.17 * * Public voidserviceaction (httpservletrequest request, httpservletresponse response, actionmapping mapping)throwsservletexception {Map<string, object> extracontext =Createcontextmap (Request, response, mapping); //If There is a previous value stack, then create a new copy and pass it on to is used by the new ActionValuestack stack =(Valuestack) Request.getattribute (Servletactioncontext.struts_valuestack_key); BooleanNullstack = Stack = =NULL; if(nullstack) {Actioncontext CTX=Actioncontext.getcontext (); if(CTX! =NULL) {Stack=Ctx.getvaluestack (); }        }        if(Stack! =NULL) {extracontext.put (Actioncontext.value_stack, Valuestackfactory.createvaluestack (STACK)); } String Timerkey= "Handling request from Dispatcher"; Try{Utiltimerstack.push (Timerkey); String namespace=Mapping.getnamespace (); String name=Mapping.getname (); String Method=Mapping.getmethod (); Actionproxy Proxy= GetContainer (). getinstance (actionproxyfactory.class). Createactionproxy (namespace, name, method, Extracontext,true,false);            Request.setattribute (Servletactioncontext.struts_valuestack_key, Proxy.getinvocation (). GetStack ()); //if the actionmapping says to go straight-a result, do it!            if(Mapping.getresult ()! =NULL) {result result=Mapping.getresult ();            Result.execute (Proxy.getinvocation ()); } Else{proxy.execute (); }            //If There is a previous value stack then set it back onto the request            if(!nullstack)            {Request.setattribute (servletactioncontext.struts_valuestack_key, stack); }        } Catch(ConfigurationException e) {logconfigurationexception (request, E);        Senderror (Request, response, Httpservletresponse.sc_not_found, E); } Catch(Exception e) {if(HandleException | |DevMode)            {Senderror (Request, response, Httpservletresponse.sc_internal_server_error, E); } Else {                Throw Newservletexception (e); }        } finally{utiltimerstack.pop (Timerkey); }    }
View Code

Similarly, we will see there are several cleanup methods, in the guest after dinner, need to clean up the mess, but also trouble dispatcher this dispatcher, get the framework is the life cycle of the event of the framework elements of the cleanup (there will always be a lot of remnants of the existence).

Similarly, for our people to the restaurant to eat this process, the middle of the design of the various small events, such as a la carte, some emergency special services, etc. will be in the beginning of the registration of the moment has been tied to a thread, for the framework is threadlocal, when we pay the money away, The bill will not be much use, leave a log can be left aside, the program is destroyed.

Re-analysis, when we order, the menu to the waiter, the waiter to the chef, after the kitchen finished food to the waiter, waiter served, in fact, here is involved in a chain of responsibility model, about the menu, but also involves a model, is the construction mode, the hotel according to the season and their advantages to design the menu, and then by the cook , and the guests only need to order.

When we spend much, often restaurants will discount or send things, this is involved in a strategy of the model, an interface with different strategies to achieve, minus 100 or greater strength, etc.

Sometimes we will encounter very wonderful things, is a dish, such as a plate of cucumber, often there will be a special tall on the name, and then a name on the plate of the price of cucumber to promote, to see how valuable decorative mode ...

See, a menu has so much knowledge, here at this level of the note contains the room number dish name, class annotations If write room number, method only write the name of the dish, otherwise each dish has to add room number, specific according to their own ideas to become

The realization of a framework is actually those things, various inseparable from the threadlocal mode decorative mode model mode of construction mode of responsibility chain Model Scheduler, source code from life, read the source when a lot of practice, understand well, knock it, that's the thing

In the next article, we summarize the comments

Some personal understanding of the framework

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.