CN117032652A - Class instance state generation and recovery method based on reflection and annotation - Google Patents

Class instance state generation and recovery method based on reflection and annotation Download PDF

Info

Publication number
CN117032652A
CN117032652A CN202311018561.XA CN202311018561A CN117032652A CN 117032652 A CN117032652 A CN 117032652A CN 202311018561 A CN202311018561 A CN 202311018561A CN 117032652 A CN117032652 A CN 117032652A
Authority
CN
China
Prior art keywords
state
annotation
class
instance
interface
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.)
Pending
Application number
CN202311018561.XA
Other languages
Chinese (zh)
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.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
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 Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CN202311018561.XA priority Critical patent/CN117032652A/en
Publication of CN117032652A publication Critical patent/CN117032652A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages

Abstract

The invention discloses a class instance state generation and recovery method based on reflection and annotation, which is characterized in that by defining state annotation, a state coverage domain, a state object interface and a state domain object, annotation and reflection technologies in programming language are adopted, and in the process of program operation, a state generation method and a state recovery method aiming at class instances running in a memory are provided for a user, and are packaged into the state object interface, so that the state domain object bound with the class instances is finally formed; the invention ensures that a user can acquire and recover the real-time state only by one-time initialization in the program operation life cycle; the performance of the method in the class with sparse state variables is far superior to that of the serialization mode, and meanwhile, the custom of the state processing logic design can be realized through inheritance annotation state interfaces and rewriting state generation and recovery interfaces, so that the design process of the class state processing logic is greatly simplified.

Description

