CN112769706B - Componentized routing method and system - Google Patents

Componentized routing method and system Download PDF

Info

Publication number
CN112769706B
CN112769706B CN202011550082.9A CN202011550082A CN112769706B CN 112769706 B CN112769706 B CN 112769706B CN 202011550082 A CN202011550082 A CN 202011550082A CN 112769706 B CN112769706 B CN 112769706B
Authority
CN
China
Prior art keywords
routing
component
class
annotations
annotation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011550082.9A
Other languages
Chinese (zh)
Other versions
CN112769706A (en
Inventor
朱祥吾
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202011550082.9A priority Critical patent/CN112769706B/en
Publication of CN112769706A publication Critical patent/CN112769706A/en
Application granted granted Critical
Publication of CN112769706B publication Critical patent/CN112769706B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/02Topology update or discovery
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/54Organization of routing tables
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering

Abstract

The embodiment of the invention provides a componentized routing method, which comprises the following steps: obtaining annotations added by a user and corresponding to the classes or methods related to the route; when a compiling instruction is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores the routing relation among all the components; when a Gradle plug-in constructing instruction is received, scanning annotations of all files in a preset project, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR, and the component class comprises an interface and a static agent class corresponding to the interface; and writing the corresponding relation between the interfaces in the component classes and the static agent classes into a routing table so as to find the corresponding relation and the routing relation from the routing table, and performing componentized routing according to the corresponding relation and the routing relation when receiving a routing request for the target component. The invention can support the routing of the components in the AAR, does not need to inherit the GoModule and realizes the complete decoupling among the components.

Description

Componentized routing method and system
Technical Field
The embodiment of the invention relates to the technical field of cloud transmission, in particular to a componentized routing method and a componentized routing system.
Background
Most existing products are developed in a modular manner across teams, and the decoupling problem between modules/components can be realized in a modular routing manner. There are numerous open source routing schemes in the industry, including: android routers (arouters), activitylRouter, and the like, among which the most well-known ARouter schemes of the current-genus Ali open source.
The ARouter has powerful functions, can be initialized and managed in groups according to needs, and supports flexible degradation schemes. But suffers from the following significant drawbacks: the calling of the componentized routing needs to acquire a Service interface file in advance and can be used after the Service interface file is forcibly transferred, and the process is obviously coupled seriously.
The activitylRouter is a known open source library on Github, is simple in function realization and easy to maintain, and has the defects that: 1) Only supporting the component routing under the current Module project, and not supporting the component routing in the AAR; 2) Componentized Router, which requires a Method of defining static in advance in the component, is incorporated into the reference. This is not friendly to the component developer, and the Method as the entry of the component probably needs to resolve multiple cases, which is neither elegant nor cumbersome.
In addition, the existing laddin Router scheme is simple to implement, and all components (components) need to inherit GoModule, so that decoupling is not thorough.
Disclosure of Invention
In view of the above, there is a need to provide a componentized routing Method, system, computer device and readable storage medium, which can solve the problems in the prior art that component routing in AAR is not supported, a Method of static is required to be defined in advance in a component, the unified entry is referred to, all components do not need to inherit GoModule, and decoupling is not complete.
In order to achieve the above object, an embodiment of the present invention provides a componentized routing method, where the method includes:
obtaining annotations added by a user and corresponding to a class or a method related to a route, wherein the annotations comprise: @ Router, @ RouterService and @ RouterMethod;
when a compiling instruction sent by the user is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores routing relations among all the components;
when a Gradle plug-in construction instruction sent by the user is received, scanning annotations of all files in a preset project of the software development kit, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR, and the component classes comprise interfaces and static agent classes corresponding to the interfaces;
writing the corresponding relation between the interface and the static agent class in the component class into the routing table so as to find the corresponding relation and the routing relation from the routing table; and
and when a routing request for a target component is received, performing componentized routing according to the corresponding relation and the routing relation in the routing table.
Optionally, the method further comprises:
before receiving a compiling instruction sent by the user, pre-configuring a plurality of supported target annotations into a processor, wherein the plurality of target annotations comprise: @ Router, @ RouterService and @ RouterMethod;
the identifying the annotation and generating a corresponding routing table according to the identification result includes:
comparing the annotation to the plurality of the target annotations to determine whether the annotation belongs to a plurality of the target annotations; and
and when the annotation belongs to a plurality of target annotations and the annotation is @ Router, generating the routing table according to the @ Router.
Optionally, the component class is identified by a corresponding class name, the static agent class is used to implement the interface, and the generating a component class corresponding to each component according to the annotation includes:
acquiring the class name of the component class;
generating the interface corresponding to each component by the class name according to the generation rule of I + class name + RouterService;
and generating the static Proxy class corresponding to the interface by the class name according to a generation rule of the class name + Proxy.
Optionally, the generating an interface corresponding to each component and a static agent class corresponding to the interface according to the annotation includes:
and generating the interface and the static agent class corresponding to the interface according to the @ RouterService and the @ RouterMethod.
Optionally, the method further comprises:
packaging the component classes into Jar packages so that each component dynamically adds the dependent Jar packages.
Optionally, the method further comprises:
and when routing is carried out, acquiring a corresponding component class instance according to the routing table, and calling a service according to the component class instance.
Optionally, the method further comprises:
creating a centralized management process;
acquiring routing information of all processes, and registering the routing information of all processes to the centralized management process;
when a first process in all processes carries out route skipping, the first process searches a corresponding path from the centralized management process to determine that the path exists in a second process;
and after the path and the second process are found, the path and the second process are called back to the first process, and then the target page is jumped according to the calling back result.
In order to achieve the above object, an embodiment of the present invention further provides a componentized routing system, which is applied to a software development kit, and includes:
the annotation acquisition module is used for acquiring annotations added by a user and corresponding to the class or method related to the route, wherein the annotations include: @ Router, @ RouterService and @ RouterMethod;
a routing table generation module, configured to identify the annotation when receiving a compiling instruction sent by the user, and generate a corresponding routing table according to the identified annotation, where the routing table stores routing relationships among the components;
the component class generation module is used for scanning annotations of all files in a preset project of the software development kit when a Gradle plug-in construction instruction sent by the user is received, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR (architecture analysis and reporting), and the component class comprises an interface and a static agent class corresponding to the interface;
a writing module, configured to write the correspondence between the interface in the component class and the static proxy class into the routing table, so as to find the correspondence between the component class and the routing relation from the routing table; and
and the routing module is used for performing componentized routing according to the corresponding relation and the routing relation in the routing table when receiving a routing request for a target component.
To achieve the above object, embodiments of the present invention further provide a computer device, a memory of the computer device, a processor, and a computer program stored in the memory and executable on the processor, where the computer program, when executed by the processor, implements the steps of the componentized routing method described above.
To achieve the above object, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, where the computer program is executable by at least one processor to cause the at least one processor to execute the steps of the componentized routing method described above.
The componentized routing method, the system, the computer equipment and the computer readable storage medium provided by the embodiment of the invention acquire annotations which are added by a user and correspond to the classes or methods related to the routing; when a compiling instruction sent by the user is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores routing relations among all components, so that all classes can call methods of other classes; when a Gradle plug-in construction instruction sent by the user is received, scanning annotations of all files in a preset project of the software development kit, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR, and the component classes comprise interfaces and static agent classes corresponding to the interfaces; writing the corresponding relation between the interface and the static agent class in the component class into the routing table so as to find the corresponding relation and the routing relation from the routing table; and when a routing request for a target component is received, performing componentized routing according to the corresponding relation and the routing relation in the routing table, supporting component routing in the AAR, and realizing complete decoupling among the components without inheriting GoModule, wherein a static Method is not required to be defined in the components in advance and is uniformly participated, so that the development efficiency of component developers is greatly improved, the development process is simplified, non-invasive injection and low-invasive component application are realized, and the generation efficiency of the routing table is greatly improved.
Drawings
FIG. 1 is a diagram of an exemplary environment architecture for a modular routing method according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating exemplary steps of a modular routing method according to an embodiment of the present invention;
FIG. 3 is a flow chart of another exemplary step of a componentized routing method according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating an exemplary method for generating interface and static proxy classes;
FIG. 5 is a flowchart illustrating exemplary steps of the componentized routing method according to an embodiment of the present invention;
FIG. 6 is a block diagram of a process of a modular routing system according to an embodiment of the present invention;
FIG. 7 is a diagram of a hardware architecture of a computer device according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the description relating to "first", "second", etc. in the present invention is for descriptive purposes only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
Fig. 1 is a diagram illustrating an exemplary application environment architecture of the modular routing method according to an embodiment of the present invention. The Application (APP) in fig. 1 includes a plurality of modules (modules), such as Module a, module B, etc., and an Android Archive (AAR) file. The componentized routing is realized by finding the lowest layer depended on Module (Base Module) and adding a routing table in the Module. In FIG. 1, each Module dynamically adds dependencies by creating a Base Module and by way of a Jar package, which is a Component Class (Component Class). That is, each Module dynamically adds the dependency of the Component Class to realize the addition of the routing table, and then realizes the componentized routing according to the added routing table.
Example one
Referring to fig. 2, a flow chart of steps for componentized routing of an embodiment of the present invention is shown. It is to be understood that the flow charts in the embodiments of the present method are not intended to limit the order in which the steps are performed. It should be noted that the present embodiment is exemplarily described with a computer device as an execution subject, and the computer device may include a mobile terminal such as a tablet computer, a notebook computer, a palm computer, and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The method specifically comprises the following steps:
step S101: obtaining a comment (Annotation) added by a user and corresponding to a Class (Class) or a Method (Method) related to a route, wherein the comment comprises: @ Router, @ RouterService, and @ RouterMethod.
Note that the annotation is a form of metadata, and can be added to Java source code, and classes, methods, variables, parameters, packets, and the like in Java can be annotated without direct influence on the annotated code.
In an exemplary embodiment, the user adds corresponding annotations to routing related classes or methods by using annotations, which the software development kit then obtains. Non-invasive injection can be realized through an annotation mode, and low-invasive component application is realized.
Step S102: when a compiling (compiler) instruction sent by the user is received, the annotation is identified, and a corresponding routing table (RouterMap) is generated according to the identified annotation, wherein the routing table stores the routing relation among all the components.
Specifically, when compiling, the annotation is parsed by using a Processor (Processor) of the JavaPoet, and then a corresponding routermap. The JavaPoet is a Java code generation framework and provides Java Application Interface (Application Interface) API generation.A Java source file generates codes correspondingly according to annotations, database modes, protocol formats and the like by using the JavaPoet.
When the class or method related to the routing is detected to be updated, the method can take effect in a recompilation (Rebuild) mode, automatically generates a corresponding routing table, supports module transplantation, realizes flexible plug-in and plug-out of the module, and has the characteristics of simple use, convenient maintenance and low invasiveness. The updating comprises the following steps: delete or add or modify operations.
In practical application, during the compiling period, the Processor only generates a RouterMap. It should be noted that javasissst is a class library used for processing Java bytecode. Javasissist provides a number of convenient ways by which bytecode can be generated and then executed by a Java Virtual Machine (JVM). And after the RouterMap.java file is obtained, continuously compiling the RouterMap.java file in the Gradle construction period to generate a RouterMap.class file. The Gradle is a construction tool and strongly supports multi-project construction.
By using the JavaPoet mode, the annotation can be automatically generated into codes, manual code maintenance is avoided, and the generation efficiency of the routing table is improved.
In an exemplary embodiment, as shown in fig. 3, the method further comprises:
step S201: before receiving a compiling instruction sent by the user, pre-configuring a plurality of supported target annotations into a processor, wherein the plurality of target annotations comprise: @ Router, @ RouterService and @ RouterMethod;
the step S102 of identifying the annotation and generating a corresponding routing table according to the identified annotation may include steps S202 to S203:
step S202: comparing the annotation with the plurality of the target annotations to determine whether the annotation belongs to a plurality of the target annotations;
step S203: and when the annotation belongs to a plurality of target annotations and the annotation is @ Router, generating the routing table according to the @ Router.
Specifically, the system-supported annotations are determined by pre-configuring a plurality of annotations into the processor prior to compilation. The added annotations are then compared with pre-configured annotations at compile time to determine whether the development is componentized based on the comparison. When the annotation belongs to one of the plurality of target annotations, then componentized development is determined, and then a routing table will be generated from the @ Router annotation. And judging the type of the annotation so as to generate a routing table according to the @ Router annotation in the compiling period.
Step S103: when a Gradle plug-in construction instruction sent by the user is received, the annotations of all files in the preset project of the software development kit are scanned, and a Component Class (Component Class) corresponding to each Component is generated according to the annotations, wherein the annotations of all files comprise AAR, and the Component classes comprise interfaces and static agent classes corresponding to the interfaces.
Note that the annotations of all files herein include Java Archive (JAR) and Android Archive (AAR). The JAR is a software package file format that is typically used to aggregate large numbers of Java class files, associated metadata and resource (text, pictures, etc.) files into one file in order to develop Java platform applications or libraries. AAR is a binary archive file of Android library items, containing all resources, such as: class and res resource files, etc.
Compared with the prior art that a reflection mode is adopted, the embodiment of the invention adopts a static agent mode to realize the binding of an Interface (Interface) and the realization of the Interface, greatly improves the processing performance of a computer and accelerates the processing speed of the computer.
In an exemplary embodiment, the component class is identified by a corresponding class name, and the static proxy class is used to implement the interface, that is, the proxy class is an implementation or method of the interface. Since the component classes include interfaces and static Proxy classes (Proxy), the step S103 of generating a component class corresponding to each component according to the annotations may include the following steps:
acquiring the class name of the component class;
generating the interface corresponding to each component by the class name according to the generation rule of I + class name + RouterService;
and generating the static Proxy class corresponding to the interface by the class name according to a generation rule of the class name + Proxy.
That is, the generation rule of the interface is: class name (ClassName) + routervice; the generation rule of the static agent class corresponding to the interface is as follows: className + Proxy.
Illustratively, fig. 4 shows a schematic diagram of an exemplary interface and static agent generation method. Java, wherein the Login is a functional component provided externally, and the generated Interface according to the Login is ILoginRouterService, namely the proxy class of the Login is LoginProxy.
In an exemplary embodiment, the generating a component class corresponding to each component according to the annotation includes: and generating the component class according to the @ RouterService and the @ RouterMethod.
In practical application, during the period of constructing the Gradle, the Gradle plug-in is required to be customized, then an initial Jar package with a preset name is checked or created, occupied-position compiling is carried out, then the router.
In an exemplary embodiment, when the component class corresponding to each component is generated according to the annotation, a corresponding java file is generated according to the annotation, and then a class file is generated according to the java file. For example, generating a RouterServiceInterface.java file and a RouterServiceProxy.java file according to the annotation, and then generating a RouterServiceInterface.class file according to the RouterServiceInterface.java file. And finally, packaging the RouterServiceInterface class file into a target Jar packet, and replacing the initial Jar packet with the target Jar packet.
In the embodiment, when the project is pulled for the first time, the Component Class source file is packaged into the Jar package, so that the problem of wrong compilation can be solved.
It should be noted that the above-mentioned file generation and packaging processes are both implemented in the transformation (Transform) phase of the Gradle construction period.
In an exemplary embodiment, the method further creates a catalog under the engineering catalog, stores the source files of the Component Class under the new catalog, and submits the source files of the Component Class to a remote git repository for merging (Merge) or synchronization (Sync). In this embodiment, the bytecode file generated by the Component Class is not stored, jar is not submitted, and Proxy does not need to submit to the git warehouse, so that synchronization when multiple developers modify the same Component is realized, and user experience is improved.
Step S104: writing the corresponding relation between the interface in the component class and the static agent class into the routing table so as to find the corresponding relation and the routing relation from the routing table.
Step S105: and when a routing request for a target component is received, performing componentized routing according to the corresponding relation and the routing relation in the routing table.
Specifically, the component class includes the interface and the static agent class, and the correspondence between the component class is the correspondence between the interface and the static agent class. After the corresponding relation of the component class is written into the routing table, when routing is needed, the corresponding relation of the interface and the static agent class and the routing relation among the components are searched in the routing table, and the componentized routing can be directly carried out according to the corresponding relation and the routing relation.
Because the component classes in the embodiment of the invention are generated according to the annotations of all the files, and the annotations of all the files comprise AARs, the invention not only supports the component routing under the current Module engineering, but also supports the component routing in the AARs. Because the invention directly generates the corresponding routing table according to the annotation, the componentized routing is realized, goModule does not need to be inherited, and the complete decoupling among the components is realized. The Method of static does not need to be defined in advance in the component, and the static Method is uniformly referred to, so that the development efficiency of component developers is greatly improved, and the development process is simplified.
In an exemplary embodiment, the method further comprises: packaging the Component Class into a Jar package so that each Component dynamically adds the dependent Jar package.
Specifically, a new directory router.gradle is created under the engineering directory by packing the produced Class bytecode into Jar packages, and then Jar package dependencies are added to all modules in the router.gradle directory. Add Jar package dependencies to all modules in the Router. In the router, the JAR is generated according to the computer Class, so as to solve the problem that when JAR generates an addition dependency in a plug-in (Plugin), the Plugin needs to be executed first, that is, synchronization needs to be executed more than once when JAR is not generated.
In an exemplary embodiment, the method further comprises: and when routing is carried out, acquiring the corresponding Component Class instance according to the routing table, and calling the service according to the Component Class instance.
In actual practice, unused classes are not instantiated. And when routing is carried out, acquiring the corresponding Component Class instance according to the routing table, and realizing componentized routing.
In an exemplary embodiment, the method further adds a centralized management process, and registers the routing information of all processes to the centralized management process. When a first process carries out route skipping, the first process searches a corresponding path from the centralized management process so as to determine a second process in which the path exists. And after the path and the second process are found, calling back the path and the second process to the first process so as to jump to a target page. In practical application, a centralized management process is newly added in application, then other processes are started, and management information of all the processes is placed in the centralized management process, which is equivalent to that routing information of all the processes is registered in the centralized management process. When routing jump is carried out, the mapping relation is searched in the centralized management process, for example, a path and the process in which the path exists are searched. And after the path and the process existing in the path are found, the path and the process existing in the path are called back to the process needing to be jumped, so that cross-process component calling is realized. By the method, cross-process component calling can be realized.
In an exemplary embodiment, the method further abstracts the protocol into an interface, realizes the visualization of the entry of the component interface during calling, and improves the experience of the user.
Fig. 5 is a flowchart illustrating exemplary specific steps of the componentized routing method according to the embodiment of the present invention. First, the user adds annotations, including @ Router, @ RouterService, and @ RouterMethod. Then, in the compiling stage, the Processor (Processor) of the JavaPoet traverses all the annotations and parses the annotation @ Router to output a routermap. In the construction stage of the Gradle plug-in, firstly customizing the Gradle plug-in; jar of a specific name is checked/created for placeholder compilation. Create router.gradle, add Jar dependencies of all modules therein; secondly, in build.gradle under the engineering root directory, apply router.gradle; then, in a Transform stage, scanning annotations in all files, including JAR and AAR, generating java and class files of corresponding Interface and Proxy, and writing the corresponding relation of the Interface and the Proxy into a RouterMap; and finally, packaging the produced class file into Jar, wherein the name of the class file is the same as the name of the Jar subjected to space-occupying compilation, so as to replace the Jar package, and thus completing the construction of the Gradle plug-in.
According to the componentized routing method provided by the embodiment of the invention, annotations which are added by a user and correspond to the classes or methods related to the routing are obtained; when a compiling instruction sent by the user is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores routing relations among all components, so that all classes can call methods of other classes; when a Gradle plug-in construction instruction sent by the user is received, scanning annotations of all files in a preset project of the software development kit, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR, and the component classes comprise interfaces and static agent classes corresponding to the interfaces; writing the corresponding relation between the interface and the static agent class in the component class into the routing table so as to find the corresponding relation and the routing relation from the routing table; and when a routing request for a target component is received, performing componentized routing according to the corresponding relation and the routing relation in the routing table, supporting component routing in the AAR, and realizing complete decoupling among the components without inheriting GoModule, wherein a static Method is not required to be defined in the components in advance and is uniformly participated, so that the development efficiency of component developers is greatly improved, the development process is simplified, non-invasive injection and low-invasive component application are realized, and the generation efficiency of the routing table is greatly improved.
Example two
Referring to fig. 6, a schematic diagram of program modules of a componentized routing system according to an embodiment of the present invention is shown. The modular routing system can be applied to electronic equipment. In this embodiment, the componentized routing system may include or be divided into one or more program modules, which are stored in a storage medium and executed by one or more processors, to implement the present invention and implement the componentized routing method described above. The program module referred to in the embodiments of the present invention refers to a series of computer program instruction segments capable of performing specific functions, and is more suitable than the program itself for describing the execution process of the componentized routing system in the storage medium. The following description will specifically describe the functions of the program modules of the present embodiment:
an Annotation acquisition module 201, configured to acquire an Annotation (Annotation) added by a user and corresponding to a Class (Class) or a Method (Method) related to a route, where the Annotation includes: @ Router, @ RouterService, and @ RouterMethod.
Note that the annotation is a form of metadata, and can be added to Java source code, and classes, methods, variables, parameters, packets, and the like in Java can be annotated without direct influence on the annotated code.
In an exemplary embodiment, the user adds corresponding annotations to the route-related classes or methods by using annotations, which are then retrieved by the software development kit. Non-invasive injection can be realized through annotation, and low-invasive component application is realized.
A routing table generating module 202, configured to, when a Compile (build) instruction sent by the user is received, identify the annotation, and generate a corresponding routing table (RouterMap) according to the identified annotation, where the routing table stores routing relationships among the components.
Specifically, when compiling, the annotation is parsed by using a Processor (Processor) of the JavaPoet, and then a corresponding routermap. The JavaPoet is a Java code generation framework and provides Java Application Interface (Application Interface) API generation.A Java source file generates codes correspondingly according to annotations, database modes, protocol formats and the like by using the JavaPoet.
When the class or method related to the routing is detected to be updated, the updating can be effective in a recompilation (Rebuild) mode, a corresponding routing table is automatically generated, module transplantation is supported, flexible plugging and unplugging of the module are realized, and the method has the characteristics of simplicity in use, convenience in maintenance and low invasiveness. The updating comprises the following steps: delete or add or modify operations.
In practical application, during the compiling period, the Processor only generates a RouterMap. It should be noted that Javassist is a class library used for processing Java bytecode. Javasissist provides a number of convenient ways by which bytecode can be generated and then executed by a Java Virtual Machine (JVM). And after the RouterMap.java file is obtained, continuously compiling the RouterMap.java file in the Gradle construction period to generate a RouterMap.class file. The Gradle is a construction tool and strongly supports multi-project construction.
By using the JavaPoet mode, the annotation can be automatically generated into codes, manual code maintenance is avoided, and the generation efficiency of the routing table is improved.
In an exemplary embodiment, the componentized routing system may further include a configuration module configured to, when the supporting plurality of target annotations are pre-configured into the processor before compiling, where the plurality of target annotations include: @ Router, @ RouterService and @ RouterMethod;
in an exemplary embodiment, the routing table generating module 202 may include a determining module and a generating module.
Said determining module for comparing said annotation with said plurality of said target annotations to determine if said annotation belongs to a plurality of said target annotations;
and the generating module is used for generating the routing table according to the @ Router when the annotation belongs to the plurality of target annotations and the annotation is the @ Router.
Specifically, the system-supported annotations are determined by pre-configuring a plurality of annotations into the processor prior to compilation. The added annotations are then compared with preconfigured annotations at compile time to determine whether the development is componentized according to the comparison result. When the annotation belongs to one of the plurality of target annotations, then componentized development is determined, and then a routing table will be generated from the @ Router annotation. And judging the type of the annotation so as to generate a routing table according to the @ Router annotation in the compiling period.
The Component Class generating module 203 is configured to scan annotations of all files in a preset project of the software development kit when receiving a Gradle plug-in construction instruction sent by the user, and generate a Component Class (Component Class) corresponding to each Component according to the annotations, where the annotations of all files include AAR, and the Component Class includes an interface and a static agent Class corresponding to the interface.
Note that the annotations of all files herein include Java Archive (JAR) and Android Archive (AAR). The JAR is a software package file format that is typically used to aggregate large numbers of Java class files, associated metadata and resource (text, pictures, etc.) files into one file in order to develop Java platform applications or libraries. AAR is a binary archive file of Android library items, containing all resources, such as: class and res resource files, etc.
Compared with the prior art that a reflection mode is adopted, the embodiment of the invention adopts a static agent mode to realize the binding of an Interface (Interface) and the realization of the Interface, greatly improves the processing performance of a computer and accelerates the processing speed of the computer.
In an exemplary embodiment, the component class is identified by a corresponding class name, and the static proxy class is used to implement the interface, that is, the proxy class is an implementation or method of the interface. Since the component class includes an interface and a static Proxy class (Proxy), the component class generation module 203 is specifically configured to: acquiring the class name of the component class; generating the interface corresponding to each component by the class name according to the generation rule of I + class name + RouterService; and generating the static Proxy class corresponding to the interface by the class name according to a generation rule of the class name + Proxy.
That is, the generation rule of the interface is: class name (ClassName) + routervice; the generation rule of the static agent class corresponding to the interface is as follows: className + Proxy.
Illustratively, fig. 4 shows a schematic diagram of an exemplary interface and static agent generation method. Java, wherein the log is a functional component provided externally, the Interface generated according to the log is ILoginRouterService, and the generated ILoginRouterService is realized, that is, the proxy class of the log is LoginProxy.
In an exemplary embodiment, the generating a component class corresponding to each component according to the annotation includes: and generating the component class according to the @ RouterService and the @ RouterMethod.
In practical application, during the period of constructing the Gradle, the Gradle plug-in is required to be customized, then an initial Jar package with a preset name is checked or created, occupied-position compiling is carried out, then the router.
In an exemplary embodiment, when the component class corresponding to each component is generated according to the annotation, a corresponding java file is generated according to the annotation, and then a class file is generated according to the java file. For example, a routerserviceinterface.java file and a routerserviceproxy.java file are generated according to the annotation, and then a routerserviceinterface.class file is generated according to the routerserviceinterface.java file. And finally, packaging the RouterServiceInterface class file into a target Jar packet, and replacing the initial Jar packet with the target Jar packet.
According to the method and the system, when the project is pulled for the first time, the Component Class source file is packaged into a Jar package, and the problem of wrong compilation can be solved.
It should be noted that the above-mentioned file generation and packaging processes are both implemented in the transformation (Transform) phase of the Gradle construction period.
In an exemplary embodiment, the method further creates a catalog under the engineering catalog, stores the source files of the Component Class under the new catalog, and submits the source files of the Component Class to a remote git repository for merging (Merge) or synchronization (Sync). In this embodiment, the bytecode file generated by the Component Class is not stored, jar is not submitted, and Proxy does not need to submit to the git warehouse, so that synchronization of multiple developers when modifying the same Component is realized, and user experience is improved.
A writing module 204, configured to write the correspondence between the interface in the component class and the static agent class into the routing table, so as to find the correspondence and the routing relationship from the routing table.
The routing module 205 is configured to perform componentized routing according to the corresponding relationship and the routing relationship in the routing table when receiving a routing request for a target component.
Specifically, the component class includes the interface and the static agent class, and the correspondence between the component class is the correspondence between the interface and the static agent class. After the corresponding relation of the component class is written into the routing table, when routing is needed, the corresponding relation of the interface and the static agent class and the routing relation among the components are searched in the routing table, and the componentized routing can be directly carried out according to the corresponding relation and the routing relation.
Because the component classes in the embodiment of the invention are generated according to the annotations of all the files, and the annotations of all the files comprise AARs, the invention not only supports the component routing under the current Module engineering, but also supports the component routing in the AARs. Because the invention directly generates the corresponding routing table according to the annotation, the componentized routing is realized, goModule does not need to be inherited, and the complete decoupling among the components is realized. The invention does not need to define the Method of static in advance in the component and uniformly participate in the component, thereby greatly improving the development efficiency of component developers and simplifying the development process.
In an exemplary embodiment, the system further comprises a packaging module for packaging the Component Class into a Jar package, so that each Component dynamically adds the dependent Jar package.
Specifically, a new directory router.gradle is created under the engineering directory by packing the produced Class bytecode into Jar packages, and then Jar package dependencies are added to all modules in the router.gradle directory. Add Jar package dependencies to all modules in the Router. In the router, the JAR is generated according to the computer Class, so as to solve the problem that when JAR generates an addition dependency in a plug-in (Plugin), the Plugin needs to be executed first, that is, synchronization needs to be executed more than once when JAR is not generated.
In an exemplary embodiment, the system further includes an obtaining module, configured to obtain, when performing routing, a corresponding Component Class instance according to the routing table, and perform service invocation according to the Component Class instance.
In actual practice, unused classes are not instantiated. And when routing is carried out, acquiring the corresponding Component Class instance according to the routing table, and realizing componentized routing.
In an exemplary embodiment, a centralized management process is further added, and the routing information of all the processes is registered to the centralized management process. When a first process carries out route skipping, the first process searches a corresponding path from the centralized management process so as to determine a second process in which the path exists. And after the path and the second process are found, calling back the path and the second process to the first process so as to jump to a target page. In practical application, a centralized management process is newly added in application, then other processes are started, and management information of all the processes is placed in the centralized management process, which is equivalent to that routing information of all the processes is registered in the centralized management process. When routing jump is carried out, the mapping relation is searched in the centralized management process, for example, a path and the process in which the path exists are searched. And after the path and the process existing in the path are found, the path and the process existing in the path are called back to the process needing to be jumped, so that cross-process component calling is realized. Cross-process component invocation can be achieved through the embodiment.
In an exemplary embodiment, the system further abstracts the protocol into an interface, so that the participation visualization during calling of the component interface is realized, and the experience degree of a user is improved.
The componentized routing system provided by the embodiment of the invention obtains the comments which are added by the user and correspond to the classes or methods related to the routing; when a compiling instruction sent by the user is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores routing relations among all components, so that all classes can call methods of other classes; when receiving a Gradle plug-in constructing instruction sent by the user, scanning annotations of all files in a preset project of the software development kit, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AARs (architecture analysis algorithms), and the component classes comprise interfaces and static agent classes corresponding to the interfaces; writing the corresponding relation between the interface and the static proxy class in the component class into the routing table so as to find the corresponding relation and the routing relation from the routing table; when a routing request for a target component is received, componentized routing is carried out according to the corresponding relation and the routing relation in the routing table, component routing in AAR can be supported, goModule does not need to be inherited, complete decoupling among components is achieved, static Method does not need to be defined in the components in advance, and the Method is involved in the components in a unified mode, so that the development efficiency of component developers is greatly improved, the development process is simplified, non-invasive injection and low-invasive component application are achieved, and the generation efficiency of the routing table is greatly improved.
EXAMPLE III
Referring to fig. 7, a hardware architecture diagram of a computer device according to a third embodiment of the present invention is shown. The computer device 2 includes, but is not limited to, a memory 21, a processor 22, and a network interface 23 communicatively coupled to each other via a system bus, and FIG. 7 illustrates only the computer device 2 having components 21-23, but it is to be understood that not all of the illustrated components are required and that more or fewer components may alternatively be implemented. In the present embodiment, the computer device 2 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a preset or stored instruction. For example, a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server, or a rack server (including an independent server or a server cluster composed of a plurality of servers) that can execute programs, and the like.
The memory 21 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 21 may be an internal storage unit of the computer device 2, such as a hard disk or a memory of the computer device 2. In other embodiments, the memory may also be an external storage device of the computer device 2, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the computer device 2. Of course, the memory 21 may also comprise both an internal storage unit of the computer device 2 and an external storage device thereof. In this embodiment, the memory 21 is generally used for storing an operating system installed on the computer device 2 and various types of application software, such as program codes of the componentized routing system 20. Further, the memory 21 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 22 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 22 is typically used to control the overall operation of the computer device 2. In this embodiment, the processor 22 is configured to execute the program codes stored in the memory 21 or process data, for example, execute the componentized routing system 20.
The network interface 23 may comprise a wireless network interface or a wired network interface, and the network interface 23 is generally used for establishing communication connection between the computer device 2 and other electronic devices. For example, the network interface 23 is used to connect the computer device 2 to an external terminal through a network, establish a data transmission channel and a communication connection between the computer device 2 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, bluetooth (Bluetooth), wi-Fi, and the like.
It is noted that fig. 7 only shows the computer device 2 with components 21-23, but it is to be understood that not all shown components are required to be implemented, and that more or less components may be implemented instead.
Example four
The present embodiments also provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the modular routing method of the embodiments.
In this embodiment, the computer-readable storage medium includes a Flash memory, a hard disk, a multimedia Card, a Card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application store, etc., and in other embodiments, the computer-readable storage medium may also be an external storage device of the computer apparatus, such as a plug-in hard disk equipped on the computer apparatus, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card, etc. Of course, the computer-readable storage medium may also include both internal and external storage devices of the computer device. In this embodiment, the computer-readable storage medium is generally used for storing an operating system and various types of application software installed in the computer device, for example, the program code of the componentized routing method in the embodiment, and the like. Further, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (9)

