Routing method, device, computer system and computer readable storage medium

文档序号:1952139 发布日期:2021-12-10 浏览:17次 中文

阅读说明:本技术 路由方法、装置、计算机系统及计算机可读存储介质 (Routing method, device, computer system and computer readable storage medium ) 是由 王志昱 于 2021-04-02 设计创作,主要内容包括:本公开提供了一种基于代码插桩技术的路由方法,包括:在业务模块的编译阶段,通过代码插桩技术在业务模块的初始化方法中添加路由注册类、路由拦截器注册类、路由匹配器注册类的初始化方法,初始化路由注册类、路由拦截器注册类、路由匹配器注册类;通过路由注册类将表示业务模块的各子模块的路由字符串和类名注册到路由表中,通过路由拦截器注册类将至少一个路由拦截器注册到路由拦截器链中,通过路由匹配器注册类将至少一个路由匹配器注册到路由匹配器链中;当调用业务模块的其中一个子模块时,根据路由表、路由拦截器链、路由匹配器链获取对应的路由拦截器和/或路由匹配器;在路由拦截器和/或路由匹配器的验证通过后,运行子模块。(The present disclosure provides a routing method based on a code instrumentation technique, including: in the compiling stage of the service module, adding initialization methods of a route registration class, a route interceptor registration class and a route matcher registration class in an initialization method of the service module through a code instrumentation technology, and initializing the route registration class, the route interceptor registration class and the route matcher registration class; registering a routing character string and a class name representing each sub-module of a service module in a routing table through a routing registration class, registering at least one routing interceptor in a routing interceptor chain through a routing interceptor registration class, and registering at least one routing matcher in a routing matcher chain through a routing matcher registration class; when one sub-module of the service module is called, acquiring a corresponding route interceptor and/or a route matcher according to the route table, the route interceptor chain and the route matcher chain; and after the verification of the route interceptor and/or the route matcher is passed, the sub-module is operated.)

1. A routing method, comprising:

in the compiling stage of the service module, adding initialization methods of a route registration class, a route interceptor registration class and a route matcher registration class in the initialization method of the service module through a code instrumentation technology;

when the service module is initialized, initializing the route registration class, the route interceptor registration class and the route matcher registration class;

registering the routing character strings and class names representing the sub-modules of the service module into a routing table through the routing registration class, registering at least one routing interceptor into a routing interceptor chain through the routing interceptor registration class, and registering at least one routing matcher into a routing matcher chain through the routing matcher registration class;

when one of the sub-modules of the service module is called, acquiring a corresponding route interceptor and/or a route matcher according to the route table, the route interceptor chain and the route matcher chain;

and after the verification of the route interceptor and/or the route matcher is passed, operating the sub-module.

2. The method of claim 1, wherein:

the routing character string, the routing interceptor and the routing matcher are pre-programmed in the annotation of the corresponding sub-module.

3. The method of claim 2, wherein the adding, in the initialization method of the service module, the route registration class, the route interceptor registration class, and the route matcher registration class by using a code instrumentation technique in the compiling stage of the service module comprises:

generating the route registration class, the route interceptor registration class and the route matcher registration class according to all the route character strings, the route interceptors and the route matchers included in the annotation;

scanning to obtain the route registration class, the route interceptor registration class and the route matcher registration class;

and acquiring an initialization method of the service module, and adding the initialization methods of the route registration class, the route interceptor registration class and the route matcher registration class into the initialization method of the service module.

4. The method of claim 2, when the routing registration class, the routing interceptor registration class, and the routing matcher registration class are initialized, respectively invoking the registration methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration to perform the registration of the routing character string, the routing interceptor, and the routing matcher, comprising:

scanning a routing character string, a routing interceptor and a routing matcher in the annotation of each sub-module;

and registering all the routing character strings and the class names of the corresponding sub-modules in a routing table, registering all the routing interceptors in a routing interceptor chain, and registering all the routing matchers in a routing matcher chain.

5. The method according to claim 1, wherein when one of the sub-modules of the service module is called, acquiring a corresponding route interceptor and/or route matcher according to the routing table, the route interceptor chain, and the route matcher chain includes:

when a first submodule of the service module sends a routing request for calling a second submodule of the service module, acquiring a routing character string of the second submodule prestored in the first submodule;

acquiring the class name of the second submodule from the routing table according to the routing character string;

and acquiring a corresponding route interceptor from the route interceptor chain according to the class name, and/or acquiring a corresponding route matcher from the route matcher chain.

6. The method of claim 5, wherein the chain of route interceptors is a chain of responsibility, and the obtaining the corresponding route interceptor from the chain of route interceptors according to the class name comprises:

enabling the route interceptors on the route interceptor chain to sequentially intercept the route requests;

if one of the route interceptors is matched with the class name of the second sub-module, executing an interception operation;

and when any route interceptor on the route interceptor executes the intercepting operation, terminating the route request.

7. The method of claim 6, further comprising:

and when no route interceptor on the route interceptor executes the interception operation, enabling a route matcher on the route matcher chain to process the route request.

8. A routing device, comprising:

a code instrumentation module, configured to add an initialization method of a route registration class, a route interceptor registration class, and a route matcher registration class in an initialization method of the service module through a code instrumentation technology at a compiling stage of the service module;

the initialization module is used for initializing the route registration class, the route interceptor registration class and the route matcher registration class when the service module is initialized;

a route registration module, configured to register a route string and a class name, which represent each sub-module of the service module, in a route table through the route registration class, register at least one route interceptor in a route interceptor chain through the route interceptor registration class, and register at least one route matcher in a route matcher chain through the route matcher registration class;

the route execution module is used for acquiring a corresponding route interceptor and/or route matcher according to the route table, the route interceptor chain and the route matcher chain when one of the sub-modules of the service module is called;

and the calling execution module is used for operating the sub-module after the verification of the route interceptor and/or the route matcher is passed.

9. A computer system, comprising:

one or more processors;

a memory for storing one or more programs,

wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-7.

10. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to carry out the method of any one of claims 1 to 7.

Technical Field

The present disclosure relates to the technical field of computer technologies, and in particular, to a routing method, device, computer system, and computer-readable storage medium based on a code instrumentation technique.

Background

With the development of mobile end technology and the increase of service demand, the code amount of mobile end items is also increasing. In order to reduce the coupling degree between service requirements and improve the independence of service modules, modular development and operation are carried out. However, since the components are independent of each other and cannot be called, page jump and parameter passing become very difficult. Based on this, a routing framework that allows convenient hopping and participation between components is important.

In the prior art, all route annotations in a project are scanned during program compiling, a route character string in the annotations is analyzed to generate a route table, the route table is loaded when the project is initialized, when a page jumps, the matching is carried out through the character string to be jumped and the character string in the route table, and the corresponding page is jumped if the matching is successful.

In implementing the disclosed concept, the inventors found that there are at least the following problems in the related art: first, there are many operations that require user configuration, such as initialization operation of a routing framework, maintenance operation of a routing string, etc., and if a developer of a program forgets to perform a certain configuration due to negligence or a fault occurs while performing a certain operation, the program runs abnormally, which may waste a lot of debugging and debugging time. Secondly, the matching of the route is limited to the jump between the application internal pages, and is not flexible enough, and if some special processing is required to be performed on the route through some customized rules, such as jumping to a certain system page, making some data requests before the route, converting one route into two routes, and the like, the matching cannot be realized by using the prior art.

Disclosure of Invention

In view of the above, the present disclosure provides a routing method, apparatus, computer system and computer-readable storage medium based on code instrumentation.

One aspect of the present disclosure provides a routing method, including: in the compiling stage of the service module, adding initialization methods of a route registration class, a route interceptor registration class and a route matcher registration class in the initialization method of the service module through a code instrumentation technology; when the service module is initialized, initializing the route registration class, the route interceptor registration class and the route matcher registration class; registering the routing character strings and class names representing the sub-modules of the service module into a routing table through the routing registration class, registering at least one routing interceptor into a routing interceptor chain through the routing interceptor registration class, and registering at least one routing matcher into a routing matcher chain through the routing matcher registration class; when one of the sub-modules of the service module is called, acquiring a corresponding route interceptor and/or a route matcher according to the route table, the route interceptor chain and the route matcher chain; and after the verification of the route interceptor and/or the route matcher is passed, operating the sub-module.

