A business processing method, application generation method, server, device and equipment
By adding a lock mechanism to the base class of the object library, the target object can control the target business requested by the business, solving the data consistency problem when multiple processes modify the same data, and improving business processing efficiency and resource utilization.
Patent Information
- Application Number
- CN202210111794.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-29
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-01-29
AI Technical Summary
In the prior art, when multiple processes need to modify the same data, pessimistic locking and optimistic locking methods lead to high programming requirements, high resource consumption and low business processing efficiency.
By adding lock mechanisms for multiple object services to the base class of the object library, the target object can control the target services corresponding to the business request, including two mechanisms: pessimistic lock and optimistic lock.
It realizes data consistency of objects during business processing, reduces data processing volume and resource occupancy, and improves the operational performance and business processing efficiency of applications.
Smart Images

Figure CN114443181B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer applications, and in particular to a business processing method, an application generation method, a server, a device, a equipment and a storage medium. Background Art
[0002] In recent years, games have become more and more popular. In actual game operation, it is often the case that multiple client processes need to modify the same data, resulting in the results of multiple data modifications overwriting each other. At this time, there will be a problem of data consistency.
[0003] At present, when multiple processes need to modify the same data, two methods are generally used: pessimistic locking that queues multiple modification operations and optimistic locking that adds a version number to each modification operation. The existing pessimistic locking and optimistic locking methods lock the data to be modified for each object. This operation has high programming requirements, a large workload for developers, and large application files. It occupies a lot of memory and consumes a lot of resources during runtime, and has low business processing efficiency. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a business processing method, an application generating method, a server, an apparatus, a device and a storage medium.
[0005] The present disclosure provides a service processing method, the method comprising:
[0006] In response to a trigger operation of a user on a target object, receiving a service request sent by a client and initiated for the target object, wherein the service request includes an object address of the target object in a target process;
[0007] Based on the object address, determining the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a pre-set object library, and a lock mechanism for multiple object businesses is added to the base class;
[0008] According to the lock mechanism corresponding to the business request, the target object is controlled to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
[0009] In an optional implementation, before receiving a service request sent by a client and initiated for the target object in response to a user's triggering operation on the target object, the method includes:
[0010] Based on the target process where the target object is located, determining an object address of the target object in the target process;
[0011] The object address is sent to the client, so that the client initiates a service request for the target object based on the object address.
[0012] In an optional implementation manner, when the application is running, the target object is generated based on the following steps:
[0013] When starting the application, determining a target process running the target object in the distributed server cluster, initializing the target process, and generating the target object in the target process based on a pre-written class including the business logic; or
[0014] During the running of the application, in response to the event request sent by the client, a target object is generated in the target process based on a pre-written class including business logic.
[0015] In an optional implementation, when the lock mechanism corresponding to the business request is a pessimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes:
[0016] Determining a target service corresponding to the service request;
[0017] Adding the target service to a corresponding message queue, wherein the message queue is used to store target services of each user for the target object, and the target service has the same service content as the target service;
[0018] When it is the turn of the target service according to the order of arrangement of the services in the message queue, the target object is controlled to implement the target service.
[0019] In an optional implementation, when the lock mechanism corresponding to the business request is an optimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes:
[0020] Determining a target service corresponding to the service request;
[0021] Add a version number to the target service;
[0022] Based on the version number, the target object is controlled to implement the target service.
[0023] In an optional implementation, after controlling the target object to implement the target service corresponding to the service request according to the lock mechanism corresponding to the service request, the method includes:
[0024] Determine the business result of the target object completing the target business;
[0025] The business result is sent to the client, so that the client presents content corresponding to the business result.
[0026] The present disclosure also provides an application generation method, the method comprising:
[0027] Obtaining a class of a target object written by a user, as well as application logic of an application to be generated and a pre-set object library, wherein the class includes the business logic of the target object;
[0028] Associating the class with the base class of the object library to control the class to inherit the base class at runtime;
[0029] Add a lock mechanism for multiple object services in the base class;
[0030] Registering an object service that can be called externally among the plurality of object services in the base class;
[0031] Based on the processed object library, the class and the application logic, an application file of the application to be generated is generated.
[0032] The present disclosure also provides a server, the server comprising:
[0033] A service receiving module, configured to receive a service request sent by a client and initiated for a target object in response to a trigger operation of a user for the target object, wherein the service request includes an object address of the target object in a target process;
[0034] An object determination module, configured to determine the target object running in the target process based on the object address, wherein the target object is generated based on a pre-written class including business logic, the class inherits a pre-set base class of an object library, and a lock mechanism for multiple object businesses is added to the base class;
[0035] The business execution module is used to control the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
[0036] In an optional implementation manner, the server further includes an address sending module, and the address sending module is used to:
[0037] Based on the target process where the target object is located, determining an object address of the target object in the target process;
[0038] The object address is sent to the client, so that the client initiates a service request for the target object based on the object address.
[0039] In an optional implementation manner, the service receiving module generates the target object based on the following steps:
[0040] When starting the application, determining a target process running the target object in the distributed server cluster, initializing the target process, and generating the target object in the target process based on a pre-written class including the business logic; or
[0041] During the running of the application, in response to the event request sent by the client, a target object is generated in the target process based on a pre-written class including business logic.
[0042] In an optional implementation manner, when the lock mechanism corresponding to the business request is a pessimistic lock, the business execution module controls the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, specifically for:
[0043] Determining a target service corresponding to the service request;
[0044] Adding the target service to a corresponding message queue, wherein the message queue is used to store target services of each user for the target object, and the target service has the same service content as the target service;
[0045] When it is the turn of the target service according to the order of arrangement of the services in the message queue, the target object is controlled to implement the target service.
[0046] In an optional implementation manner, when the lock mechanism corresponding to the business request is an optimistic lock, the business execution module controls the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, specifically for:
[0047] Determining a target service corresponding to the service request;
[0048] Add a version number to the target service;
[0049] Based on the version number, the target object is controlled to implement the target service.
[0050] In an optional implementation manner, the server further includes a result sending module, and the result sending module is used to:
[0051] Determine the business result of the target object completing the target business;
[0052] The business result is sent to the client, so that the client presents content corresponding to the business result.
[0053] The present disclosure also provides an application generation device, the device comprising:
[0054] An information acquisition module, used to acquire a class of a target object written by a user, as well as application logic of an application to be generated and a pre-set object library, wherein the class includes the business logic of the target object;
[0055] A base class association module, used for associating the class with the base class of the object library, so as to control the class to inherit the base class at runtime;
[0056] A lock mechanism adding module, used for adding a lock mechanism for multiple object services in the base class;
[0057] A service registration module, used for registering an object service that can be called externally among the plurality of object services in the base class;
[0058] The file generation module is used to generate the application file of the application to be generated based on the processed object library, the class and the application logic.
[0059] An embodiment of the present disclosure also provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the above-mentioned business processing method and the above-mentioned application generation method, or steps in any possible implementation of the above-mentioned business processing method and the above-mentioned application generation method are executed.
[0060] The embodiments of the present disclosure also provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program executes the above-mentioned business processing method and the above-mentioned application generation method, or steps in any possible implementation of the above-mentioned business processing method and the above-mentioned application generation method.
[0061] The disclosed embodiments provide a business processing method, application generation method, server, device, equipment and storage medium. When generating an application, the class of the target object can be set to be associated with the base class of the object library, and a lock mechanism for the object business can be added to the base class. During application operation, the class of the target object can inherit from the base class of the object library. When a business request initiated for the target object is received, the target object can be controlled to implement the target business corresponding to the business request according to the lock mechanism added in the base class. In this way, applying a lock mechanism to the business can ensure the data consistency of the object during the business processing process, effectively reduce the data processing volume and resource occupancy rate, improve the operating performance of the application and the business processing efficiency, and when writing an application, it is only necessary to add a lock mechanism once in the base class, which can effectively reduce the amount of code, realize the lightweight application code, effectively reduce the coding workload of developers, and greatly reduce the consumption of manpower and material resources.
[0062] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0064] Figure 1 A schematic diagram showing an application scenario of a business processing method provided by an embodiment of the present disclosure is shown;
[0065] Figure 2 A flowchart of an application generation method provided by an embodiment of the present disclosure is shown;
[0066] Figure 3 A schematic diagram of application generation provided by an embodiment of the present disclosure is shown;
[0067] Figure 4 A schematic diagram of data interaction during the running of an application provided by an embodiment of the present disclosure is shown;
[0068] Figure 5 A flow chart of a business processing method provided by an embodiment of the present disclosure is shown;
[0069] Figure 6A schematic diagram of determining a target object provided by an embodiment of the present disclosure is shown;
[0070] Figure 7 A schematic diagram of implementing a target service according to an optimistic lock provided by an embodiment of the present disclosure is shown;
[0071] Figure 8 A flowchart showing another service processing method provided by an embodiment of the present disclosure is shown;
[0072] Fig. 9 One of the schematic diagrams of a server provided by an embodiment of the present disclosure is shown;
[0073] Fig.10 A second schematic diagram of a server provided by an embodiment of the present disclosure is shown;
[0074] Fig.11 A schematic diagram of an application generating device provided by an embodiment of the present disclosure is shown;
[0075] Fig.12 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0076] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0077] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0078] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0079] According to research, currently, two methods are generally used to improve data consistency: pessimistic locking that queues multiple modification operations and optimistic locking that adds a version number to each modification operation. The existing pessimistic and optimistic locking methods lock the data to be modified for each object. This operation has high programming requirements, a large workload for developers, and large application files. It occupies a lot of memory and consumes a lot of resources during runtime, and has low business processing efficiency.
[0080] Based on the above research, the present disclosure provides a business processing method and an application generation method. When generating an application, the class of the target object can be set to be associated with the base class of the object library, and a lock mechanism for the object business can be added to the base class. During the operation of the application, the class of the target object can inherit from the base class of the object library. When a business request initiated for the target object is received, the target object can be controlled to implement the target business corresponding to the business request according to the lock mechanism added in the base class. In this way, applying a lock mechanism to the business can ensure the data consistency of the object during the business processing process, effectively reduce the data processing volume and resource occupancy rate, improve the operating performance of the application and the business processing efficiency, and when writing an application, it is only necessary to add a lock mechanism once in the base class, which can effectively reduce the amount of code, realize the lightweight application code, effectively reduce the coding workload of developers, and greatly reduce the consumption of manpower and material resources.
[0081] To facilitate understanding of this embodiment, a business processing method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the business processing method provided in the embodiment of the present disclosure is generally an electronic device with certain computing capabilities, and the electronic device includes, for example, a terminal device or a server or other processing device. In some possible implementations, the business processing method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0082] See also Figure 1 , Figure 1 The following is a schematic diagram of an application scenario of a business processing method provided by an embodiment of the present disclosure. Figure 1 As shown in , in the actual application scenario, there is a server and multiple clients that can communicate with the server, and the client and the server can exchange data. In the actual application, the server is configured with an application file, and multiple clients can initiate business requests to the same business object in the server. The server can implement the task corresponding to the business request based on the mechanism corresponding to the business request.
[0083] For example, the server may be a game server, and the terminal may be a game player terminal. During the game, multiple players may make the same series of business logic requests for the same object. For example, in a game with the background of taking care of pets, multiple players may feed the same cat. At this time, the server needs to respond to the business requests of the terminals corresponding to the multiple players to implement the target business corresponding to the business requests.
[0084] See also Figure 2 , Figure 2 This is a flow chart of an application generation method provided by an embodiment of the present disclosure. Figure 2 As shown in , the application generation method provided by the embodiment of the present disclosure includes:
[0085] S201: Acquire a class of a target object written by a user, as well as application logic of an application to be generated and a preset object library, wherein the class includes the business logic of the target object.
[0086] In this step, the developer pre-writes the class to generate the target object, including the business logic of the target object, and also pre-sets the object library and the application logic of the application to be generated, so that the class, the application logic and the object library can be directly obtained.
[0087] The application to be generated, that is, the user of the application logic, can be based on the object library and set multiple object services in the object library.
[0088] Among them, the object library is a container of distributed objects for developers to use when writing applications. The object library provides base classes, based on which various types of user-defined target objects can be generated. Through the functions of the object library, the target object can automatically obtain the ability to solve data consistency problems. In addition, the object library can record the address of the target object and the address of the process that issues a business request to the target object.
[0089] S202: Associating the class with the base class of the object library to control the class to inherit the base class at runtime.
[0090] In this step, the object library provides a base class. In order to enable the class to inherit the base class of the object library, the class needs to be linked to the base class. To this end, the class can be associated with the base class of the object library, so that the class can inherit the base class at runtime.
[0091] The base class is a type oriented to the application to be generated and includes commonalities of all entities.
[0092] S203: Add a lock mechanism for multiple object services in the base class.
[0093] In this step, a lock mechanism for multiple object services may be added to the base class, so that when the subsequent application is running, the lock mechanism corresponding to the service request can be used to control the target object to implement the target service corresponding to the service request.
[0094] S204: Registering the object services that can be called externally among the multiple object services in the base class.
[0095] In this step, in actual situations, one target object corresponds to multiple object services, some of which need to be called and presented by the client, while some do not. Therefore, the multiple object services set in the object library include object services that can be called externally and object services that cannot be called externally. It is only necessary to register the object services that can be called externally in the base class.
[0096] It can be understood that the lock mechanism for multiple object services added in the base class includes the lock mechanism corresponding to the object services.
[0097] For example, in a game whose background is feeding pets, only the object business of the pet's satiety related to feeding needs to be presented, and there is no need to present the object business of the pet's cleanliness value. Therefore, it is only necessary to register the object business of the pet's satiety in the base class, and there is no need to register the object business of the pet's cleanliness value in the base class.
[0098] S205: Generate an application file of the application to be generated based on the processed object library, the class and the application logic.
[0099] In this step, the processed object library, the class and the application logic are determined, and the processed object library, the class and the application logic are integrated into the application file of the application to be generated through the processing of the compiler and the linker.
[0100] Please also see Figure 3 , Figure 3 A schematic diagram generated for an application. Figure 3 As shown in, after determining the class, the application function processing module is obtained through the action of the compiler, and after determining the application logic, the application server assembly module is obtained through the action of the compiler. When the application function processing module, the application server assembly module and the object library are determined, the application executable file is obtained by integrating them through the linker.
[0101] The application generation method provided by the embodiment of the present disclosure can obtain a class of a target object written by a user, as well as the application logic of an application to be generated and a preset object library, wherein the class includes the business logic of the target object, and the class is associated with a base class of the object library to control the class to inherit the base class at runtime, a lock mechanism for multiple object services is added to the base class, and object services that can be called externally among the multiple object services are registered in the base class, and an application file of the application to be generated is generated based on the processed object library, the class and the application logic.
[0102] In this way, when writing an application, you only need to add a lock mechanism once in the base class, which can effectively reduce the amount of code, achieve lightweight application code, effectively reduce the coding workload of developers, and greatly reduce the consumption of manpower and material resources.
[0103] See also Figure 4 , Figure 4 The following is a schematic diagram of data interaction during the running of an application provided by an embodiment of the present disclosure. Figure 4 As shown in , during the operation of the application, first, the client initiates a request to create an object, and the server creates a target object in response to the request sent by the client, and generates an object address of the target object in the target process. Then, the server returns the object address to the client. The client can initiate a service request for the target object only after obtaining the object address. Then, when the server receives the service request initiated by the client for the target object, it can understand that the service request includes the object address of the target object in the target process, thereby processing the target service corresponding to the service request, obtaining the service result, and returning the service result to the client.
[0104] Please also see Figure 5 , Figure 5 The following is a flow chart of a business processing method provided by an embodiment of the present disclosure. Figure 5 As shown in , the service processing method provided by the embodiment of the present disclosure includes:
[0105] S501: In response to a user's triggering operation on a target object, receiving a service request sent by a client and initiated for the target object, wherein the service request includes an object address of the target object in a target process.
[0106] In this step, upon receiving a trigger operation from the user on the target object, the trigger operation from the user on the target object can be responded to. It can be understood that the trigger operation will be accompanied by a service request, so the service request sent by the client and initiated for the target object can be received.
[0107] For example, in a game whose background is feeding a pet, the user triggers a button to feed the pet, that is, the user triggers the feeding event. Accordingly, the client sends a service request to increase the satiety value of the fed pet.
[0108] The target object is generated in the target process when the application is running based on a pre-written class including business logic.
[0109] For example, in a game whose background is to take care of a pet, a pre-written class is obtained, and after the class is instantiated, a target object whose object is a cat is generated in a target process.
[0110] Specifically, in an optional implementation manner, the target object is generated based on the following steps:
[0111] When starting the application, determining a target process running the target object in the distributed server cluster, initializing the target process, and generating the target object in the target process based on a pre-written class including the business logic; or
[0112] During the running of the application, in response to the event request sent by the client, a target object is generated in the target process based on a pre-written class including business logic.
[0113] In this step, the timing of generating the target in the target process based on the pre-written class including the business logic can be when starting the application, determining the target process running the target object in the distributed server cluster and initializing the target process, or it can be when responding to an event request sent by the client during the running of the application.
[0114] For example, in a game whose background is to take care of pets, the generation of a target object of a cat can be done by generating the target object of the cat when the game is started, or by generating the target object of the cat when a player initiates an event of feeding the cat during the running of the game.
[0115] Here, the generated target object is stored in a target process in a multi-process cluster with self-adjusting load balancing and availability, which can reduce the memory usage and thus achieve a higher capacity than a general data cache system.
[0116] The cluster specifically includes several processes, and each process specifically includes several objects, which are set according to the actual game mechanism and are not limited here.
[0117] It can be understood that the service request includes the object address of the target object in the target process, so that when the service request is received, the target object can be found from the distributed server cluster based on the object address. Further, only when the object address is obtained can the client locate the target object and then initiate a service request for the target object. For this purpose, the object address needs to be sent to the client in advance so that the client can initiate the service request.
[0118] Accordingly, in an optional implementation, before receiving a service request sent by a client and initiated for the target object in response to a trigger operation of a user for the target object, the method includes:
[0119] Based on the target process where the target object is located, determining an object address of the target object in the target process;
[0120] The object address is sent to the client, so that the client initiates a service request for the target object based on the object address.
[0121] In this step, when the target object is generated, the target object can be located to determine the target process where the target object is located. Furthermore, the object address of the target object in the target process can be determined, so that the object address can be sent to the client so that the client can initiate a business request for the target object based on the object address.
[0122] The client is a caller that needs to initiate a call to the target object. In addition, the client can be a portable mobile smart device such as a smart phone, a tablet computer, a wearable device, or a personal computer terminal, and no limitation is made here.
[0123] Exemplarily, when a player feeds a cat, the object address of the cat is sent to the client of the player who feeds the cat.
[0124] S502: Based on the object address, determine the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a preset object library, and a lock mechanism for multiple object businesses is added to the base class.
[0125] In this step, when the object address is determined, the target process can be determined according to the object address, thereby determining the target object running in the target process.
[0126] For example, Figure 6 For example, Figure 6 is a schematic diagram for determining the target object, such as Figure 6 As shown, in the distributed server cluster, there are processes 1, 2, 3 and 4. Different objects are created in each process, and each object has an object address in the process. When receiving a service request initiated by a client, taking the service request including address 4 as an example, according to the object address of the target object included in the service request in the target process, it can be determined that the target object is cat 4 running in process 3.
[0127] The class includes business logic and a mechanism for remote calling. Because the class inherits the base class of the object library pre-set in the application, the base class has a lock mechanism for multiple object services added to it. In this way, the methods for multiple object services included in the class correspond to the binding lock mechanism.
[0128] The lock mechanism is a mechanism used by computers to coordinate multiple processes or threads to concurrently access a resource. In databases, in addition to traditional computer resource contention, data is also a resource that needs to be shared by users. The establishment of a lock mechanism can solve the consistency and effectiveness of concurrent data access.
[0129] The lock mechanism includes but is not limited to pessimistic lock, optimistic lock, exclusive lock, shared lock, fair lock, unfair lock, and spin lock.
[0130] Among them, the implementation of the pessimistic locking mechanism locks the same object called by multiple processes or threads as a mark. When a process or thread wants to make a business request to the object, it needs to obtain the lock first. If other processes or threads are using the lock of this object at this time, they need to wait, thereby realizing the queuing of multiple business requests waiting for execution.
[0131] Among them, the implementation of the optimistic locking mechanism adds an additional version number to each read and write operation of the object. The version number represents the number of times the data corresponding to the object has been modified. In this way, before each write operation, it can be determined whether the data has been modified by other processes or threads. Only when the version number of the write operation is consistent with the version number of the read operation, the business request is considered to be successfully processed, thereby obtaining the correct business processing result.
[0132] S503: According to the lock mechanism corresponding to the business request, control the target object to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
[0133] In this step, when the target object is determined, based on the target business included in the class, the target business is registered as being able to be externally called when the class is pre-written, and is bound to a corresponding lock mechanism. The lock mechanism corresponding to the business request can be determined, and according to the lock mechanism corresponding to the business request, the target object is controlled to implement the target business corresponding to the business request.
[0134] The target service is a service bound to a lock mechanism in the object service.
[0135] The target business is bound with a corresponding lock mechanism, which may be a definition of a corresponding lock attribute added to the target business, so that the target business can be processed according to the lock mechanism during the processing.
[0136] The locking mechanism includes but is not limited to a pessimistic locking mechanism and an optimistic locking mechanism.
[0137] Exemplarily, in the case where multiple players feed the same cat, when feeding service requests sent by multiple clients of multiple players and initiated based on the address of the cat are received, the feeding of the same cat by multiple players is implemented according to the lock mechanism corresponding to the feeding service request.
[0138] Therefore, in an optional implementation manner, when the lock mechanism corresponding to the business request is a pessimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes:
[0139] Determining a target service corresponding to the service request;
[0140] Adding the target service to a corresponding message queue, wherein the message queue is used to store target services of each user for the target object, and the target service has the same service content as the target service;
[0141] When it is the turn of the target service according to the order of arrangement of the services in the message queue, the target object is controlled to implement the target service.
[0142] In this step, when the lock mechanism corresponding to the business request is a pessimistic lock, the target business corresponding to the business request is first determined, and then according to the pessimistic lock mechanism, a message queue for storing the object business of each user for the target object is set, the object business has the same business content as the target business, the target business is added to the corresponding message queue, and each business in the message queue is arranged in order of execution. When it is not the turn of the target business, the target business is queued in the message queue waiting for execution. When it is the turn of the target business, the target object is controlled to implement the target business.
[0143] For example, players A, B and C feed the same cat, and the three feeding tasks will be added to the message queue and executed in sequence. For the task of player C feeding the cat, first, when player A's task of feeding the cat is executed, player C's task of feeding the cat waits. Then, when player B's task of feeding the cat is executed, player C's task of feeding the cat waits. Finally, when it is player C's turn to feed the cat, the task is processed.
[0144] Furthermore, in an optional implementation manner, when the lock mechanism corresponding to the business request is an optimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes:
[0145] Determining a target service corresponding to the service request;
[0146] Add a version number to the target service;
[0147] Based on the version number, the target object is controlled to implement the target service.
[0148] In this step, when the lock mechanism corresponding to the business request is an optimistic lock, first determine the target business corresponding to the business request, then add a version number to the target business according to the optimistic lock mechanism, and then, when the version number is added, the target object can be controlled based on the version number to implement the target business.
[0149] For example, Figure 7 For example, Figure 7 A schematic diagram of realizing target business according to optimistic locking is shown in FIG. Figure 7As shown, player a and player b feed the same cat. Player a feeds the cat 10 points of cat food, and player b feeds the cat 20 points of cat food. A version number "1" is added to process C where the cat is located. Process A where player a feeds the cat obtains the current satiety value data of 100 points of the cat in process C, and process A also obtains the current version number "1" of process C. After player a finishes feeding the cat 10 points of cat food, process A sends back to process C the data that the cat's satiety value needs to be increased by 10 points after player a feeds the cat, and also sends back the version number "1" obtained by process A. Because the version number sent back by process A is the same as the current version number of process C, both are "1", so the processing operation is correct, process C accepts the operation of process A, the cat's satiety value data in process C increases by 10 points to 110 points, and the version number of process C is changed to "2".
[0150] Furthermore, if process B where player b feeds the cat obtains 100 points of cat satiety data from process C at the same time as process A, then process B also obtains version number "1" of process C. After player b finishes feeding the cat 20 points of cat food, process B sends back to process C the data that the cat's satiety value needs to be increased by 20 points after player b's feeding, and also sends back version number "1" obtained by process B. Because the version number of process C has been changed to "2" at this time, the two version numbers are different, so process C rejects process B's operation and sends an error prompt to process B. After receiving the error prompt, process B After that, the cat's satiety value data of 110 points in process C is retrieved, and the current version number of process C "2" is also obtained. After player b finishes feeding the cat 20 points of cat food, process B sends back to process C the data that the cat's satiety value needs to be increased by 20 points after player b's feeding, and at the same time sends back the version number "2" obtained by process B. Because the version number sent back by process B is the same as the current version number of process C, both are "2", so the processing operation is correct this time, process C accepts the operation of process B, the cat's satiety value data in process C increases by 20 points to 130 points, and the version number of process C is changed to "3".
[0151] The business processing method provided by the embodiment of the present disclosure receives a business request sent by a client and initiated for the target object in response to a trigger operation of a user on the target object, wherein the business request includes an object address of the target object in a target process; based on the object address, determines the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a pre-set object library, and a lock mechanism for multiple object businesses is added to the base class; according to the lock mechanism corresponding to the business request, controls the target object to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered as being able to be called externally, and is bound to a corresponding lock mechanism.
[0152] In this way, applying a lock mechanism to the business can ensure the data consistency of objects during business processing, effectively reduce the amount of data processing, improve business processing efficiency, further reduce resource usage, and improve application performance.
[0153] See also Figure 8 , Figure 8 Flow chart of another business processing method provided by the embodiment of the present disclosure. Figure 8 As shown in , the service processing method provided by the embodiment of the present disclosure includes:
[0154] S801: In response to a trigger operation of a user on a target object, receiving a service request sent by a client and initiated for the target object, wherein the service request includes an object address of the target object in a target process.
[0155] S802: Based on the object address, determine the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a preset object library, and a lock mechanism for multiple object businesses is added to the base class.
[0156] S803: According to the lock mechanism corresponding to the business request, control the target object to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
[0157] Among them, the description of step S801 to step S803 can refer to the description of step S501 to step S503, and can achieve the same technical effects and solve the same technical problems, and will not be repeated here.
[0158] S804: Determine the business result of the target object completing the target business.
[0159] In this step, when the target object is controlled to implement the target service corresponding to the service request, the service result of the target object completing the target service can be obtained.
[0160] S805: Send the business result to the client, so that the client presents content corresponding to the business result.
[0161] In this step, when the service result is determined, the service result may be sent to the client, and the client may present corresponding content based on the service result.
[0162] For example, when a player feeds a cat 10 points of cat food, the cat's satiety value displayed on the player's client interface increases by 10 points.
[0163] The business processing method provided by the embodiment of the present disclosure receives a business request sent by a client and initiated for the target object in response to a trigger operation of a user on the target object, wherein the business request includes an object address of the target object in a target process; based on the object address, determines the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a pre-set object library, and a lock mechanism for multiple object businesses is added to the base class; according to the lock mechanism corresponding to the business request, controls the target object to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered as being able to be called externally, and is bound to a corresponding lock mechanism.
[0164] In this way, applying a lock mechanism to the business can ensure the data consistency of objects during business processing, effectively reduce the amount of data processing, improve business processing efficiency, further reduce resource usage, and improve application performance.
[0165] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0166] Based on the same inventive concept, a server corresponding to the business processing method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned business processing method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0167] See also Fig. 9 and Fig.10 , Fig. 9One of the schematic diagrams of a server provided in an embodiment of the present disclosure, Fig.10 The second schematic diagram of a server provided in the embodiment of the present disclosure. Fig. 9 As shown in , the server 900 provided in the embodiment of the present disclosure includes:
[0168] The service receiving module 910 is used to receive a service request sent by a client and initiated for the target object in response to a trigger operation of the user for the target object, wherein the service request includes an object address of the target object in the target process;
[0169] An object determination module 920, configured to determine the target object running in the target process based on the object address, wherein the target object is generated based on a pre-written class including business logic, the class inherits a pre-set base class of an object library, and a lock mechanism for multiple object businesses is added to the base class;
[0170] The business execution module 930 is used to control the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
[0171] In an optional implementation manner, the service receiving module 910 generates the target object based on the following steps:
[0172] When starting the application, determining a target process running the target object in the distributed server cluster, initializing the target process, and generating the target object in the target process based on a pre-written class including the business logic; or
[0173] During the running of the application, in response to the event request sent by the client, a target object is generated in the target process based on a pre-written class including business logic.
[0174] In an optional implementation manner, when the lock mechanism corresponding to the business request is a pessimistic lock, the business execution module 930 controls the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, specifically for:
[0175] Determining a target service corresponding to the service request;
[0176] Adding the target service to a corresponding message queue, wherein the message queue is used to store target services of each user for the target object, and the target service has the same service content as the target service;
[0177] When it is the turn of the target service according to the order of arrangement of the services in the message queue, the target object is controlled to implement the target service.
[0178] In an optional implementation manner, when the lock mechanism corresponding to the business request is an optimistic lock, the business execution module 930 controls the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, specifically for:
[0179] Determining a target service corresponding to the service request;
[0180] Add a version number to the target service;
[0181] Based on the version number, the target object is controlled to implement the target service.
[0182] In an optional implementation, Fig.10 As shown, the server 900 further includes an address sending module 940 and a result sending module 950 .
[0183] The address sending 940 module is used for:
[0184] Based on the target process where the target object is located, determining an object address of the target object in the target process;
[0185] The object address is sent to the client, so that the client initiates a service request for the target object based on the object address.
[0186] The result sending module 950 is used for:
[0187] Determine the business result of the target object completing the target business;
[0188] The business result is sent to the client, so that the client presents content corresponding to the business result.
[0189] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0190] The server provided by the embodiment of the present disclosure receives, in response to a user's trigger operation on a target object, a business request sent by a client and initiated for the target object, wherein the business request includes an object address of the target object in a target process; based on the object address, determines the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a pre-set object library, and a lock mechanism for multiple object services is added to the base class; according to the lock mechanism corresponding to the business request, controls the target object to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered as being able to be called externally, and is bound to a corresponding lock mechanism.
[0191] In this way, applying a lock mechanism to the business can ensure the data consistency of objects during business processing, effectively reduce the amount of data processing, improve business processing efficiency, further reduce resource usage, and improve application performance.
[0192] Based on the same inventive concept, an application generation device corresponding to the application generation method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned application generation method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0193] See also Fig.11 , Fig.11 A schematic diagram of an application generation device provided by an embodiment of the present disclosure. Fig.11 As shown in , the application generating device 1100 provided in the embodiment of the present disclosure includes:
[0194] The information acquisition module 1110 is used to acquire the class of the target object written by the user, the application logic of the application to be generated, and the pre-set object library, wherein the class includes the business logic of the target object;
[0195] A base class association module 1120, used for associating the class with the base class of the object library, so as to control the class to inherit the base class at runtime;
[0196] A lock mechanism adding module 1130, used to add a lock mechanism for multiple object services in the base class;
[0197] A service registration module 1140, configured to register an object service that can be externally called among the plurality of object services in the base class;
[0198] The file generation module 1150 is used to generate the application file of the application to be generated based on the processed object library, the class and the application logic.
[0199] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0200] The application generation device provided by the embodiment of the present disclosure can obtain the class of the target object written by the user, the application logic of the application to be generated and the preset object library, wherein the class includes the business logic of the target object, associates the class with the base class of the object library to control the class to inherit the base class at runtime, adds a lock mechanism for multiple object services to the base class, registers the object services that can be called externally among the multiple object services in the base class, and generates the application file of the application to be generated based on the processed object library, the class and the application logic.
[0201] In this way, when writing an application, you only need to add a lock mechanism once in the base class, which can effectively reduce the amount of code, achieve lightweight application code, effectively reduce the coding workload of developers, and greatly reduce the consumption of manpower and material resources.
[0202] Corresponds to Figure 5 and Figure 8 Business processing methods in Figure 2 The application generation method in the present disclosure also provides an electronic device 1200, such as Fig.12 FIG. 1 is a schematic diagram of the structure of an electronic device 1200 provided in an embodiment of the present disclosure, including:
[0203] Processor 1210, memory 1220, and bus 1230; memory 1220 is used to store execution instructions, including memory 1221 and external memory 1222; memory 1221 here is also called internal memory, which is used to temporarily store the operation data in processor 1210 and the data exchanged with external memory 1222 such as hard disk. Processor 1210 exchanges data with external memory 1222 through memory 1221. When the electronic device 1200 is running, the processor 1210 communicates with the memory 1220 through bus 1230, so that the processor 1210 executes Figure 5 and Figure 8 The steps of the business processing method in Figure 2 The steps of the application generation method in .
[0204] The present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the business processing method or application generation method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0205] The present disclosure also provides a computer program product, which includes computer instructions. When the computer instructions are executed by a processor, the steps of the business processing method or application generation method described in the above method embodiment can be executed. For details, please refer to the above method embodiment, which will not be repeated here.
[0206] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0207] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working processes of the servers, electronic devices and devices described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed servers, electronic devices, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0208] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0209] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0210] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0211] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A business processing method, characterized in that: include: In response to a trigger operation of a user on a target object, receiving a service request sent by a client and initiated for the target object, wherein the service request includes an object address of the target object in a target process; Based on the object address, determining the target object running in the target process, wherein the target object is generated based on a pre-written class including business logic, the class inherits a base class of a pre-set object library, and a lock mechanism for multiple object businesses is added to the base class; According to the lock mechanism corresponding to the business request, the target object is controlled to implement the target business corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound with a corresponding lock mechanism.
2. The method according to claim 1, characterized in that Before receiving a service request sent by a client and initiated for the target object in response to a trigger operation of the user on the target object, the method includes: Based on the target process where the target object is located, determining an object address of the target object in the target process; The object address is sent to the client, so that the client initiates a service request for the target object based on the object address.
3. The method according to claim 1, characterized in that The target object is generated based on the following steps: When starting the application, determining a target process running the target object in the distributed server cluster, initializing the target process, and generating the target object in the target process based on a pre-written class including the business logic; or During the running of the application, in response to the event request sent by the client, a target object is generated in the target process based on a pre-written class including business logic.
4. The method according to claim 1, characterized in that: In a case where the lock mechanism corresponding to the business request is a pessimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes: Determining a target service corresponding to the service request; Adding the target service to a corresponding message queue, wherein the message queue is used to store target services of each user for the target object, and the target service has the same service content as the target service; When it is the turn of the target service according to the order of arrangement of the services in the message queue, the target object is controlled to implement the target service.
5. The method according to claim 1, characterized in that In a case where the lock mechanism corresponding to the business request is an optimistic lock, controlling the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request includes: Determining a target service corresponding to the service request; Add a version number to the target service; Based on the version number, the target object is controlled to implement the target service.
6. The method according to claim 1, characterized in that After controlling the target object to implement the target service corresponding to the service request according to the lock mechanism corresponding to the service request, the method includes: Determine the business result of the target object completing the target business; The business result is sent to the client, so that the client presents content corresponding to the business result.
7. An application generation method, characterized in that: The method comprises: Obtaining a class of a target object written by a user, as well as application logic of an application to be generated and a pre-set object library, wherein the class includes the business logic of the target object; Associating the class with the base class of the object library to control the class to inherit the base class at runtime; Add a lock mechanism for multiple object services in the base class; Registering an object service that can be called externally among the plurality of object services in the base class; Based on the processed object library, the class and the application logic, an application file of the application to be generated is generated.
8. A server, characterized in that: The server comprises: A service receiving module, configured to receive a service request sent by a client and initiated for a target object in response to a trigger operation of a user for the target object, wherein the service request includes an object address of the target object in a target process; An object determination module, configured to determine the target object running in the target process based on the object address, wherein the target object is generated based on a pre-written class including business logic, the class inherits a pre-set base class of an object library, and a lock mechanism for multiple object businesses is added to the base class; The business execution module is used to control the target object to implement the target business corresponding to the business request according to the lock mechanism corresponding to the business request, wherein the class includes the target business, the target business is pre-registered to be able to be called externally, and is bound to the corresponding lock mechanism.
9. An application generating device, characterized in that: The device comprises: An information acquisition module, used to acquire a class of a target object written by a user, as well as application logic of an application to be generated and a pre-set object library, wherein the class includes the business logic of the target object; A base class association module, used for associating the class with the base class of the object library, so as to control the class to inherit the base class at runtime; A lock mechanism adding module, used for adding a lock mechanism for multiple object services in the base class; A service registration module, used for registering an object service that can be called externally among the plurality of object services in the base class; The file generation module is used to generate the application file of the application to be generated based on the processed object library, the class and the application logic.
10. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the business processing method according to any one of claims 1 to 6 or the application generation method according to claim 7 are performed.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the business processing method according to any one of claims 1 to 6 or the application generation method according to claim 7.
Citation Information
Patent Citations
Resource management method, client and system
CN103873343A
Vehicle real-time information scheduling method based on timed task framework
CN111177164A