1. A componentized routing method applied to a software development kit, the method comprising:
obtaining annotations added by a user and corresponding to a class or a method related to a route, wherein the annotations comprise: @ Router, @ RouterService and @ RouterMethod;
when a compiling instruction sent by the user is received, the annotation is identified, a corresponding routing table is generated according to the identified annotation, and the routing table stores routing relations among all the components;
when a Gradle plug-in construction instruction sent by the user is received, scanning annotations of all files in a preset project of the software development kit, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR, and the component classes comprise interfaces and static agent classes corresponding to the interfaces;
writing the corresponding relation between the interface and the static agent class in the component class into the routing table so as to find the corresponding relation and the routing relation from the routing table; and
when a routing request for a target component is received, performing componentized routing according to the corresponding relation and the routing relation in the routing table;
generating a component class corresponding to each component according to the annotation includes:
and generating the component class according to the @ RouterService and the @ RouterMethod.
2. The modular routing method of claim 1, wherein the method further comprises:
before receiving a compiling instruction sent by the user, pre-configuring a plurality of supported target annotations into a processor, wherein the plurality of target annotations comprise: @ Router, @ RouterService, and @ RouterMethod;
the identifying the annotation and generating a corresponding routing table according to the identified annotation includes:
comparing the annotation to the plurality of the target annotations to determine whether the annotation belongs to a plurality of the target annotations; and
and when the annotation belongs to a plurality of target annotations and the annotation is @ Router, generating the routing table according to the @ Router.
3. The componentized routing method of claim 1, wherein the component classes are identified by corresponding class names, the static proxy class is used to implement the interface, and the generating the component class corresponding to each component from the annotations comprises:
acquiring the class name of the component class;
generating the interface corresponding to each component by the class name according to the generation rule of I + class name + RouterService;
and generating the static Proxy class corresponding to the interface by the class name according to a generation rule of the class name + Proxy.
4. The modular routing method of claim 1, wherein the method further comprises:
and packaging the component classes into Jar packages so that each component dynamically adds the dependent Jar packages.
5. The modular routing method of claim 1, wherein the method further comprises:
and when routing is carried out, acquiring the corresponding component class instance according to the routing table, and calling the service according to the component class instance.
6. The modular routing method of claim 1, wherein the method further comprises:
creating a centralized management process;
acquiring routing information of all processes, and registering the routing information of all processes to the centralized management process;
when a first process in all processes carries out route skipping, the first process searches a corresponding path from the centralized management process to determine that the path exists in a second process;
and after the path and the second process are found, the path and the second process are called back to the first process, and then the target page is jumped according to the calling back result.
7. A componentized routing system applied to a software development kit, comprising:
the annotation acquisition module is used for acquiring annotations added by a user and corresponding to the class or method related to the route, wherein the annotations include: @ Router, @ RouterService, and @ RouterMethod;
a routing table generation module, configured to identify the annotation when receiving a compiling instruction sent by the user, and generate a corresponding routing table according to the identified annotation, where the routing table stores routing relationships among the components;
the component class generation module is used for scanning annotations of all files in a preset project of the software development kit when a Gradle plug-in construction instruction sent by the user is received, and generating a component class corresponding to each component according to the annotations, wherein the annotations of all files comprise AAR (architecture analysis and reporting), and the component class comprises an interface and a static agent class corresponding to the interface;
a writing module, configured to write the correspondence between the interface in the component class and the static proxy class into the routing table, so as to find the correspondence between the component class and the routing relation from the routing table; and
the routing module is used for performing componentized routing according to the corresponding relation and the routing relation in the routing table when receiving a routing request for a target component;
generating a component class corresponding to each component according to the annotation includes: and generating the component class according to the @ RouterService and the @ RouterMethod.
8. A computer arrangement, characterized in that the computer arrangement comprises a memory, a processor and a computer program stored on the memory and executable on the processor, which computer program, when executed by the processor, carries out the steps of the modular routing method according to any one of claims 1-6.
9. A computer-readable storage medium, having stored therein a computer program executable by at least one processor to cause the at least one processor to perform the steps of the modular routing method according to any of claims 1-6.
CN202011550082.9A 2020-12-24 2020-12-24 Componentized routing method and system Active CN112769706B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011550082.9A CN112769706B (en) 2020-12-24 2020-12-24 Componentized routing method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011550082.9A CN112769706B (en) 2020-12-24 2020-12-24 Componentized routing method and system