Class instance state generation and recovery method based on reflection and annotation
Technical Field
The invention relates to the field of computers, in particular to a class instance state generation and recovery method based on reflection and annotation.
Background
In the running process of the object-oriented program, the member attribute of the object will have a status meaning under a specific business scene, for example, the average score attribute in the object of "class score sheet", and in the business scene of "calculating class average score", when the score sheet (for example, excel sheet) is read, the average score is calculated in the manner of "average score= (student serial number average score+score sheet [ student serial number ])/(student serial number+1)". In this traffic scenario, the average score is the state. When the score data is invisible to the subject, the subject can only receive one score data, and a counter is maintained to record the number of students, so that the number of students can be in a state.
In the above example, average score and student population are related to the business scenario "calculate average score". In a computer, the business scenario is defined as a task, and the object instance "class score" is a node of the task, and variables in the node related to the task result are states.
The state is an important concept in the scenes of a distributed flow batch data processing system, multithreading asynchronization, cyclic IO tasks and the like, the business logic often needs to update and inquire the state according to events in the data flow, so that complex event-driven application and real-time analysis are realized, the state can be used for ensuring the correctness and consistency of data flow processing through controlling all states in the tasks, for example, when faults or rebalancing are encountered, the state can be restored and migrated through saving points and check points, and therefore, the accurate primary semantics are realized. Accurate one-time semantics ensure that the results of the data stream processing do not error or repeat due to system uncertainty. Meanwhile, the state can provide various APIs for the application program, such as obtaining the current snapshot of the workflow and loading the checkpoint file, so that offline analysis and debugging are realized.
The generation of the state is not separated from the analysis of the instance object, and the current main stream practice mainly comprises two types:
1. the class realizes the serialization interface, and the access of the state adopts the mode of serialization and anti-serialization:
this is the simplest way but only for nodes of simpler construction. The main difficulty is in implementing a serialized interface. If more complex classes exist in the classes, a rather complex serialization method is required. In the case of complex class relationships, modifying the interface of one of the classes requires modifying the update serialization interface at the same time. At the same time, in most cases, only individual member attributes of a class are used as states, the serialization traverses all member attributes, and if the serialization of the member attributes is not filtered, the formed state file has very much useless information.
The method is easy to implement, and serialization tools such as Jackson, kryo, fastjson and the like can be used as tools for state generation. However, in the process of state recovery, only a complete example is obtained after the reverse serialization, and in the implementation of the fault recovery mechanism, the state in the example obtained after the reverse serialization still needs to be explicitly applied to the node in the task. Meanwhile, the later maintenance is very complicated, and the coupling performance is strong. And meanwhile, the serialization performance is poor and the time is long.
2. The state class interface is realized independently, and the class realizes and maintains the access interface of the state of the class:
the class realizes a state generation interface and a state recovery interface, wherein the state generation interface is responsible for packaging class member attributes into a set, the set can be a data structure such as a hash table, an array and the like, the multi-state is a basic data type, the multi-state is directly added into the set, and if the state is a complex class, the state interface provided by the class can be called to acquire the state; the state recovery interface takes the set generated by the state acquisition interface as an entry, and recovers the state of the instance according to the set.
Compared with a serialization mode, the method is more efficient and flexible, has better performance, is very complicated and complex in practical use, a class designer needs to set a corresponding state generation and recovery interface for each class, and member attributes are packaged separately to form a set, and the set of states is manually processed and applied to class members. Likewise, operations on the state sets in both interfaces need to be synchronized during maintenance.
Disclosure of Invention
The invention aims at overcoming the defects of the prior art and providing a class instance state generation and recovery method based on reflection and annotation.
The aim of the invention is realized by the following technical scheme: a method for generating and restoring class instance states based on reflection and annotation, the method comprising the steps of:
s1, adding an annotation state interface into a class instance, and providing a state generation and recovery method based on state annotation;
s2, defining a state object interface in the class instance, and providing a method for anonymously and quickly accessing member variables in the class instance under the condition of being unknown to the class; creating a state object interface total set;
s3, creating a corresponding state domain object for a class instance, and binding the state domain object to the class object instance by calling an initialization method of the state domain object, wherein the method specifically comprises the following steps:
s3.1, inputting parameters, and obtaining reflection objects of all member variables of the class object instance through reflection;
s3.2, traversing the reflection object of the member variable, judging an annotation domain, packaging the reflection object into a state object interface according to the type of the state annotation, and storing the state object interface into a state object interface total set;
if the traversal is not finished, continuing the traversal, and if the traversal is finished, executing the next step;
s4, traversing a state object interface total set maintained by the state domain object; executing a state generation method in the state object interface total set to perform state generation, collecting variable names of member variables as keys, and packaging the state object interfaces as values into key value pairs, and returning the key value pairs to a user, wherein the key value pairs are used as input parameters of a state recovery method;
the state recovery method of the state domain object obtains the corresponding state from the entry according to the member variable name, and the state is used as the entry to call the state recovery method of the state object interface, so as to complete state recovery.
Further, annotating the state annotations implemented by the state interface includes: the state value annotation, the state class annotation and the state method annotation are used for marking the appointed member variable in the class, wherein the member variable appointed by the state value annotation is of a basic data type, the member variable of the state class annotation mark is of a class, and the member variable of the state method mark needs to realize an annotation state interface.
Further, the state object interface includes:
single instance state object interface: corresponding to the state value annotation, encapsulating the reflection object of the member variable marked by the state value annotation in the class instance into an interface, wherein the single instance state object maintains the reflection object corresponding to the class of the member variable;
multiple instance state object interface: corresponding to the state class annotation, packaging a state object set of the member variable marked by the state class annotation in the class instance as an interface, and storing the state object set corresponding to the member variable marked by the state class annotation in a key value mode by maintaining multiple cases of state objects;
method state object interface: corresponding to the state method annotation, the annotation state interfaces of the member variables marked by the state method annotation in the class instance are packaged into interfaces, and the method state object interface maintains two interfaces, including a state generation method and a state recovery method provided by the annotation state interfaces.
Further, when a single-instance state object interface is created, only the variable names of the reflecting object and the member variable are needed; when creating a multi-instance state object interface, all state object interfaces in the instance and variable names of member variables are needed; when creating the method state object interface, only the reflection object of the member variable is needed.
Further, the state generating method and the state recovering method of the three-type state object interface are as follows:
the state generation method of the single-instance state object interface is based on a call method of a reflection object, the reflected object corresponding to the state object is used as a parameter of the call method, the call method is executed to obtain the value of the member variable, the parameter name of the member variable is used as a key, and a state key value pair is formed to return; firstly, converting the type of a reflecting object into a modifiable type, and calling a call method through a Setter to inject a state value into a member variable corresponding to the reflecting object, wherein the state value is consistent with a state value structure returned by a state generating method;
the state generation method of the multi-instance state object interface specifically comprises the following steps: traversing the state generation method of all the state object interfaces in the maintained state object interface set, and returning the collected content in the form of state key value pairs; the entering of the state recovery method is that the state recovery method of the state object interface in the maintained state object interface set is traversed and executed, and meanwhile, the value is taken from the entering according to the parameter name in the state object interface to be used as the entering of the state recovery method of the current object instance;
the state generating method of the method state object interface directly executes the state generating method of the object instance and returns the result state key value pair; the entry of the state recovery method is the result of the state generation method, the state recovery method of the object instance is directly executed, and the value is taken from the entry according to the parameter name of the object instance, and the value is taken as the entry of the state recovery method of the object instance.
Further, the creating a state object interface total set specifically includes: creating a HashMap which takes a character string and a state object interface as key value pairs as a set of state object interfaces.
Further, the annotation domain judgment specifically includes:
if the annotation domain of the current reflection object has state value annotation, packaging the reflection object into a single-instance state object interface, and storing the single-instance state object interface into a total set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state class annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, taking the value as an entry parameter, executing again from S3.1, and recursively calling an initialization method; after the call is completed, the obtained state object interface set is packaged into a plurality of cases of state object interfaces, and the plurality of cases of state object interfaces are stored into the total set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state method annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, packaging the value as a method state object interface, and storing the method state object interface into a total set by taking the variable name of the current member variable as a key.
The invention has the beneficial effects that:
the invention allows the user to quickly acquire the state of the corresponding class instance by only executing the state generation method of the state domain object for one class instance which has completed binding the state domain object in the program operation life cycle. The state domain object can be subjected to real-time state acquisition and state recovery in the life cycle of the whole program by only initializing once, and in the class with sparse state variables, the performance of the solution is far better than that of the serialization mode, and is equivalent to that of the state interface for independently realizing the class; meanwhile, the solution can realize the self-definition of the state processing logic design by inheriting the annotation state interface and rewriting the state generation and restoration interface, and provide the annotation which can cover most of scenes, thereby greatly simplifying the design process of the class state processing logic. The method is beneficial to users to better realize key services such as interrupt self-recovery, breakpoint continuous transmission, online/offline debugging, snapshot and the like in the process of programming.
Drawings
FIG. 1 is a schematic diagram of a state coverage provided by an embodiment of the present invention;
FIG. 2 is a schematic diagram of a state object interface structure according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a state object interface call operation logic provided in an embodiment of the present invention;
FIG. 4 is a flowchart of a state domain object initialization process according to an embodiment of the present invention;
FIG. 5 is a flow chart of the application of "data deduplication" in accordance with an embodiment of the present invention;
fig. 6 is a code application diagram of applying a "data deduplication job" according to an embodiment of the present invention.
Detailed Description
The following describes the embodiments of the present invention in further detail with reference to the drawings.
Aiming at the defects of the prior art, the invention provides a class instance state generating and recovering method based on reflection and annotation;
the state generation method is a method capable of extracting and packaging values of all member variables conforming to state definition in a certain class instance in a program into a data structure with a standard structure in the life cycle of an object-oriented program;
the state recovery method is a method capable of modifying the value of a member variable conforming to the state definition in a class instance into a corresponding value in a data structure by using a data structure of a structural specification in the life cycle of an object-oriented program;
the specific steps of the embodiment of the invention are as follows:
s1, adding an annotation state interface into a class instance, and providing a state generation and recovery method based on state annotation;
defining a state annotation: the embodiment of the invention provides an annotation state interface which provides an annotation-based state generation method and a state recovery method.
The embodiments of the present invention provide three types of state annotations: state value notes, state class notes, state method notes.
State value annotation: the annotation is used to mark a specified member variable in the class, which is typically a basic data type, which is directly valued when a state value is obtained and which is directly assigned when the state value is restored.
State class annotation: the annotation is used for marking the appointed member variable in the class, but the member variable is a class, and the variable also has a state, so the variable cannot be directly valued, the member variable value marked by the state value annotation is obtained, and the member variable marked by the state value annotation is recovered when the state is recovered.
State method notes: the annotation is used for marking the appointed member variable in the class, but the member variable needs to realize an annotation state interface, and when the state is generated, the state generating method is called to generate the state, and when the state is recovered, the state recovering method is called to recover the state.
In particular, the annotation is only validated when the class implements the annotation state interface, and the default state generation and recovery method provided by the annotation state interface can be rewritten, so that the state generation can be implemented to realize logic customization.
Defining a state coverage field: the annotation state interface has a state override field, which refers to all states that the interface can access in the class, including member variables, member variables of member variables, override fields of the annotation state interface of member variables, and so on. When a class implements the annotation state interface, it has a state override field whose scope is determined by the set of variables that are ultimately overridden by the three classes of annotations.
The state coverage is a logical concept that is used to refer to the collection of states that a class ultimately generates, and when the state coverage is larger, the larger the state objects that are actually generated for an instance of that class. When the member structure of a class is very complex, its state coverage field will also span the state coverage fields of multiple classes, producing state objects that are also more complex in structure.
As shown in FIG. 1, class A has class A member variable 1, class A member variable 2 and class A member variable 3, which are all of a basic data type, and variable 1 and variable 2 are annotated by a state value, class A member variable B is of a class B type and is annotated by a state class, class A member variable C is of a class C type and is annotated by a state method. The class A realizes an annotation state interface, the interface is provided with a state coverage field, the scope is a coverage field set of three classes of annotations, the coverage field of a state value annotation mark is a class A member variable 1 and a variable 2, the coverage field of the state class annotation mark is a class B member variable 1, a variable 2 and a variable 3 in a class A member variable B, the coverage field of a state method annotation mark is a coverage field of a method realized by the annotation state interface of a class A member variable C, the coverage field of the annotation state interface of the class C is also determined according to the set formed by the coverage fields of the three classes of annotations, when the class C realizes a custom state method and rewrites the annotation state interface, the state coverage field of the class C comprises the variable related to the custom state method.
S2, defining a state object interface in the class instance, and providing a method for anonymously and quickly accessing member variables in the class instance under the condition of being unknown to the class; creating a state object interface total set;
defining a state object interface: at this time, the state generation and restoration of class a transitions to operation of the state overlay domain of the annotation state interface. The state override domain logically corresponds to all member variables that the class instance implementing the annotation state interface ultimately has. Thus the operation on the state override domain is actually an operation on a class member variable.
The annotation state interface provides a basic state generation and restoration method that operates on class member variables, but a specific class is not visible to the annotation state interface, while the annotation state interface will be implemented on a wide variety of custom classes, so the default method provided by the interface cannot specify specific variables in the class instance state overlay domain in a static manner.
Based on the above problems, a concept of a state object interface is presented for providing a series of methods for anonymous quick access to member variables in an instance of a class, without knowledge of the class. The state object interface has a plurality of realization classes, all of which are based on a reflection method, and realize the value and assignment of members of class examples. Three classes of notes respectively:
single instance state object interface: corresponding to the state value annotation, the reflective object of the member variable marked by the state value annotation in the class instance is packaged into an interface, and the reflective object corresponding to the class of the member variable is maintained by the single instance state object, and in general, one class instance has a plurality of single instance state object interfaces. When the single-instance state interface is created, only the variable names of the reflecting objects and the member variables are needed.
Multiple instance state object interface: corresponding to the state class annotation, a state object set of the member variables marked by the state class annotation in the class instance is packaged as an interface, a plurality of state objects maintain a set of the state object interfaces of the member variables marked by the state class annotation, the set is stored in a key value mode, and three types of state object interfaces can be arranged in the set. When creating the multi-instance state object interface, all state object interfaces and variable names of member variables in the class instance are needed.
Method state object interface: corresponding to the state method annotation, the annotation state interfaces of the member variables marked by the state method annotation in the class instance are packaged into interfaces, and the method state object interface maintains two interfaces (a state generation method and a state recovery method provided by the annotation state interfaces) on the premise that the class corresponding to the member variables needs to realize the annotation state interfaces. When creating the method state object interface, only the reflection object of the member variable is needed.
The state object interface also maintains the parameter names and instances of the corresponding member variables, and the structures of the three types of state object interfaces are shown in fig. 2:
for a class, it may be annotated by multiple states, so it corresponds to a set of state object interfaces, a single instance state interface corresponds to a member variable marked by a state value annotation in a class instance, a multiple instance state interface corresponds to a member variable marked by a state class annotation in a class instance, and a method state object interface corresponds to a member variable marked by a state method annotation in a class instance. Each set in the above diagram represents a state coverage field for a class instance.
The state object interface provides a state generation method and a state restoration method, which are default call methods annotating the state interface.
The state generating method and the state recovering method of the three-type state object interface are as follows:
single instance state object interface: the state generation method is based on a call method of a reflection object, the reflected object corresponding to the state object is used as a parameter of the call method, the call method is executed to acquire the value of the member variable, the parameter name of the member variable is used as a key, and a state key value pair is formed and returned. The state recovery method firstly converts the type of the reflecting object into a modifiable type, and the call method is called by the Setter to inject the state value into the member variable corresponding to the reflecting object. The state value is consistent with the state value structure returned by the state generating method.
Multiple instance state object interface: the multiple state object interfaces maintain a set of state object interfaces, so that the state generation method adopts a state generation method for traversing all the state object interfaces in the set, and the collected content is returned in the form of state key value pairs. The entry of the state recovery method is that the state recovery method of the state interfaces in the set is traversed and executed, and meanwhile, values are taken from the entry according to the parameter names appointed in the state interfaces to serve as the entry of the state recovery method of the current object instance.
The parameter names specified here are: in the set of the state object interfaces, the parameter name corresponding to the state recovery method of one of the state object interfaces is added to the state recovery method of the state object interface of a plurality of cases, and the value is taken from the added parameter of the state recovery method according to the parameter name, and the value is the state recovery method and the added parameter of one of the state object interfaces in the set. (in actual implementation, only the parameter entering is needed to be traversed, because the parameter entering is a HashMap, the key is a parameter name, and the value is the state object interface and the parameter entering.)
Method state object interface: the method state object interface maintains the state generation method and the state recovery method of the annotation state interface of the object instance, and the annotation state interface is required to be realized. Therefore, the state generation method directly executes the state generation method of the object instance, and returns the result state key value pair. The entry of the state recovery method is the result of the state generation method, the state recovery method of the object instance is directly executed, and the value is taken from the entry according to the parameter name of the object instance, and the value is taken as the entry of the state recovery method of the object instance.
The call operation logic diagram of the three types of interfaces is shown in the following figure 3.
S3, creating a corresponding state domain object for a class instance, and binding the state domain object to the class object instance by calling an initialization method of the state domain object, wherein the method specifically comprises the following steps:
defining a state domain object: the state domain object is a further encapsulation of the state object interface. The state domain object is responsible for managing the state coverage domain of a class instance and provides initialization, state generation and state recovery methods. The state domain object maintains a set of state object interfaces at the top level in the state overlay domain of the class instance.
A corresponding state domain object is created for a class state instance, and firstly, a HashMap with a character string and a state object interface as key value pairs is created as a set of state object interfaces. The state domain object is bound to a class object instance by invoking an initialization method for the state domain object.
The initialization process of the state domain object is shown in fig. 4, and the specific steps are as follows:
and (3) inputting parameters: class object instances;
obtaining the reflection objects of all member variables of the class object instance through reflection;
traversing the reflection object of the member variable, and judging the annotation domain;
if the annotation domain of the current reflection object has state value annotation, packaging the reflection object into a single-instance state object interface, and storing the single-instance state object interface into a set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state class annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, taking the value as an entry parameter, executing again from 1, and recursively calling an initialization method. After the call is completed, the obtained state object interface set is packaged into a plurality of cases of state object interfaces, and the plurality of cases of state object interfaces are stored into the set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state method annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, packaging the value as a method state object interface, and storing the method state object interface into a set by taking the variable name of the current member variable as a key;
finishing the processing of the reflection object of the current member variable, returning to continuous traversal if the traversal is not finished, and finishing the traversal of the member variable and initializing the state domain object if the traversal is finished;
s4, after the initialization of the state domain object is completed, the maintained state object interface set of the state domain object becomes a state coverage domain of the object instance logically. Traversing the state object interface set and executing the state generation method to generate a state, collecting and packaging the state as a key value pair, and returning the key value pair to a user, wherein the key value pair is also used as a reference of a state recovery method; the state recovery method of the state domain object is to traverse the state object interface set to obtain keys (variable names of member variables) and values (state object interfaces), obtain corresponding states from the input parameters according to the member variable names, and call the state recovery method of the state object interface by taking the states as the input parameters to finish state recovery. The state domain object provides a state generation method and a state recovery method for upper layer users of the computer. The method provides a bottom interface support for realizing the functions of abnormal interrupt recovery, unit test, dynamic update and single step debugging of the computer system, and solves the problem of difficult control of the state of memory stack data in a complex system.
The invention can be applied to mechanisms such as abnormal interrupt recovery, unit test, dynamic update, single step debugging and the like in various computer systems. This embodiment takes interrupt recovery as an example:
the abnormal interrupt recovery means that in normal execution of the computer, the operation is not completed according to a correct execution plan due to unexpected reasons, and the reasons for generating the abnormal interrupt may include memory leakage, insufficient resources, system loopholes, business logic errors, data anomalies and the like. Aborts are very common in computer programs, and in general business, they can help engineers locate problems with the system, but in some specific scenarios, such as long jobs, real-time jobs, and daemon jobs, if the running progress before the interrupt cannot be recovered in time after the interrupt, it may cause immeasurable losses.
Take the example of a "data deduplication" operation. The operation consists of three parts, namely data reading, data deduplication and data output. The data reading reads a batch of data with repeated content from the file according to the line, the data deduplication adopts the key uniqueness of the hash table as a deduplication means, and the data output outputs the data obtained by deduplication to the file according to the line. The operation adopts the design idea of stream data processing, the three parts are designed into three calculation nodes which are connected in series through a message channel, each node independently operates, and the data input node is responsible for driving the whole operation. The overall structure is shown in fig. 5.
In this job, the data input node reads data from a data file containing duplicate data, and sends the read data to the message channel. The data deduplication node continuously acquires data from the message channel, the read data is judged whether to have a duplicate key through a hash table, if yes, the data is discarded, if not, the data is recorded in the hash table and is sent to the message access. The data output node obtains the data from the message channel and outputs the data to the result file in an 'append write' mode. If the operation is normal, the data in the result file will not have a repetition phenomenon.
If an abort occurs, the "data that has occurred" in the hash table is lost. After restarting the operation, since the hash table is an empty set, the file is re-read and then de-duplicated, and repeated data will appear in the result file instead. Obviously, this is not as expected for the operation.
In order to make the job meet the expectations, the data in the hash table is continuously saved to the local file in the process of operation of the job, and when restarting is carried out due to abnormal interruption, the data is read from the file and the data in the hash table is recovered. According to the content designed by the invention, the data deduplication node can realize annotation state interfaces to have the capabilities of state generation and state recovery, and the hash table is used for registering itself with the interfaces in a mode of 'state value annotation mark'.
Based on the above design, the code design in which data deduplication is shown in the left diagram of fig. 6, in which Node abstract classes implement an annotation state interface. The hash table existData is marked by @ Status (state value annotation).
At run-time, the state generation method is performed in a timed or quantitative manner, as shown in the right-hand diagram of fig. 6 above, and the snapshot method (which is a state generation method provided by the annotation state interface and has implemented a default method) is performed by the data deduplication node at regular time. After the system interrupt is resumed, the data deduplication node executes a restore method, reads the state data from the file, and resumes. The code of the persisted portion is omitted for space and only the critical portion is retained.
After the task is restarted, the data in the hash table is restored to a state before interruption, so that the running can be continuously executed from the interruption, and the correctness of the execution result is ensured. In the application, the invention provides an annotation state interface, so that the data deduplication node has the capabilities of state recovery and state generation, and a user has the capability of customizing state contents through state annotation.
The above-described embodiments are intended to illustrate the present invention, not to limit it, and any modifications and variations made thereto are within the spirit of the invention and the scope of the appended claims.

