Routing Method, Device, Computer System, and Computer Readable Storage Medium
By adding route registration classes, interceptor registration classes and matcher registration classes in the compilation stage of the business module, the problems of page jump and parameter passing in component development are solved, and flexible routing processing is achieved and the risk of configuration errors is reduced.
Patent Information
- Application Number
- CN202110364676.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-02
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-04-02
AI Technical Summary
In the component development of the existing technology, page jumps and parameter transfers are difficult, and routing configuration operations are cumbersome, errors are prone to, and complex routing needs cannot be flexibly handled.
Using code insertion technology, the route registration class, the route interceptor registration class, and the route matcher registration class are added during the compilation stage of the business module. The route registration class is used to register the route string and class name into the routing table, and the route interceptor chain and the route matcher chain are used for routing processing.
Reduces user configuration errors, improves the flexibility of the routing framework and project independence, reduces the debugging and troubleshooting time of developers, and provides a unified routing matching interface.
Smart Images

Figure CN113778452B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of computer technologies, and more particularly, to a routing method, apparatus, computer system, and computer-readable storage medium based on code instrumentation technology. Background Art
[0002] With the development of mobile technologies and the increase in business requirements, the code volume of mobile projects is also constantly growing. To reduce the coupling degree between business requirements and improve the independence of business modules, component-based development has emerged. However, since each component is independent and cannot call each other, it has become very difficult to perform page jumps and parameter passing. Based on this, a routing framework that can facilitate jumps and parameter passing between components is very important.
[0003] The prior art generally scans all routing annotations in a project during program compilation, parses the routing strings in the annotations, and generates a routing table. The routing table is loaded during project initialization. When a page jump occurs, the string to be jumped to is matched with the strings in the routing table, and if the match is successful, the corresponding page is jumped to.
[0004] In the process of implementing the concept of the present disclosure, the inventors found that there are at least the following problems in the related art: First, there are many operations that need to be configured by the user, such as the initialization operation of the routing framework, the maintenance operation of the routing string, etc. If the developers of the program forget to perform a certain configuration due to negligence, or make a mistake when performing a certain operation, the program will run abnormally, which may waste a lot of time for debugging and error correction. Second, the matching of routes is limited to jumps between internal pages of the application, which is not flexible enough. If some custom rules are desired to perform some special processing on the routes, such as jumping to a certain system page, making some data requests before the route, converting one route into two routes, etc., the existing technology cannot be used to achieve this. Summary of the Invention
[0005] In view of this, the present disclosure provides a routing method, apparatus, computer system, and computer-readable storage medium based on code instrumentation technology.
[0006] One aspect of the present disclosure provides a routing method, including: in the compilation stage of the service module, adding the initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to the initialization method of the service module through code instrumentation technology; when the service module is initialized, initializing the routing registration class, the routing interceptor registration class, and the routing matcher registration class; registering the routing strings and class names representing the sub-modules of the service module to the routing table through the routing registration class, registering at least one routing interceptor to the routing interceptor chain through the routing interceptor registration class, and registering at least one routing matcher to the routing matcher chain through the routing matcher registration class; when calling one of the sub-modules of the service module, obtaining the corresponding routing interceptor and / or routing matcher according to the routing table, the routing interceptor chain, and the routing matcher chain; after the verification of the routing interceptor and / or the routing matcher passes, running the sub-module.
[0007] According to an embodiment of the present disclosure, the routing string, the routing interceptor, and the routing matcher are pre-written in the annotations of the corresponding sub-modules.
[0008] According to an embodiment of the present disclosure, in the compilation stage of the service module, adding the initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to the initialization method of the service module through code instrumentation technology includes: generating the routing registration class, the routing interceptor registration class, and the routing matcher registration class according to all the routing strings, routing interceptors, and routing matchers included in the annotations; scanning to obtain the routing registration class, the routing interceptor registration class, and the routing matcher registration class; obtaining the initialization method of the service module, and adding the initialization methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration class to the end of the initialization method of the service module.
[0009] According to an embodiment of the present disclosure, after the routing registration class, the routing interceptor registration class, and the routing matcher registration class are initialized, respectively calling the registration methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration class to register the routing string, the routing interceptor, and the routing matcher includes: scanning the routing strings, routing interceptors, and routing matchers in the annotations of each sub-module; registering all the routing strings and the class names of the corresponding sub-modules to the routing table, registering all the routing interceptors to the routing interceptor chain, and registering all the routing matchers to the routing matcher chain.
[0010] According to an embodiment of the present disclosure, when one of the sub-modules of the service module is called, obtaining the corresponding routing interceptor and / or routing matcher according to the routing table, the routing interceptor chain, and the routing matcher chain includes: when a first sub-module of the service module sends a routing request to call a second sub-module of the service module, obtaining the routing string of the second sub-module pre-stored in the first sub-module; obtaining the class name of the second sub-module from the routing table according to the routing string; obtaining the corresponding routing interceptor from the routing interceptor chain according to the class name, and / or obtaining the corresponding routing matcher from the routing matcher chain.
[0011] According to an embodiment of the present disclosure, the routing interceptor chain is in the responsibility chain pattern. Obtaining the corresponding routing interceptor from the routing interceptor chain according to the class name includes: causing the routing interceptors on the routing interceptor chain to sequentially intercept the routing request; if one of the routing interceptors on the routing interceptor matches the class name of the second sub-module, performing an interception operation; when any one of the routing interceptors on the routing interceptor performs the interception operation, terminating the routing request.
[0012] According to an embodiment of the present disclosure, it further includes: when no routing interceptor on the routing interceptor performs an interception operation, causing the routing matcher on the routing matcher chain to process the routing request.
[0013] Another aspect of the present disclosure provides a routing device, including: a code instrumentation module, configured to add initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to an initialization method of the service module through code instrumentation technology during a compilation stage of the service module; an initialization module, configured to initialize the routing registration class, the routing interceptor registration class, and the routing matcher registration class when the service module is initialized; a routing registration module, configured to register the routing strings and class names representing the sub-modules of the service module to a routing table through the routing registration class, register at least one routing interceptor to a routing interceptor chain through the routing interceptor registration class, and register at least one routing matcher to a routing matcher chain through the routing matcher registration class; a routing execution module, configured to obtain the corresponding routing interceptor and / or routing matcher according to the routing table, the routing interceptor chain, and the routing matcher chain when one of the sub-modules of the service module is called; and a call execution module, configured to run the sub-module after verification of the routing interceptor and / or the routing matcher passes.
[0014] Another aspect of the present disclosure provides a computer system, comprising: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method according to any one of the first aspect.
[0015] Another aspect of the present disclosure provides a computer-readable storage medium having executable instructions stored thereon, which when executed by a processor cause the processor to implement the method according to any one of the first aspect.
[0016] According to an embodiment of the present disclosure, through code instrumentation technology, cumbersome configuration operations such as initialization of the framework are automatically completed by the framework, avoiding waste of unnecessary debugging and troubleshooting time due to configuration mistakes of developers, and at the same time reducing the invasiveness of the framework code; a unified routing matching interface can be provided externally, allowing developers to customize routing interceptors and routing matchers to handle complex routing logics in requirements, improving the flexibility of the project. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Through the following description of the embodiments of the present disclosure with reference to the drawings, the above and other objects, features and advantages of the present disclosure will become clearer. In the drawings:
[0018] Figure 1 Schematically shows an exemplary system architecture to which the routing method and apparatus of the present disclosure can be applied;
[0019] Figure 2 Schematically shows a flowchart of the routing method according to an embodiment of the present disclosure;
[0020] Figure 3 Schematically shows a detailed flowchart of step S210 of the routing method according to an embodiment of the present disclosure;
[0021] Figure 4 Schematically shows a detailed flowchart of step S240 of the routing method according to an embodiment of the present disclosure;
[0022] Figure 5 Schematically shows a detailed flowchart of step S430 of the routing method according to an embodiment of the present disclosure;
[0023] Figure 6 Schematically shows a block diagram of the routing apparatus according to an embodiment of the present disclosure; and
[0024] Figure 7 Schematically shows a block diagram of a computer system 700 suitable for implementing the routing apparatus according to an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present disclosure. In the following detailed description, for the sake of explanation, numerous specific details are set forth in order to provide a comprehensive understanding of the embodiments of the present disclosure. However, obviously, one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present disclosure.
[0026] The terms used herein are merely for describing specific embodiments and are not intended to limit the present disclosure. The terms "including", "comprising", etc. used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0027] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those of ordinary skill in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0028] In the case of using expressions such as "at least one of A, B, and C, etc.", generally, it should be interpreted according to the meaning commonly understood by those of ordinary skill in the art (for example, "a system having at least one of A, B, and C" should include, but not be limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.). In the case of using expressions such as "at least one of A, B, or C, etc.", generally, it should be interpreted according to the meaning commonly understood by those of ordinary skill in the art (for example, "a system having at least one of A, B, or C" should include, but not be limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.).
[0029] Embodiments of the present disclosure provide a routing method and apparatus. Through code instrumentation technology, it is possible to add initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to the initialization method of a service module during the compilation phase of the service module. 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 the routing strings, routing interceptors, and routing matchers of the sub-modules of the service module. When one of the sub-modules of the service module is called, the corresponding routing interceptor and / or routing matcher are obtained according to the routing table, the routing interceptor chain, and the routing matcher chain. After the verification of the routing interceptor and / or routing matcher passes, the sub-module is run.
[0030] Figure 1 Schematically shown is an exemplary system architecture 100 that can implement a routing method and apparatus according to an embodiment of the present disclosure. It should be noted that Figure 1 The illustration is only an example of a system architecture to which the embodiments of the present disclosure can be applied, to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0031] As Figure 1 shown, the system architecture 100 according to this embodiment may include an application layer, a routing interface layer, and a routing capability layer. Among them, the application layer may include a project main module 110 (i.e., a service module), sub-modules 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. The routing capability layer may include a code instrumentation module 170, an annotation module 180, and an annotation processing module 190.
[0032] Among them, each sub-module 111 is provided with a routing annotation, a routing interceptor annotation, and a routing matcher annotation. Among them, the routing annotation includes at least the routing string of its sub-module 111 (not shown in the figure). The routing interceptor annotation includes at least one piece of code of a routing interceptor for its sub-module 111. The routing matcher annotation includes at least one piece of code of a routing matcher for its sub-module 111.
[0033] The routing table 140 is used to store the routing strings and class names of each sub-module. The routing matcher chain 150 is used to store each routing matcher. The routing interceptor chain 160 is used to store each routing interceptor. According to the routing table, the routing matcher chain 150, and the routing interceptor chain 160, corresponding routing interceptors and / or routing matchers can be called when accessing each sub-module, so as to implement interception and / or matching operations when accessing the sub-module.
[0034] The annotation processing module 190 is used to generate corresponding registration classes based on the routing string, the routing matcher 120, and the routing interceptor 130; the annotation module 180 is used to assist the annotation processing module 190 in scanning the annotations of the sub-modules, so that the annotation processing module 190 generates corresponding registration classes according to the routing string, the routing matcher 120, and the routing interceptor 130 in the annotations; the code instrumentation module 170 is used to insert the initialization code of the registration classes into the initialization code of the project main module 110 to realize the automatic generation and insertion of the registration class code. When the project main module 110 is initialized, the corresponding registration classes generated by the routing matcher 120 and the routing interceptor 130 are initialized accordingly to generate the routing table 140, the routing matcher chain 150, and the routing interceptor chain 160. When a certain sub-module 111 is called or accessed, the corresponding routing interceptor 130 and / or routing matcher 120 in the routing matcher chain 150 and the routing interceptor chain 160 are obtained according to the routing string of the sub-module, and corresponding interception and / or matching operations are performed.
[0035] It should be understood that Figure 1 the numbers of the project main module 110, the sub-module 111, the routing matcher 120, the routing interceptor 130, the routing table 140, the routing matcher chain 150, and the routing interceptor chain 160 in [[ ]] are only illustrative. According to the implementation requirements, there can be any number of project main modules 110, sub-modules 111, routing matchers 120, routing interceptors 130, routing tables 140, routing matcher chains 150, and routing interceptor chains 160.
[0036] Figure 2 The flowchart of the routing method according to an embodiment of the present disclosure is schematically shown.
[0037] As Figure 2 shown, the method includes operations S210 to S230.
[0038] S210, in the compilation stage of the service module, add the initialization methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration class to the initialization method of the service module through code instrumentation technology.
[0039] S220, when the service module is initialized, initialize the routing registration class, the routing interceptor registration class, and the routing matcher registration class.
[0040] S230, register the routing strings and class names representing the sub-modules of the service module into the routing table through the routing registration class, register at least one routing interceptor into the routing interceptor chain through the routing interceptor registration class, and register at least one routing matcher into the routing matcher chain through the routing matcher registration class.
[0041] S240. When calling one of the sub - modules of the business module, obtain the corresponding route interceptor and / or route matcher according to the route table, the route interceptor chain, and the route matcher chain.
[0042] S250. After the verification of the route interceptor and / or route matcher passes, run the sub - module.
[0043] According to the embodiments of the present disclosure, the automatic generation of the route registration class, the route interceptor registration class, and the route matcher registration class can be achieved through the code instrumentation technology without manual configuration by the user. The route matcher and the route interceptor are written in the annotations of each sub - module and are uniformly managed through a unified route interceptor chain and route matcher chain, enabling developers to customize the route matching rules and their routing methods with high flexibility.
[0044] Next, it will be combined with Figures 3 - 5 to Figure 2 further describe the
[0045] Figure 3 The flowchart of step S210 of the routing method according to the embodiments of the present disclosure is schematically shown.
[0046] As Figure 3 shown, step S210 may include steps S310 to S330.
[0047] S310. Generate the route registration class, the route interceptor registration class, and the route matcher registration class according to all the route strings, route interceptors, and route matchers included in the annotation.
[0048] According to the embodiments of the present disclosure, step S210 is executed in the compilation stage of the business module project. Generally, the compilation of the business module of an Android application is divided into two stages. The first stage is the stage of compiling.java files into.class files, and the second stage is the stage of aggregating.class files into.dex files. When proceeding to the first stage, the annotation processing module in the routing capability layer starts to work. It scans all the route annotations and route matcher annotations under the module and generates the corresponding route registration class, route matcher registration class, and route interceptor registration class.
[0049] According to the embodiments of the present disclosure, when the compilation operation proceeds to the second stage, the code instrumentation module starts to work. This module is actually a Gradle plugin. Its responsibility is to scan all the elements in the.class files when the compiler aggregates the.class files in the business module project into.dex files. When an element meets a certain condition, a series of operations are performed on the element, specifically steps S320 to S330.
[0050] S320, scan to obtain the route registration class, route interceptor registration class, and route matcher registration class.
[0051] S330, obtain the initialization method of the service module, and add the initialization methods of the route registration class, route interceptor registration class, and route matcher registration class to the initialization method of the service module.
[0052] Specifically, in the embodiment of the present disclosure, the code instrumentation module will scan the code in module2 twice. During the first scan, it will record the full paths of all route registration classes, route matcher registration classes, and route interceptor registration classes. During the second scan, it will look for the entry of the service module project, that is, the onCreate lifecycle method of the Application subclass. When this lifecycle method is matched, the initialization operations of the route registration class, route matcher registration class, and route interceptor registration class obtained from the first scan are added to the end of this method through ASM instrumentation technology.
[0053] When the user runs the project of the service module, it will first run to the onCreate lifecycle method of the Application subclass. At this time, it will run to the initialization of the route registration class, route matcher registration class, and route interceptor registration class that we instrumented at the end of this method. After the initialization is completed, the registration methods of the route registration class, route interceptor registration class, and route matcher registration class are called respectively to register the route string to the route table, register the route matcher to the route matcher chain, and register the route interceptor to the route interceptor chain, including steps S331 to S332.
[0054] S331, scan the route strings, route interceptors, and route matchers in the annotations of each sub-module.
[0055] S332, register all the route strings and the class names of the corresponding sub-modules to the route table, register all the route interceptors to the route interceptor chain, and register all the route matchers to the route matcher chain.
[0056] In the embodiment of the present disclosure, the route registration class, route matcher registration class, and route interceptor registration class each contain a register method for registration. After the route registration class is initialized, when its register method is called, the route strings and class names of each sub-module under the service module are registered to the route table. After the route matcher registration class is initialized, when its register method is called, the class names of all route matchers under this module are added to the route matcher chain. After the route interceptor registration class is initialized, when its register method is called, the types of all route interceptors under this module are added to the route interceptor chain.
[0057] According to an embodiment of the present disclosure, during the running process after the service module completes initialization, if a call between sub-modules occurs, a routing operation is performed according to step S240.
[0058] Figure 4 The flowchart of step S240 of the routing method according to an embodiment of the present disclosure is schematically shown.
[0059] As Figure 4 shown, step S240 may include steps S410 to S430.
[0060] S410, when a routing request for calling a second sub-module of the service module is sent by a first sub-module of the service module, obtain the routing string of the second sub-module pre-stored in the first sub-module.
[0061] S420, obtain the class name of the second sub-module from the routing table according to the routing string.
[0062] S430, obtain the corresponding routing interceptor from the routing interceptor chain according to the class name, and / or obtain the corresponding routing matcher from the routing matcher chain.
[0063] According to the above method, the relevant routing interceptor and / or routing matcher of the called second sub-module can be obtained to complete the relevant interception and / or matching operations.
[0064] Figure 5 The flowchart of step S430 of the routing method according to an embodiment of the present disclosure is schematically shown.
[0065] Specifically, the routing interceptor chain is in the responsibility chain pattern, and obtaining the corresponding routing interceptor from the routing interceptor chain according to the class name in step S430 includes steps S510 to S540.
[0066] S510, make the routing interceptors on the routing interceptor chain intercept the routing request in sequence.
[0067] S520, if one of the routing interceptors on the routing interceptor matches the class name of the second sub-module, perform an interception operation.
[0068] S530, when any one of the routing interceptors on the routing interceptor performs the interception operation, terminate the routing request.
[0069] S540, when no routing interceptor on the routing interceptor performs an interception operation, make the routing matcher on the routing matcher chain process the routing request.
[0070] The following details steps S510 - S540 according to a specific embodiment.
[0071] For example, there are two sub - modules, Module1 and Module2, in the business module. There is a page PageA in Module1 and a page PageB in Module2. Now, according to business requirements, there are two buttons on the PageA page. When the first button is clicked, it will jump to the PageB page, but the PageB page requires the user to be logged in. If not logged in, it will jump to the login page; when the second button is clicked, it will call a specified number. When the user clicks the first button on PageA, the routing method will be called, and the routing string of PageB is passed in as a method parameter. At this time, the routing request will be intercepted in the routing interceptor chain in sequence. Since the interceptor chain uses the responsibility chain design pattern, when any interceptor on the chain intercepts the routing, the routing request will terminate and the interception action of this interceptor will be executed. For the above example, when the login interceptor on the chain detects that the current user has no login status, it will execute its interception method and jump to the login page; conversely, if the user has a login status, this interceptor will not intercept, and thus directly jump to pageB. When the user clicks the second button on PageA, the routing method will be called, and the string "tel: 10010" is passed in as a method parameter. At this time, it first goes through the interceptor chain and is not intercepted by the interceptor, and then goes through the routing matcher chain. At this time, if the TelMatcher matches that the routing string starts with "tel", this routing will be processed into a jump to the system call phone page.
[0072] The routing method provided by the embodiments of the present disclosure realizes the automatic generation and initialization of the registration classes of the routing interceptor and the routing matcher through code instrumentation technology, avoiding unnecessary debugging and troubleshooting time wasted due to configuration mistakes of developers, and at the same time reducing the invasiveness of the code; this method can provide a unified routing matching interface externally, allowing developers to customize routing interceptors and routing matchers to handle complex routing logics in requirements, improving the flexibility of the project.
[0073] Figure 6 A block diagram of a routing device according to an embodiment of the present disclosure is schematically shown.
[0074] As Figure 6 shown, the embodiments of the present disclosure provide a routing device 600, including: a code instrumentation module 610, an initialization module 620, a routing registration module 630, a routing execution module 640, and a call execution module 650.
[0075] The code instrumentation module 610 is used to add 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 during the compilation stage of the service module through code instrumentation technology.
[0076] The initialization module 620 is used to initialize the route registration class, the route interceptor registration class, and the route matcher registration class when the service module is initialized.
[0077] The route registration module 630 is used to register the route strings and class names representing the sub-modules of the service module into the route table through the route registration class, register at least one route interceptor into the route interceptor chain through the route interceptor registration class, and register at least one route matcher into the route matcher chain through the route matcher registration class.
[0078] The route execution module 640 is used to obtain the corresponding route interceptor and / or route matcher according to the route table, the route interceptor chain, and the route matcher chain when calling one of the sub-modules of the service module.
[0079] The call execution module 650 is used to run the sub-module after the verification of the route interceptor and / or the route matcher passes.
[0080] According to the embodiments of the present disclosure, any multiple of the modules, sub-modules, units, and sub-units, or at least part of the functions of any multiple of them can 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 can be split into multiple modules for implementation. Any one or more of the modules, sub-modules, units, and sub-units according to the embodiments of the present disclosure can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on substrate, a system on package, an application specific integrated circuit (ASIC), or can be implemented by any other reasonable way of integrating or packaging the circuit in hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in an appropriate combination of any several of them. Alternatively, one or more of the modules, sub-modules, units, and sub-units according to the embodiments of the present disclosure can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding functions can be executed.
[0081] For example, any combination of the code instrumentation module 610, the initialization module 620, the routing registration module 630, the routing execution module 640, and the call execution module 650 may be combined and implemented in one module / unit / sub-unit, or any one of the modules / units / sub-units may be split into multiple modules / units / sub-units. Alternatively, at least part of the functions of one or more of these modules / units / sub-units may be combined with at least part of the functions 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 routing registration module 630, the routing execution module 640, and the call execution module 650 may be at least partially implemented 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 any other reasonable manner of integrating or packaging circuits, etc., implemented by hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in an appropriate combination of any several of them. Alternatively, at least one of the code instrumentation module 610, the initialization module 620, the routing registration module 630, the routing execution module 640, and the call execution module 650 may be at least partially implemented as a computer program module, which may perform corresponding functions when the computer program module is run.
[0082] It should be noted that the routing device part in the embodiments of the present disclosure corresponds to the routing method part in the embodiments of the present disclosure. For the description of the routing device part, please refer to the routing method part specifically, and details are not described herein again.
[0083] Figure 7 A block diagram of a computer system suitable for implementing the method described above according to an embodiment of the present disclosure is schematically shown. Figure 7 The computer system shown is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.
[0084] Such as Figure 7As shown, the 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., CPU), an instruction set processor, and / or a related chipset, and / or a dedicated microprocessor (e.g., an application-specific integrated circuit (ASIC)), and so on. The processor 701 may also include on-board memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0085] In the RAM 703, various programs and data required for the operation of the system 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. The processor 701 performs various operations of the method flow according to an embodiment of the present disclosure by executing the programs in the ROM 702 and / or the RAM 703. It should be noted that the programs may also be stored in one or more memories other than the ROM 702 and the RAM 703. The processor 701 may also perform various operations of the method flow according to an embodiment of the present disclosure by executing the programs stored in the one or more memories.
[0086] According to an embodiment of the present disclosure, the system 700 may further include an input / output (I / O) interface 705, and the input / output (I / O) interface 705 is also connected to the bus 704. The system 700 may further include one or more of the following components connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. 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, etc., is installed on the drive 710 as needed so that a computer program read from it can be installed into the storage section 708 as needed.
[0087] According to an embodiment of the present disclosure, the method flow according to the embodiments of the present disclosure can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes program codes for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 709, and / or installed from a removable medium 711. When the computer program is executed by a processor 701, the above functions defined in the system according to the embodiments of the present disclosure are executed. According to an embodiment of the present disclosure, the above-described systems, devices, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0088] The present disclosure also provides a computer-readable storage medium, which can be included in the device / device / system described in the above embodiments; or can exist alone without being assembled into the device / device / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiments of the present disclosure is implemented.
[0089] According to an embodiment of the present disclosure, the computer-readable storage medium can be a non-volatile computer-readable storage medium. For example, it can include but is not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, device, or device.
[0090] For example, according to an embodiment of the present disclosure, the computer-readable storage medium can include the above-described ROM 702 and / or RAM 703 and / or one or more memories other than ROM 702 and RAM 703.
[0091] The flowcharts and block diagrams in the accompanying drawings 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 diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than that noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0092] Those skilled in the art will appreciate that the features recited in the various embodiments and / or claims of the present disclosure may be combined and / or combined in various ways, even if such combinations or combinations are not explicitly recited in the present disclosure. In particular, without departing from the spirit and teachings of the present disclosure, the features recited in the various embodiments and / or claims of the present disclosure may be combined and / or combined in various ways. All such combinations and / or combinations fall within the scope of the present disclosure.
[0093] The embodiments of the present disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments have been described separately above, this does not mean that the measures in each embodiment cannot be used advantageously in combination. The scope of the present disclosure is defined by the appended claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art can make various substitutions and modifications, and all such substitutions and modifications should fall within the scope of the present disclosure.
Claims
1. A routing method, comprising: In the compilation stage of a service module, adding initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to the initialization method of the service module through code instrumentation technology; When the service module is initialized, initializing the routing registration class, the routing interceptor registration class, and the routing matcher registration class; Registering the routing strings and class names of each sub-module representing the service module into the routing table through the routing registration class, registering at least one routing interceptor into the routing interceptor chain through the routing interceptor registration class, and registering at least one routing matcher into the routing matcher chain through the routing matcher registration class; When calling one of the sub-modules of the service module, obtaining the corresponding routing interceptor and / or routing matcher according to the routing table, the routing interceptor chain, and the routing matcher chain; After the verification of the routing interceptor and / or the routing matcher passes, running the sub-module; After the routing registration class, the routing interceptor registration class, and the routing matcher registration class are initialized, respectively calling the registration methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration class to register the routing string, the routing interceptor, and the routing matcher, including: Scanning the routing strings, routing interceptors, and routing matchers in the annotations of each sub-module; Registering all the routing strings and the class names of the corresponding sub-modules into the routing table, registering all the routing interceptors into the routing interceptor chain, and registering all the routing matchers into the routing matcher chain; Wherein, the routing strings, routing interceptors, and routing matchers are pre-written in the annotations of the corresponding sub-modules.
2. The method according to claim 1, wherein the adding initialization methods of a routing registration class, a routing interceptor registration class, and a routing matcher registration class to the initialization method of the service module through code instrumentation technology in the compilation stage of the service module comprises: Generating the routing registration class, the routing interceptor registration class, and the routing matcher registration class according to all the routing strings, routing interceptors, and routing matchers included in the annotation; Scanning and obtaining the routing registration class, the routing interceptor registration class, and the routing matcher registration class; Obtaining the initialization method of the service module, and adding the initialization methods of the routing registration class, the routing interceptor registration class, and the routing matcher registration class to the initialization method of the service module.
3. The method according to claim 1, wherein the obtaining the corresponding routing interceptor and / or routing matcher according to the routing table, the routing interceptor chain, and the routing matcher chain when calling one of the sub-modules of the service module comprises: When a first sub-module of the service module sends a routing request to call a second sub-module of the service module, obtaining the routing string of the second sub-module pre-stored in the first sub-module; Obtaining the class name of the second sub-module from the routing table according to the routing string; Obtain the corresponding route interceptor from the route interceptor chain according to the class name, and / or obtain the corresponding route matcher from the route matcher chain.
4. The method according to claim 3, wherein the route interceptor chain is in the responsibility chain pattern, and the obtaining the corresponding route interceptor from the route interceptor chain according to the class name includes: Cause the route interceptors on the route interceptor chain to intercept the route request in sequence; If one of the route interceptors on the route interceptor matches the class name of the second sub-module, perform the interception operation; When any one of the route interceptors on the route interceptor performs the interception operation, terminate the route request.
5. The method according to claim 4, further comprising: When no route interceptor on the route interceptor performs the interception operation, cause the route matcher on the route matcher chain to process the route request.
6. A routing device, comprising: A code instrumentation module, configured to add initialization methods of a route registration class, a route interceptor registration class, and a route matcher registration class to an initialization method of the service module through code instrumentation technology during the compilation phase of the service module; An initialization module, 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, configured to register route strings and class names representing each sub-module of the service module into a route table through the route registration class, register at least one route interceptor into a route interceptor chain through the route interceptor registration class, and register at least one route matcher into a route matcher chain through the route matcher registration class; A route execution module, configured to obtain a corresponding route interceptor and / or route matcher according to the route table, the route interceptor chain, and the route matcher chain when calling one of the sub-modules of the service module; A call execution module, configured to run the sub-module after the verification of the route interceptor and / or the route matcher passes; After the route registration class, the route interceptor registration class, and the route matcher registration class are initialized, call the registration methods of the route registration class, the route interceptor registration class, and the route matcher registration class respectively to perform registration of route strings, route interceptors, and route matchers, including: Scan the route strings, route interceptors, and route matchers in the annotations of each sub-module; Register all the route strings and the class names of the corresponding sub-modules into the route table, register all the route interceptors into the route interceptor chain, and register all the route matchers into the route matcher chain; Wherein, the route strings, route interceptors, and route matchers are pre-written in the annotations of the corresponding sub-modules.
7. A computer system, comprising: One or more processors; A memory, configured to store one or more programs, Wherein, when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having executable instructions stored thereon, which when executed by a processor cause the processor to implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
AOP proxy framework implementation method and system, storage medium and electronic equipment
CN108196833A