Publications (2)

Publication Number Publication Date
CN112769706A CN112769706A (en) 2021-05-07
CN112769706B true CN112769706B (en) 2023-03-24

Family

ID=75695550

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011550082.9A Active CN112769706B (en) 2020-12-24 2020-12-24 Componentized routing method and system

Country Status (1)

Country Link
CN (1) CN112769706B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112925562A (en) * 2021-02-19 2021-06-08 京东方科技集团股份有限公司 Application generation method and device based on android system and storage medium
CN113922999A (en) * 2021-09-29 2022-01-11 上加下信息技术成都有限公司 Authority management configuration method and system based on routing management and electronic equipment
CN114168111B (en) * 2021-12-07 2024-04-05 北京五八信息技术有限公司 Method, device, product and storage medium for realizing componentized route

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6799320B1 (en) * 1998-12-16 2004-09-28 Microsoft Corporation Providing binding options for component interfaces
CN105718289A (en) * 2016-01-21 2016-06-29 腾讯科技(深圳)有限公司 Component relationship establishing method and equipment
CN108563432A (en) * 2018-03-14 2018-09-21 广东能龙教育股份有限公司 Android application program componentization rapid development method through route configuration
CN110007925A (en) * 2019-04-01 2019-07-12 睿驰达新能源汽车科技(北京)有限公司 A kind of method and device promoting application program runnability
CN111638923A (en) * 2020-06-04 2020-09-08 北京思特奇信息技术股份有限公司 Method and device for data routing based on Java annotation

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6799320B1 (en) * 1998-12-16 2004-09-28 Microsoft Corporation Providing binding options for component interfaces
CN105718289A (en) * 2016-01-21 2016-06-29 腾讯科技(深圳)有限公司 Component relationship establishing method and equipment
CN108563432A (en) * 2018-03-14 2018-09-21 广东能龙教育股份有限公司 Android application program componentization rapid development method through route configuration
CN110007925A (en) * 2019-04-01 2019-07-12 睿驰达新能源汽车科技(北京)有限公司 A kind of method and device promoting application program runnability
CN111638923A (en) * 2020-06-04 2020-09-08 北京思特奇信息技术股份有限公司 Method and device for data routing based on Java annotation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Android软件开发组件化研究;殷涛,催佳冬;《计算机应用与软件》;20190930;第36卷(第9期);全文 *