Claims (7)

1. A method for generating and recovering class instance states based on reflection and annotation, the method comprising the steps of:
s1, adding an annotation state interface into a class instance, and providing a state generation and recovery method based on state annotation;
s2, defining a state object interface in the class instance, and providing a method for anonymously and quickly accessing member variables in the class instance under the condition of being unknown to the class; creating a state object interface total set;
s3, creating a corresponding state domain object for a class instance, and binding the state domain object to the class object instance by calling an initialization method of the state domain object, wherein the method specifically comprises the following steps:
s3.1, inputting parameters, and obtaining reflection objects of all member variables of the class object instance through reflection;
s3.2, traversing the reflection object of the member variable, judging an annotation domain, packaging the reflection object into a state object interface according to the type of the state annotation, and storing the state object interface into a state object interface total set;
if the traversal is not finished, continuing the traversal, and if the traversal is finished, executing the next step;
s4, traversing a state object interface total set maintained by the state domain object; executing a state generation method in the state object interface total set to perform state generation, collecting variable names of member variables as keys, and packaging the state object interfaces as values into key value pairs, and returning the key value pairs to a user, wherein the key value pairs are used as input parameters of a state recovery method;
the state recovery method of the state domain object obtains the corresponding state from the entry according to the member variable name, and the state is used as the entry to call the state recovery method of the state object interface, so as to complete state recovery.
2. The method for generating and recovering a state of a class instance based on reflection and annotation of claim 1, wherein annotating the state of the state interface implementation comprises: the state value annotation, the state class annotation and the state method annotation are used for marking the appointed member variable in the class, wherein the member variable appointed by the state value annotation is of a basic data type, the member variable of the state class annotation mark is of a class, and the member variable of the state method mark needs to realize an annotation state interface.
3. The method for generating and recovering a state of a class instance based on reflection and annotation of claim 2, wherein the state object interface comprises:
single instance state object interface: corresponding to the state value annotation, encapsulating the reflection object of the member variable marked by the state value annotation in the class instance into an interface, wherein the single instance state object maintains the reflection object corresponding to the class of the member variable;
multiple instance state object interface: corresponding to the state class annotation, packaging a state object set of the member variable marked by the state class annotation in the class instance as an interface, and storing the state object set corresponding to the member variable marked by the state class annotation in a key value mode by maintaining multiple cases of state objects;
method state object interface: corresponding to the state method annotation, the annotation state interfaces of the member variables marked by the state method annotation in the class instance are packaged into interfaces, and the method state object interface maintains two interfaces, including a state generation method and a state recovery method provided by the annotation state interfaces.
4. A method for generating and recovering a class instance state based on reflection and annotation as recited in claim 3, wherein only the variable names of the reflection object and the member variables are needed when creating the single instance state object interface; when creating a multi-instance state object interface, all state object interfaces in the instance and variable names of member variables are needed; when creating the method state object interface, only the reflection object of the member variable is needed.
5. A method for generating and recovering a state of a class instance based on reflection and annotation as claimed in claim 3, wherein the method for generating and recovering states of three classes of state object interfaces is as follows:
the state generation method of the single-instance state object interface is based on a call method of a reflection object, the reflected object corresponding to the state object is used as a parameter of the call method, the call method is executed to obtain the value of the member variable, the parameter name of the member variable is used as a key, and a state key value pair is formed to return; firstly, converting the type of a reflecting object into a modifiable type, and calling a call method through a Setter to inject a state value into a member variable corresponding to the reflecting object, wherein the state value is consistent with a state value structure returned by a state generating method;
the state generation method of the multi-instance state object interface specifically comprises the following steps: traversing the state generation method of all the state object interfaces in the maintained state object interface set, and returning the collected content in the form of state key value pairs; the entering of the state recovery method is that the state recovery method of the state object interface in the maintained state object interface set is traversed and executed, and meanwhile, the value is taken from the entering according to the parameter name in the state object interface to be used as the entering of the state recovery method of the current object instance;
the state generating method of the method state object interface directly executes the state generating method of the object instance and returns the result state key value pair; the entry of the state recovery method is the result of the state generation method, the state recovery method of the object instance is directly executed, and the value is taken from the entry according to the parameter name of the object instance, and the value is taken as the entry of the state recovery method of the object instance.
6. The method for generating and recovering a class instance state based on reflection and annotation according to claim 1, wherein the creating a total set of state object interfaces specifically comprises: creating a HashMap which takes a character string and a state object interface as key value pairs as a set of state object interfaces.
7. A method for generating and recovering a class instance state based on reflection and annotation according to claim 3, wherein the making of the annotation field judgment is specifically:
if the annotation domain of the current reflection object has state value annotation, packaging the reflection object into a single-instance state object interface, and storing the single-instance state object interface into a total set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state class annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, taking the value as an entry parameter, executing again from S3.1, and recursively calling an initialization method; after the call is completed, the obtained state object interface set is packaged into a plurality of cases of state object interfaces, and the plurality of cases of state object interfaces are stored into the total set by taking the variable name of the current member variable as a key;
if the annotation domain of the current reflection object has a state method annotation, taking the current class object instance as an entry, calling a call method of the reflection object to acquire the value of the member variable, packaging the value as a method state object interface, and storing the method state object interface into a total set by taking the variable name of the current member variable as a key.
CN202311018561.XA 2023-08-14 2023-08-14 Class instance state generation and recovery method based on reflection and annotation Pending CN117032652A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311018561.XA CN117032652A (en) 2023-08-14 2023-08-14 Class instance state generation and recovery method based on reflection and annotation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311018561.XA CN117032652A (en) 2023-08-14 2023-08-14 Class instance state generation and recovery method based on reflection and annotation

Publications (1)

Publication Number Publication Date
CN117032652A true CN117032652A (en) 2023-11-10

Family

ID=88627651

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311018561.XA Pending CN117032652A (en) 2023-08-14 2023-08-14 Class instance state generation and recovery method based on reflection and annotation

Country Status (1)

Country Link
CN (1) CN117032652A (en)

Similar Documents

Publication Publication Date Title
US7676492B2 (en) Migration of database using serialized objects
TWI412945B (en) Retrieving and persisting objects from/to relational databases
US8769494B2 (en) Globally sound and consistent configuration management for distributed datacenter components
CN112287007B (en) Industrial production data real-time processing method and system based on Flink SQL engine
BRPI0719730A2 (en) PROGRAMMING AND IMPLEMENTATION GUIDED BY PRODUCER GRAPH.
GB2475161A (en) Incremental implementation of undo/redo support in legacy applications
Hayashi et al. Refactoring edit history of source code
Lima et al. A framework for verifying deadlock and nondeterminism in UML activity diagrams based on CSP
CN107479866B (en) Method for realizing application data and functions of open terminal based on reconstruction technology
Xiang et al. Checking missing-data errors in cyber-physical systems based on the merged process of Petri nets
US7949688B2 (en) Method of recording and backtracking business information model changes
US10338891B2 (en) Migration between model elements of different types in a modeling environment
Rinderle et al. On representing instance changes in adaptive process management systems
Dumas et al. Robotic Process Mining.
CN117032652A (en) Class instance state generation and recovery method based on reflection and annotation
CN116400914A (en) Method for quickly constructing web application based on data model
CN114371958A (en) Automatic storage method, device, equipment and storage medium for mirror image main body
CN117130980B (en) Virtual machine snapshot management method and device
Beznosov Architecture of information enterprises: Problems and perspectives
Andrews Design and Development of a Run-time Object Design and Instantiation Framework for BPM Systems
Hackett et al. Going Beyond an Incident Report with TLA
US20100023923A1 (en) Method for medeling objects in a hetrogenious computing environment
CN114706814A (en) Automatic file processing system
CN117785943A (en) Data query method and system based on Spring Boot and elastic search
CN117372182A (en) Insurance management system based on rapid development persistent layer code auxiliary method

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