According to the embodiment of the disclosure, the routing character string, the routing interceptor and the routing matcher are pre-programmed in the annotations of the corresponding sub-modules.

According to an embodiment of the present disclosure, in the compiling stage of the service module, the initialization method for adding the route registration class, the route interceptor registration class, and the route matcher registration class in the initialization method of the service module by using the code instrumentation technology includes: generating the route registration class, the route interceptor registration class and the route matcher registration class according to all the route character strings, the route interceptors and the route matchers included in the annotation; scanning to obtain the route registration class, the route interceptor registration class and the route matcher registration class; and acquiring an initialization method of the service module, and adding the initialization methods of the route registration class, the route interceptor registration class and the route matcher registration class to the end of the initialization method of the service module.

According to the embodiment of the present disclosure, after the routing registration class, the routing interceptor registration class, and the routing matcher registration class are initialized, the method for registering the routing registration class, the routing interceptor registration class, and the routing matcher registration class is respectively invoked to register the routing character string, the routing interceptor, and the routing matcher, including: scanning a routing character string, a routing interceptor and a routing matcher in the annotation of each sub-module; and registering all the routing character strings and the class names of the corresponding sub-modules in a routing table, registering all the routing interceptors in a routing interceptor chain, and registering all the routing matchers in a routing matcher chain.

According to an embodiment of the present disclosure, when one of the sub-modules of the service module is called, acquiring a corresponding route interceptor and/or route matcher according to the routing table, the route interceptor chain, and the route matcher chain includes: when a first submodule of the service module sends a routing request for calling a second submodule of the service module, acquiring a routing character string of the second submodule prestored in the first submodule; acquiring the class name of the second submodule from the routing table according to the routing character string; and acquiring a corresponding route interceptor from the route interceptor chain according to the class name, and/or acquiring a corresponding route matcher from the route matcher chain.

According to an embodiment of the present disclosure, the route interceptor chain is a duty chain mode, and the obtaining a corresponding route interceptor from the route interceptor chain according to the class name includes: enabling the route interceptors on the route interceptor chain to sequentially intercept the route requests; if one of the route interceptors is matched with the class name of the second sub-module, executing an interception operation; and when any route interceptor on the route interceptor executes the intercepting operation, terminating the route request.

According to an embodiment of the present disclosure, further comprising: and when no route interceptor on the route interceptor executes the interception operation, enabling a route matcher on the route matcher chain to process the route request.

Another aspect of the present disclosure provides a routing apparatus, including: a code instrumentation module, configured to add an initialization method of a route registration class, a route interceptor registration class, and a route matcher registration class in an initialization method of the service module through a code instrumentation technology at a compiling stage of the service module; the initialization module is used for initializing the route registration class, the route interceptor registration class and the route matcher registration class when the service module is initialized; a route registration module, configured to register a route string and a class name, which represent each sub-module of the service module, in a route table through the route registration class, register at least one route interceptor in a route interceptor chain through the route interceptor registration class, and register at least one route matcher in a route matcher chain through the route matcher registration class; the route execution module is used for acquiring a corresponding route interceptor and/or route matcher according to the route table, the route interceptor chain and the route matcher chain when one of the sub-modules of the service module is called; and the calling execution module is used for operating the sub-module after the verification of the route interceptor and/or the route matcher is passed.

Another aspect of the present disclosure provides a computer system comprising: one or more processors; memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of the first aspects.

Another aspect of the disclosure provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to implement the method of any one of the first aspects.

According to the embodiment of the disclosure, complicated configuration operations such as initialization of the framework are automatically completed by the framework through a code instrumentation technology, thereby avoiding unnecessary debugging and debugging time waste caused by configuration errors of developers, and simultaneously reducing the intrusiveness of the framework code; the unified route matching interface can be provided for the outside, so that development personnel can customize the route interceptor and the route matcher to process complex route logic in the demand, and the flexibility of the project is improved.

Drawings

The above and other objects, features and advantages of the present disclosure will become more apparent from the following description of embodiments of the present disclosure with reference to the accompanying drawings, in which:

fig. 1 schematically illustrates an exemplary system architecture to which the routing methods and apparatus of the present disclosure may be applied;

FIG. 2 schematically illustrates a flow chart of a routing method according to an embodiment of the present disclosure;

fig. 3 schematically shows a detailed flowchart of step S210 of the routing method according to an embodiment of the present disclosure;

fig. 4 schematically shows a detailed flowchart of step S240 of the routing method according to an embodiment of the present disclosure;

fig. 5 schematically shows a detailed flowchart of step S430 of the routing method according to an embodiment of the present disclosure;

FIG. 6 schematically shows a block diagram of a routing device according to an embodiment of the present disclosure; and

fig. 7 schematically illustrates a block diagram of a computer system 700 suitable for implementing a routing device according to an embodiment of the present disclosure.

Detailed Description

Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.

The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.

All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.

Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). Where a convention analogous to "A, B or at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B or C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).

The embodiment of the disclosure provides a routing method and a routing device, which can realize the compiling stage of a service module by a code instrumentation technology, and add a routing registration class, a routing interceptor registration class and an initialization method of a routing matcher registration class in the initialization method, so that when the service module is initialized, the routing registration class, the routing interceptor registration class and the routing matcher registration class are initialized, thereby realizing the registration of a routing character string, a routing interceptor and a routing matcher of each sub-module of the service module, when one sub-module of the service module is called, the corresponding routing interceptor and/or the routing matcher are obtained according to a routing table, a routing interceptor chain and a routing matcher chain, and after the verification of the routing interceptor and/or the routing matcher is passed, the sub-module is operated.

Fig. 1 schematically illustrates an exemplary system architecture 100 of a method, apparatus, and computer program product that may be routed according to an embodiment of the disclosure. It should be noted that fig. 1 is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.

As shown in fig. 1, the system architecture 100 according to this embodiment may include an application layer, a routing interface layer, and a routing capability layer, wherein the application layer may include a project main module 110 (i.e., a traffic module), a sub-module 111, a routing matcher 120, and a routing interceptor 130, the routing interface layer may include a routing table 140, a routing matcher chain 150, and a routing interceptor chain 160, and the routing capability layer may include a code instrumentation module 170, an annotation module 180, and an annotation processing module 190.

Each sub-module 111 is provided with a route annotation, a route interceptor annotation and a route matcher annotation, wherein the route annotation at least includes a route character string (not shown) of the sub-module 111, the route interceptor annotation includes at least one code of a route interceptor related to the sub-module 111, and the route matcher annotation includes at least one code of a route matcher related to the sub-module 111.

The routing table 140 is used for storing the routing character strings and class names of the sub-modules, the routing matcher chain 150 is used for storing the routing matchers, the routing interceptor chain 160 is used for storing the routing interceptors, and the corresponding routing interceptors and/or routing matchers can be called when accessing the sub-modules according to the routing table, the routing matcher chain 150 and the routing interceptor chain 160 so as to realize interception and/or matching operation when accessing the sub-modules.

The annotation processing module 190 is configured to generate a corresponding registration class according to the routing string, the route matcher 120, and the route interceptor 130; the annotation module 180 is configured to assist the annotation processing module 190 in scanning the annotation of the sub-module, so that the annotation processing module 190 generates a corresponding registration class according to the routing character string in the annotation, the route matcher 120, and the route interceptor 130; the code instrumentation module 170 is used for inserting the initialization code of the registered class into the initialization code of the project main module 110, so as to realize the automatic generation and insertion of the registered class code. When the project main module 110 is initialized, the corresponding registration classes generated by the route matcher 120 and the route interceptor 130 are initialized correspondingly, a route table 140, a route matcher chain 150 and a route interceptor chain 160 are generated, when a certain sub-module 111 is called or accessed, the corresponding route interceptor 130 and/or the route matcher 120 in the route matcher chain 150 and the route interceptor chain 160 are obtained according to the route character string of the sub-module, and corresponding intercepting and/or matching operations are performed in a consistent manner.

It should be understood that the number of the item master module 110, the sub-modules 111, the route matcher 120, the route interceptors 130, the route table 140, the chain of route matchers 150, and the chain of route interceptors 160 in fig. 1 are merely illustrative. There may be any number of project masters 110, sub-modules 111, route matchers 120, route interceptors 130, route tables 140, route matcher chains 150, route interceptor chains 160, as desired for the implementation.

Fig. 2 schematically shows a flow chart of a routing method according to an embodiment of the present disclosure.

As shown in fig. 2, the method includes operations S210 to S230.

S210, in the compiling stage of the service module, adding initialization methods of a route registration class, a route interceptor registration class and a route matcher registration class in the initialization method of the service module through a code instrumentation technology.

S220, when the service module is initialized, initializing a route registration class, a route interceptor registration class and a route matcher registration class.

And S230, registering the routing character strings and class names representing the sub-modules of the service module into a routing table through a routing registration class, registering at least one routing interceptor into a routing interceptor chain through a routing interceptor registration class, and registering at least one routing matcher into a routing matcher chain through a routing matcher registration class.

S240, when one sub-module of the service module is called, the corresponding route interceptor and/or route matcher are/is obtained according to the route table, the route interceptor chain and the route matcher chain.

And S250, after the verification of the route interceptor and/or the route matcher is passed, operating the sub-module.

According to the embodiment of the disclosure, automatic generation of the route registration class, the route interceptor registration class and the route matcher registration class can be realized through a code instrumentation technology without manual configuration by a user; the route matcher and the route interceptor are compiled in the annotations of each sub-module, and unified management is carried out through a unified route interceptor chain and a route matcher chain, so that a developer can customize a route matching rule and a route mode thereof, and the flexibility is high.

The routing method described in FIG. 2 is further described below in conjunction with FIGS. 3-5.

Fig. 3 schematically shows a flow chart of the routing method step S210 according to an embodiment of the present disclosure.

As shown in fig. 3, step S210 may include steps S310 to S330.

S310, generating the route registration class, the route interceptor registration class and the route matcher registration class according to all the route character strings, the route interceptors and the route matchers included in the annotation.

According to the embodiment of the present disclosure, step S210 is performed in the compiling stage of the business module project, and the compiling of the business module of the general android application is divided into two stages, the first stage is a stage of compiling the java file into a class file, and the second stage is a stage of aggregating the class file into a dex file. When the first stage is reached, the annotation processing module in the routing capability layer starts working, scans all the routing annotations and routing matcher annotations under the module, and generates a corresponding routing registration class, a routing matcher registration class and a routing interceptor registration class.

According to an embodiment of the present disclosure, the code instrumentation module begins working when the compilation operation proceeds to the second phase. The module is actually a Gradle plug-in, and the responsibility of the Gradle plug-in is that when a compiler aggregates class files in a business module project into dex files, all elements in the class files are scanned, and when the elements meet a certain condition, a series of operations are performed on the elements, specifically steps S320-S330.

S320, scanning and obtaining the route registration class, the route interceptor registration class and the route matcher registration class.

S330, acquiring the initialization method of the service module, and adding the initialization methods of the route registration class, the route interceptor registration class and the route matcher registration class to the initialization method of the service module.

Specifically, in the disclosed embodiment, the code instrumentation module will perform two scans of the code in module 2. Recording all paths of all route registration classes, route matcher registration classes and route interceptor registration classes during first scanning; during the second scanning, an entry of a business module item, namely an onCreate lifecycle method of an Application sub-class, is searched, and when the lifecycle method is matched, initialization operations of a route registration class, a route matcher registration class and a route interceptor registration class obtained by the first scanning are added to the end of the method through an ASM instrumentation technology.

When a user runs a project of the service module, firstly, an onCreate life cycle method of an Application subclass is run, at this time, the initialization of a route registration class, a route matcher registration class and a route interceptor registration class which are inserted to the end of the method is run, after the initialization is completed, the registration methods of the route registration class, the route interceptor registration class and the route matcher registration class are respectively called, a route character string is registered to a route table, a route matcher is registered to a route matcher chain and a route interceptor is registered to the route interceptor chain, and the steps comprise S331 to S332.

S331, scanning the routing character string, the routing interceptor and the routing matcher in the annotation of each sub-module.

S332, registering all the routing character strings and the class names of the corresponding sub-modules in a routing table, registering all the routing interceptors in a routing interceptor chain, and registering all the routing matchers in a routing matcher chain.

In the embodiment of the disclosure, the route registration class, the route matcher registration class and the route interceptor registration class respectively include a register method for registration. After initializing the routing registration class, calling a register method of the routing registration class, and registering the routing character string of each sub-module and the class name of the sub-module in a routing table; after the registration class of the route matcher is initialized, calling a register method of the route matcher, and adding the class names of all the route matchers under the module into a route matcher chain; after the registration class of the route interceptor is initialized, the register method of the route interceptor is called, and the types of all the route interceptors under the module are added into a route interceptor chain.

According to the embodiment of the present disclosure, in the operation process after the service module completes initialization, if the call between the sub-modules occurs, the routing operation is executed according to step S240.

Fig. 4 schematically shows a flowchart of the routing method step S240 according to an embodiment of the present disclosure.

As shown in fig. 4, step S240 may include steps S410 to S430.

S410, when a first submodule of the service module sends a routing request for calling a second submodule of the service module, a routing character string of the second submodule, which is pre-stored in the first submodule, is obtained.

S420, obtaining the class name of the second sub-module from the routing table according to the routing character string.

S430, acquiring the corresponding route interceptor from the route interceptor chain according to the class name, and/or acquiring the corresponding route matcher from the route matcher chain.

According to the method, the related route interceptor and/or route matcher of the called second sub-module can be obtained, and the related intercepting and/or matching operation is completed.

Fig. 5 schematically shows a flow chart of the routing method step S430 according to an embodiment of the disclosure.

Specifically, the route interceptor chain is in a chain of responsibility mode, and the step S430 of acquiring the corresponding route interceptor from the route interceptor chain according to the class name includes steps S510 to S540.

S510, enabling the route interceptors on the route interceptor chain to sequentially intercept the route requests.

S520, if one of the route interceptors is matched with the class name of the second sub-module, executing an intercepting operation.

S530, when any route interceptor on the route interceptor executes the intercepting operation, terminating the route request.

And S540, when no route interceptor on the route interceptor executes the interception operation, enabling the route matcher on the route matcher chain to process the route request.

Steps S510 to S540 are described in detail below according to an embodiment.

For example, there are two sub-modules, Module1 and Module2, in Module1 there is a page PageA and in Module2 there is a page PageB. At present, according to business requirements, two buttons are arranged in a PageA page, and when a first button is clicked, a PageB page can be jumped to, but the PageB page requires that a user must log in, and if the user does not log in, the user jumps to a login page; clicking the second button will call a designated number. When a user clicks a first button in the PageA, a routing method is called, a routing character string of the PageB is transmitted in a method parameter, and at the moment, routing requests are sequentially intercepted in a routing interceptor chain. Since the chain of interceptors uses the design mode of the chain of responsibility, when any interceptor on the chain intercepts the route, the route request is terminated and the intercepting action of the interceptor is executed. For the above example, when the login interceptor on the chain detects that the current user has no login state, the interception method is executed, and the login page is jumped to; otherwise, if the user has a login state, the interceptor does not intercept, and the user directly jumps to pageB. When the user clicks the second button in PageA, the routing method is invoked, and tel is passed in the method parameters: 10010, and then walking the chain of interceptors first without being intercepted by the interceptors, and then walking the chain of route matcher, and then processing the route into a calling page of the jump system if the TelMatcher matches the route character string beginning with tel.

According to the routing method provided by the embodiment of the disclosure, automatic generation and initialization of registration classes of a route interceptor and a route matcher are realized through a code instrumentation technology, unnecessary debugging and debugging time waste caused by configuration errors of developers is avoided, and meanwhile, the intrudability of codes is reduced; the method can provide a uniform route matching interface for the outside, so that development personnel can customize the route interceptor and the route matcher to process complex route logic in the requirement, and the flexibility of the project is improved.

Fig. 6 schematically shows a block diagram of a routing device according to an embodiment of the present disclosure.

As shown in fig. 6, an embodiment of the present disclosure provides a routing apparatus 600, including: code instrumentation module 610, initialization module 620, route registration module 630, route execution module 640, and call execution module 650.

A code instrumentation module 610, configured to add an initialization method of a route registration class, a route interceptor registration class, and a route matcher registration class in an initialization method of the service module through a code instrumentation technique at a compiling stage of the service module;

an initialization module 620, configured to initialize the route registration class, the route interceptor registration class, and the route matcher registration class when the service module is initialized.

A route registration module 630, configured to register, in a route table, the route character string and the class name that represent each sub-module of the service module through the route registration class, register, through the route interceptor registration class, at least one route interceptor in a route interceptor chain, and register, through the route matcher registration class, at least one route matcher in a route matcher chain.

And the route execution module 640 is configured to, when one of the sub-modules of the service module is called, obtain a corresponding route interceptor and/or route matcher according to the routing table, the route interceptor chain, and the route matcher chain.

And calling the execution module 650, configured to run the sub-module after the verification of the route interceptor and/or the route matcher passes.

Any number of modules, sub-modules, units, sub-units, or at least part of the functionality of any number thereof according to embodiments of the present disclosure may be implemented in one module. Any one or more of the modules, sub-modules, units, and sub-units according to the embodiments of the present disclosure may be implemented by being split into a plurality of modules. Any one or more of the modules, sub-modules, units, sub-units according to embodiments of the present disclosure may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in any other reasonable manner of hardware or firmware by integrating or packaging a circuit, or in any one of or a suitable combination of software, hardware, and firmware implementations. Alternatively, one or more of the modules, sub-modules, units, sub-units according to embodiments of the disclosure may be at least partially implemented as a computer program module, which when executed may perform the corresponding functions.

For example, any number of the code instrumentation module 610, the initialization module 620, the route registration module 630, the route execution module 640, and the call execution module 650 may be combined into one module/unit/sub-unit to be implemented, or any one of the modules/units/sub-units may be split into a plurality of modules/units/sub-units. Alternatively, at least part of the functionality of one or more of these modules/units/sub-units may be combined with at least part of the functionality of other modules/units/sub-units and implemented in one module/unit/sub-unit. According to an embodiment of the present disclosure, at least one of the code instrumentation module 610, the initialization module 620, the route registration module 630, the route execution module 640, and the call execution module 650 may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or in any one of three implementations of software, hardware, and firmware, or in a suitable combination of any of them. Alternatively, at least one of the code instrumentation module 610, the initialization module 620, the route registration module 630, the route execution module 640, the call execution module 650 may be at least partially implemented as a computer program module, which when executed, may perform a corresponding function.

It should be noted that, the routing device portion in the embodiment of the present disclosure corresponds to the routing method portion in the embodiment of the present disclosure, and the description of the routing device portion specifically refers to the routing method portion, which is not described herein again.

FIG. 7 schematically illustrates a block diagram of a computer system suitable for implementing the above-described method, according to an embodiment of the present disclosure. The computer system illustrated in FIG. 7 is only one example and should not impose any limitations on the scope of use or functionality of embodiments of the disclosure.

As shown in fig. 7, a computer system 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. The processor 701 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 701 may also include on-board memory for caching purposes. The processor 701 may comprise a single processing unit or a plurality of processing units for performing the different actions of the method flows according to embodiments of the present disclosure.

In the RAM 703, various programs and data necessary for the operation of the system 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other by a bus 704. The processor 701 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 702 and/or the RAM 703. It is noted that the programs may also be stored in one or more memories other than the ROM 702 and RAM 703. The processor 701 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.

According to an embodiment of the present disclosure, the system 700 may also include an input/output (I/O) interface 705, the input/output (I/O) interface 705 also being connected to the bus 704. The system 700 may also include one or more of the following components connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.

According to embodiments of the present disclosure, method flows according to embodiments of the present disclosure may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program, when executed by the processor 701, performs the above-described functions defined in the system of the embodiment of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.

The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.

According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. Examples may include, but are not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.

For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 702 and/or the RAM 703 and/or one or more memories other than the ROM 702 and the RAM 703 described above.

The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.

Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.

The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

18页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:安卓平台编译管控方法、编译系统、装置、介质和设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!