Also Published As

Publication number Publication date
CN112769706A (en) 2021-05-07

Similar Documents

Publication Publication Date Title
CN112769706B (en) Componentized routing method and system
CN109032631B (en) Application program patch package obtaining method and device, computer equipment and storage medium
CN111399840B (en) Module development method and device
CN111026439B (en) Application program compatibility method, device, equipment and computer storage medium
CN110688096B (en) Method and device for constructing application program containing plug-in, medium and electronic equipment
CN111740948B (en) Data packet issuing method, dynamic updating method, device, equipment and medium
CN110865889A (en) Method and apparatus for transferring events between components
CN113805882A (en) Method and device for developing application program, electronic equipment and storage medium
CN110716786B (en) Page display method, system and storage medium
CN113138768B (en) Application package generation method and device, electronic equipment and readable storage medium
CN105447040B (en) Binary file management and updating method, device and system
CN111352631A (en) Interface compatibility detection method and device
CN116578282A (en) Code generation method, device, electronic equipment and medium
CN110955415A (en) Method for adapting projection multi-platform service
CN113495723B (en) Method, device and storage medium for calling functional component
CN115729590A (en) Service deployment method, device, equipment and computer readable storage medium
CN111488286B (en) Method and device for independently developing Android modules
CN114860204A (en) Program processing method, program operating device, terminal, smart card and storage medium
CN113032004A (en) Method, apparatus and program product for managing development jobs in a development environment
US20120150898A1 (en) Dynamic Collection Of System Support Files In A Data Processing Environment
US11954007B2 (en) Tracking usage of common libraries by means of digitally signed digests thereof
CN114840217A (en) Compiling method, device, equipment and readable storage medium
CN112783834B (en) Service resource online restocking method and device and electronic equipment
CN115268897A (en) Component library document access method, device, equipment and medium
CN115934123A (en) Client logic updating method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant