WO2019024305A1 - 消息处理方法、装置、电子设备及计算机可读存储介质 - Google Patents

消息处理方法、装置、电子设备及计算机可读存储介质 Download PDF

Info

Publication number
WO2019024305A1
WO2019024305A1 PCT/CN2017/109572 CN2017109572W WO2019024305A1 WO 2019024305 A1 WO2019024305 A1 WO 2019024305A1 CN 2017109572 W CN2017109572 W CN 2017109572W WO 2019024305 A1 WO2019024305 A1 WO 2019024305A1
Authority
WO
WIPO (PCT)
Prior art keywords
class
business logic
message processing
target business
abstract
Prior art date
Application number
PCT/CN2017/109572
Other languages
English (en)
French (fr)
Inventor
张磊
陈少杰
张文明
Original Assignee
武汉斗鱼网络科技有限公司
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 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2019024305A1 publication Critical patent/WO2019024305A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a message processing method, apparatus, electronic device, and computer readable storage medium.
  • An application usually needs to implement multiple business logics, and the program code for independently completing a business logic belongs to a hierarchy. Sometimes the various levels of program code may need to perform time-consuming operations, and the application's user interface needs to be updated as the operation completes. For this type of operation, the existing approach is to open a separate sub-thread to execute, so as not to cause the user interface to block. The update of the user interface needs to be performed in the main thread of the application, which requires the child thread to pass the result of the operation execution to the main thread to update the user interface.
  • asynchronous message processing classes are commonly used to implement message passing between a child thread and a main thread.
  • the existing approach is to instantiate asynchronous message processing classes in the hierarchy of asynchronous message processing in the application, which results in multiple levels of instantiation of asynchronous message processing objects in the application, resulting in memory overhead. Increase.
  • instantiating asynchronous message processing objects in multiple levels can lead to repetitive development problems, which reduces development efficiency and wastes development costs.
  • an embodiment of the present invention provides a message processing method, which is applied to an application that implements multiple service logics, where the method includes:
  • the instantiated object of the asynchronous message processing class is called in the implementation class, and the message of the target business logic is processed.
  • the step of determining, in the abstract class, whether the target service logic needs to process the message asynchronously, based on the determining condition set in the implementation class of the target business logic includes:
  • the switch method is invoked in the constructor and determines whether the target business logic needs to process the message asynchronously based on the return value of the switch method.
  • the abstracted switch method only includes a method name that is delayed into implementation in a subclass of the abstract class.
  • the method further includes: causing an implementation class of the target business logic to inherit from the abstract class, where the target business logic is that the message needs to be processed asynchronously Business logic.
  • the step of determining whether the asynchronous message processing class is instantiated in the abstract class includes:
  • the method before performing the step of determining whether the asynchronous message processing class is instantiated in the abstract class, the method further includes:
  • the step of invoking the instantiated object of the asynchronous message processing class in the implementation class, and processing the message of the target business logic includes:
  • the message of the target business logic is processed by the obtained instantiated object.
  • the step of invoking the object obtaining method in the implementation class includes:
  • the object obtaining method in the abstract class is called in the implementation class of the target business logic to obtain the instantiated object of the asynchronous message processing class in the abstract class.
  • An embodiment of the present invention further provides a message processing apparatus, which is applied to an application that implements multiple service logics, where the apparatus includes:
  • the determining module is configured to determine, according to the determining condition set in the implementation class of the target business logic, whether the target business logic needs to process the message asynchronously in the abstract class, and the implementation class inherits from the abstract class;
  • An instantiation module configured to determine whether an asynchronous message processing class is instantiated in the abstract class when the target business logic needs to process the message asynchronously, and if not instantiated, instantiating the asynchronous message processing class;
  • the processing module is configured to invoke an instantiated object of the asynchronous message processing class in the implementation class to process a message of the target business logic.
  • the determining module determines, according to the determining condition set in the implementation class of the target service logic, whether the target service logic needs to process the message asynchronously in the abstract class, including:
  • the switch method is invoked in the constructor and determines whether the target business logic needs to process the message asynchronously based on the return value of the switch method.
  • the determining module determines, according to the determining condition that is set in the implementation class of the target business logic, whether the target business logic needs to process the message asynchronously in the abstract class, and further includes:
  • the abstract switch method only includes the method name, which is delayed to be implemented in a subclass of the abstract class.
  • the determining module determines, according to the determining condition that is set in the implementation class of the target business logic, whether the target business logic needs to process the message asynchronously in the abstract class, and further includes:
  • the method further includes: causing an implementation class of the target business logic to inherit from the abstract class, wherein the target business logic is a business logic that needs to process a message asynchronously.
  • the determining module includes:
  • a first obtaining sub-module configured to obtain a return value of the object obtaining method, where the object obtaining method is configured to acquire an instantiated object of the asynchronous message processing class and return;
  • the determining submodule is configured to determine that the asynchronous message processing class is not instantiated in the abstract class when the return value of the object obtaining method is not empty.
  • the device further includes:
  • the object acquisition module is configured to declare the object acquisition method in the abstract class before determining whether the asynchronous message processing class is instantiated in the abstract class.
  • the processing module includes:
  • a second obtaining submodule configured to invoke the object obtaining method in the implementation class to acquire an instantiated object of the asynchronous message processing class
  • the processing submodule is configured to process the message of the target business logic by the obtained instantiated object.
  • the second obtaining submodule is configured to invoke the object obtaining method in the implementation class to obtain an instantiated object of an asynchronous message processing class in an abstract class.
  • An electronic device comprising a memory, a processor, and a computer program stored in the memory and executed in the processor, the computer program being executed to implement the method provided by the present invention.
  • a computer readable storage medium having stored thereon a computer program that, when executed, implements the methods provided by the present invention.
  • the message processing method and apparatus provided by the embodiments of the present invention, and the computer readable storage medium of the electronic device determine whether the target business logic needs to process the message asynchronously in the abstract class, and the asynchronous message processing class is not instantiated in the abstract class.
  • the asynchronous message processing class is instantiated, and the instantiated object of the asynchronous message processing class is called in the implementation class of the target business logic to implement asynchronous processing of the message.
  • the asynchronous message processing class can be instantiated only in the abstract class, and each business logic in the application calls the instantiated object of the asynchronous message processing class when the message needs to be processed asynchronously, so that the asynchronous processing of the message can be realized, and the memory is greatly reduced. Overhead, improving development efficiency.
  • FIG. 1 is a schematic block diagram of an electronic device according to an embodiment of the present invention.
  • FIG. 2 is a schematic flowchart diagram of a message processing method according to an embodiment of the present invention.
  • FIG. 3 is a schematic diagram of the sub-steps of step S110 shown in FIG. 2.
  • FIG. 4 is a functional block diagram of a message processing apparatus according to an embodiment of the present invention.
  • FIG. 5 is still another functional block diagram of a message processing apparatus according to an embodiment of the present invention.
  • Icon 100-electronic device; 110-message processing device; 111-judgement module; 1111-first acquisition sub-module; 1112-determination sub-module; 112- instantiation module; 113-processing module; 1131-second acquisition sub-module ; 1132 - processing sub-module; 114 - object acquisition module; 120 - memory; 130 - processor; 140 - display unit.
  • FIG. 1 it is a block diagram of an electronic device 100 according to an embodiment of the present invention.
  • An application program is installed in the electronic device 100 , and the application program implements multiple service logics.
  • Each business logic can be implemented by a separate functional module, that is, the application includes a plurality of functional modules.
  • the electronic device 100 may be an electronic device based on an Android system.
  • the device 100 includes a message processing device 110, a memory 120, a processor 130, and a display unit 140.
  • the components of the memory 120, the processor 130, and the display unit 140 are electrically connected directly or indirectly to each other to implement data transmission or interaction.
  • the components can be electrically connected to one another via one or more communication buses or signal lines.
  • the message processing device 110 includes at least one software function module that can be stored in the memory 120 or in an operating system of the electronic device 100 in the form of software or firmware.
  • the processor 130 is configured to execute executable modules stored in the memory 120, such as application programs and software function modules and computer programs included in the message processing device 110, and the like.
  • the memory 120 can be, but not limited to, a random access memory (RAM), a read only memory (ROM), and a programmable read-only memory (PROM). Erasable Programmable Read-Only Memory (EPROM), Electric Erasable Programmable Read-Only Memory (EEPROM), and the like.
  • RAM random access memory
  • ROM read only memory
  • PROM programmable read-only memory
  • EPROM Erasable Programmable Read-Only Memory
  • EEPROM Electric Erasable Programmable Read-Only Memory
  • the processor 130 can be an integrated circuit chip with signal processing capabilities.
  • the above processor may also be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; or a digital signal processor (DSP), an application specific integrated circuit ( ASIC), Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component.
  • CPU central processing unit
  • NP network processor
  • DSP digital signal processor
  • ASIC application specific integrated circuit
  • FPGA Field Programmable Gate Array
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • the display unit 140 is configured to establish an interaction interface between the electronic device 100 and the user or to display a view to be displayed.
  • the view can be understood as an instance object that is instantiated in an Android system, and can be any image that can be displayed on the display interface, such as an image or a text box.
  • the display unit 140 is configured to establish an interaction interface between the electronic device 100 and the user, or to display information to be displayed, for example, a user interface of the application.
  • FIG. 1 is merely illustrative, and the electronic device 100 may also have more or less components than those shown in FIG. 1, or may have a different configuration from that shown in FIG. It should be noted that the components shown in FIG. 1 can be implemented in hardware, software, or a combination thereof.
  • FIG. 2 it is a schematic flowchart of a message processing method according to an embodiment of the present invention.
  • the message processing method is applied to an application in an electronic device 100, and the application can implement multiple service logics.
  • the specific processes and steps shown in FIG. 2 will be described in detail below.
  • Step S110 Determine, according to the judgment condition set in the implementation class of the target business logic, whether the target business logic needs to process the message asynchronously in the abstract class.
  • the application may be a video player.
  • a video player can include multiple business logics such as video playback, control bar display, gift special effects display, and user information display.
  • the individual business logic can be implemented independently by the corresponding functional modules.
  • the functional modules for implementing a business logic belong to a hierarchy.
  • the asynchronous message processing class may be a Handler, and correspondingly, the asynchronous message processing object or the instantiated object of the asynchronous message processing class refers to a Handler object.
  • each level needs to process messages asynchronously through its own Handler object
  • the Handler objects used by each level in the same application are actually the same. If only a Handler object is instantiated, and the Handler object is used when needed at each level, the memory overhead can be greatly reduced and the development efficiency can be improved.
  • the present invention has improved the design architecture of the application.
  • an abstract class is constructed, and business logic that needs to be implemented at multiple levels in the application is declared and/or implemented in the abstract class.
  • the function modules corresponding to the respective business logics of the application are implemented as inheritance classes that inherit from the abstract class. For example, taking the above video player as an example, an implementation class for implementing video playback inherits from the abstract class.
  • Business logic that is completely consistent with the functionality implemented in multiple hierarchies can be implemented directly in the abstract class.
  • Business logic that differs in functionality implemented in multiple hierarchies but differs little can be declared as an abstract method in an abstract class, and the abstraction method is overridden and implemented by an override instruction in an implementation class that implements the business logic.
  • step S110 may include step S111, step S112, and Step S113 is three sub-steps.
  • Step S111 declaring a constructor and an abstract switch method in the abstract class.
  • Step S112 rewriting and implementing the switching method in the implementation class, so that the return value of the switching method corresponds to whether the target business logic needs an asynchronous processing message.
  • the switch method declared in the abstract class is an abstract method, that is, in the abstract class, the switch method has only the method name and no method body.
  • the switch method is delayed to be implemented in a subclass of the abstract class.
  • the implementation class of the target business logic may be inherited by the abstract class, and in the target business logic.
  • the implementation class overrides and implements the switch method such that the return value of the switch method corresponds to whether the target business logic needs to process the message asynchronously.
  • the return value of the switch method is set to true, and if the target business logic does not need to process the message asynchronously, the return value of the switch method is set to false.
  • the switching method may be rewritten by an override instruction.
  • Step S113 calling the switch method in the constructing method, and determining whether the target service logic needs to process the message asynchronously based on the return value of the switch method.
  • the constructor is an intrinsic method of object creation.
  • the constructor of the abstract class is automatically called when it is instantiated.
  • the constructor is declared and implemented in an abstract class. That is, the constructor in the abstract class has a method body.
  • the switch method may be invoked in the constructing method.
  • the switch method has been rewritten in an implementation class of the target business logic, and thus, constructing The method actually performs the rewritten switch method.
  • the electronic device 100 can determine whether the target business logic needs to process the message asynchronously according to the return value of the switch method. According to the above example, if the return value of the switch method is true, the electronic device 100 determines that the target service logic needs to process the message asynchronously. If the return value of the switch method is false, the electronic device 100 determines that the target service logic does not need to be asynchronous. Process the message.
  • Step S120 When the target business logic needs to process the asynchronous message, determine whether the asynchronous message processing class is instantiated in the abstract class, and if not instantiated, instantiate the asynchronous message processing class.
  • asynchronous message processing class as a Handler
  • Determine the target business logic needs to process the message asynchronously then further determine whether there is a Handler object in the abstract class. If there is no Handler object in the abstract class, then instantiate the Handler to get a Handler object. In this way, you can guarantee that there is only one Handler object in the abstract class, which reduces memory overhead.
  • step S130 the instantiated object of the asynchronous message processing class is invoked in the implementation class, and the message of the target business logic is processed.
  • the Handler object in the abstract class is obtained in the implementation class of the target business logic and the message is asynchronously processed by the Handler object without having to re-instantiate a Handler object. It is equivalent to directly taking the Handler object in the abstract class when needed.
  • the method may further include the following steps:
  • the object acquisition method user acquires an instantiated object of the asynchronous message processing class and returns.
  • the object obtaining method may be getDefaultHandler().
  • the method getDefaultHandler() will return a Handler object.
  • the electronic device 100 does not instantiate the Handler, and the method getDefaultHandler() returns an empty object.
  • the step of determining whether the asynchronous message processing class is instantiated in the abstract class in step S120 may be implemented by the following substeps:
  • step S130 can be implemented by the following steps:
  • the object obtaining method is invoked in the implementation class to obtain an instantiated object of the asynchronous message processing class.
  • the message of the target business logic is processed by the obtained instantiated object.
  • the object obtaining method in the abstract class may be invoked in the implementation class of the target business logic to obtain the Handler object in the abstract class, so that the level of the target business logic can perform asynchronous message processing through the Handler object.
  • an embodiment of the present invention further provides a message processing apparatus 110, where the message processing apparatus 110 should An application for use in electronic device 100 that implements multiple business logic.
  • the message processing apparatus 110 includes a determination module 111, an instantiation module 112, and a processing module 113.
  • the determining module 111 is configured to determine, in the abstract class, whether the target business logic needs to process the message asynchronously based on the determining condition set in the implementation class of the target business logic.
  • the description of the determining module 111 can be specifically referred to the detailed description of the step S110 shown in FIG. 2, that is, the step S110 can be performed by the determining module 111.
  • the determining, by the determining module 111, based on the determining condition that is set in the implementation class of the target service logic, determining, in the abstract class, whether the target service logic needs to process the message asynchronously may include:
  • the switch method is overridden and implemented in the implementation class such that the return value of the switch method corresponds to whether the target business logic requires an asynchronous processing message.
  • the switch method is invoked in the constructor and determines whether the target business logic needs to process the message asynchronously based on the return value of the switch method.
  • the instantiation module 112 is configured to determine whether an asynchronous message processing class is instantiated in the abstract class when the target business logic needs to process the message asynchronously, and if not instantiated, instantiate the asynchronous message processing class .
  • the asynchronous message processing class may be a Handler.
  • the description about the instantiation module 112 may be specifically referred to the detailed description of the step S120 shown in FIG. 2, that is, the step S120 may be performed by the instantiation module 112.
  • the processing module 113 is configured to invoke an instantiated object of the asynchronous message processing class in the implementation class to process a message of the target business logic.
  • the description of the processing module 113 can be specifically referred to the detailed description of the step S130 shown in FIG. 2, that is, the step S130 can be performed by the processing module 113.
  • the message processing apparatus 110 may further include an object obtaining module 114.
  • the object obtaining module 114 is configured to declare an object obtaining method in the abstract class before determining whether the asynchronous message processing class is instantiated in the abstract class, and the object obtaining method is configured to acquire the asynchronous message processing Instantiate the object of the class and return.
  • the description of the object obtaining module 114 may refer specifically to the related steps in the foregoing content. Detailed description.
  • the determination module 111 may include an acquisition submodule and a determination submodule 1112.
  • the obtaining submodule is configured to acquire a return value of the object obtaining method.
  • the description about the acquisition sub-module may refer to the description of related steps in the above content.
  • the determining sub-module 1112 is configured to determine that the asynchronous message processing class is not instantiated in the abstract class when the return value of the object acquisition method is not empty.
  • the description about the determining sub-module 1112 may be specifically referred to the description of the relevant steps in the above content.
  • the processing module 113 may include a second acquisition submodule 1131 and a processing submodule 1132.
  • the second obtaining submodule 1131 is configured to invoke the object obtaining method in the implementation class to acquire an instantiated object of the asynchronous message processing class.
  • the description of the second obtaining sub-module 1131 may be specifically referred to the detailed description of the related steps in the foregoing content.
  • the processing sub-module 1132 is configured to process the message of the target business logic by the obtained instantiated object.
  • the description of the processing sub-module 1132 may be specifically referred to the detailed description of the relevant steps in the above content.
  • the embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium stores a computer program, and when the computer program is executed, the message processing method provided by the embodiment of the present invention is implemented.
  • the message processing method and apparatus and the electronic device 100 determine whether the target service logic needs to process the message asynchronously in the abstract class, and the asynchronous message processing class is not instantiated in the abstract class.
  • the asynchronous message processing class is instantiated, and the instantiated object of the asynchronous message processing class is called in the implementation class of the target business logic to implement asynchronous processing of the message.
  • the asynchronous message processing class can be instantiated only in the abstract class, and each business logic in the application calls the instantiated object of the asynchronous message processing class when the message needs to be processed asynchronously, so that the asynchronous processing of the message can be realized, and the memory is greatly reduced. Overhead, improving development efficiency.
  • each block of the flowchart or block diagram can represent a module, a program segment, or a portion of code that includes one or more of the Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may also occur in a different order than those illustrated in the drawings.
  • each block of the block diagrams and/or flowcharts, and combinations of blocks in the block diagrams and/or flowcharts can be implemented in a dedicated hardware-based system that performs the specified function or action. Or it can be implemented by a combination of dedicated hardware and computer instructions.
  • each functional module in each embodiment of the present invention may be integrated to form a separate part, or each module may exist separately, or two or more modules may be integrated to form a separate part.
  • the functions, if implemented in the form of software functional modules and sold or used as separate products, may be stored in a computer readable storage medium.
  • the technical solution of the present invention which is essential or contributes to the prior art, or a part of the technical solution, may be embodied in the form of a software product, which is stored in a storage medium, including
  • the instructions are used to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .
  • the message processing method, device, electronic device and computer readable storage medium determine whether the target business logic needs to process the message asynchronously in the abstract class.
  • the asynchronous message processing class can be instantiated only in the abstract class.
  • Each business logic calls the instantiated object of the asynchronous message processing class when the message needs to be processed asynchronously, so that the asynchronous processing of the message can be realized, the memory overhead is greatly reduced, and the development efficiency is improved.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

一种消息处理方法、装置、电子设备及计算机可读存储介质,方法及装置应用于包括多个业务逻辑的应用程序。方法包括:基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断目标业务逻辑是否需要异步处理消息,该实现类继承于该抽象类(S110);在目标业务逻辑需要异步处理消息时,判断该抽象类中是否实例化有异步消息处理类,若未实例化,则实例化异步消息处理类(S120);在该实现类中调用异步消息处理类的实例化对象,对目标业务逻辑的消息进行处理(S130)。如此,可以仅在抽象类中实例化异步消息处理类,应用程序中的各业务逻辑在需要异步处理消息时调用该异步消息处理类的实例化对象即可实现消息的异步处理,大大降低了内存开销,提高了开发效率。

Description

消息处理方法、装置、电子设备及计算机可读存储介质
本申请要求于2017年08月01日提交中国专利局的申请号为CN2017106480646、名称为“消息处理方法、装置及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及通信技术领域,具体而言,涉及一种消息处理方法、装置、电子设备及计算机可读存储介质。
背景技术
一个应用程序通常需要实现多个业务逻辑,用于独立完成一个业务逻辑的程序代码属于一个层级。有时各个层级的程序代码可能需要执行耗时的操作,并且在该操作执行完毕时需要对应用程序的用户界面进行更新。针对这类操作,现有的做法是开辟一个单独的子线程来执行,以免造成用户界面的阻塞。而用户界面的更新需要在应用程序的主线程进行,这就要求子线程将操作执行的结果传递到主线程,以使用户界面更新。
目前,通常采用异步消息处理类来实现子线程与主线程之间的消息传递。现有的做法是在应用程序中需要进行异步消息处理的层级中对异步消息处理类进行实例化,这就导致应用程序中有多个层级都实例化有异步消息处理对象,会导致内存的开销增大。同时,在多个层级中实例化异步消息处理对象会导致重复开发的问题,既降低了开发效率,又浪费了开发成本。
发明内容
有鉴于此,本发明的目的在于提供一种消息处理方法、装置、电子设备及计算机可读存储介质,以改善上述问题。
为了达到上述目的,本发明实施例提供一种消息处理方法,应用于实现多个业务逻辑的应用程序,所述方法包括:
基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息,所述实现类继承于所述抽象类;
在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息 处理类,若未实例化,则实例化所述异步消息处理类;
在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
可选地,在上述方法中,基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的步骤,包括:
在所述抽象类中声明构造方法以及抽象的开关方法;
在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应;
在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
可选地,抽象的所述开关方法仅包括方法名,所述开关方法延迟到所述抽象类的子类中实现。
可选地,在所述实现类中重写并实现所述开关方法之前还包括:使所述目标业务逻辑的实现类继承于所述抽象类,其中,所述目标业务逻辑为需要异步处理消息的业务逻辑。
可选地,在上述方法中,判断所述抽象类中是否实例化有异步消息处理类的步骤,包括:
获取对象获取方法的返回值,所述对象获取方法用于获取所述异步消息处理类的实例化对象并返回;
在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
可选地,在执行判断所述抽象类中是否实例化有异步消息处理类的步骤之前,所述方法还包括:
在所述抽象类中声明所述对象获取方法。
可选地,在上述方法中,在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理的步骤,包括:
在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象;
通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
可选地,在所述实现类中调用所述对象获取方法的步骤包括:
在所述目标业务逻辑的实现类中调用抽象类中的对象获取方法,以获取抽象类中的异步消息处理类的实例化对象。
本发明实施例还提供一种消息处理装置,应用于实现多个业务逻辑的应用程序,所述装置包括:
判断模块,被配置成基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息,所述实现类继承于所述抽象类;
实例化模块,被配置成在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息处理类,若未实例化,则实例化所述异步消息处理类;
处理模块,被配置成在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
可选地,在上述装置中,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,包括:
在所述抽象类中声明构造方法以及抽象的开关方法;
在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应;
在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
可选地,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,还包括:
抽象的所述开关方法仅包括方法名,所述开关方法延迟到所述抽象类的子类中实现。
可选地,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,还包括:
在所述实现类中重写并实现所述开关方法之前还包括:使所述目标业务逻辑的实现类继承于所述抽象类,其中,所述目标业务逻辑为需要异步处理消息的业务逻辑。
可选地,在上述装置中,所述判断模块包括:
第一获取子模块,被配置成获取对象获取方法的返回值,所述对象获取方法用于获取所述异步消息处理类的实例化对象并返回;
确定子模块,被配置成在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
可选地,所述装置还包括:
对象获取模块,被配置成在判断所述抽象类中是否实例化有异步消息处理类之前,在所述抽象类中声明所述对象获取方法。
可选地,在上述装置中,所述处理模块包括:
第二获取子模块,被配置成在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象;
处理子模块,被配置成通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
可选地,所述第二获取子模块被配置成在所述实现类中调用所述对象获取方法,以获取抽象类中的异步消息处理类的实例化对象。
一种电子设备,包括存储器、处理器以及存储在所述存储器中并在所述处理器中被执行的计算机程序,所述计算机程序被执行时实现本发明提供的方法。
一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被执行时实现本发明提供的方法。
本发明实施例提供的消息处理方法、装置、电子设备计算机可读存储介质,在抽象类中判断目标业务逻辑是否需要异步处理消息,在需要且抽象类中未实例化有异步消息处理类的情况下实例化异步消息处理类,并在该目标业务逻辑的实现类中调用异步消息处理类的实例化对象,以实现消息的异步处理。如此,可以仅在抽象类中实例化异步消息处理类,应用程序中的各业务逻辑在需要异步处理消息时调用该异步消息处理类的实例化对象即可实现消息的异步处理,大大降低了内存开销,提高了开发效率。
为使本发明的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图作详细说明。
附图说明
为了更清楚地说明本发明实施例的方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
图1为本发明实施例提供的一种电子设备的方框示意图。
图2为本发明实施例提供的一种消息处理方法的流程示意图。
图3为图2所示步骤S110的子步骤示意图。
图4为本发明实施例提供的一种消息处理装置的功能模块框图。
图5为本发明实施例提供的消息处理装置的又一功能模块框图。
图标:100-电子设备;110-消息处理装置;111-判断模块;1111-第一获取子模块;1112-确定子模块;112-实例化模块;113-处理模块;1131-第二获取子模块;1132-处理子模块;114-对象获取模块;120-存储器;130-处理器;140-显示单元。
具体实施方式
下面将结合本发明实施例中附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。通常在此处附图中描述和展示的本发明实施例的组件可以以各种不同的配置来布置和设计。
因此,以下对在附图中提供的本发明的实施例的详细描述并非旨在限制要求保护的本发明的范围,而是仅仅表示本发明的选定实施例。基于本发明的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。同时,在本发明的描述中,术语“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。
如图1所示,是本发明实施例提供的一种电子设备100的方框示意图,所述电子设备100中安装有应用程序,所述应用程序实现多个业务逻辑。每个业务逻辑可由独立的功能模块实现,也即,所述应用程序包括多个功能模块。
在本实施例中,所述电子设备100可以是基于Android系统的电子设备。所述电子设 备100包括消息处理装置110、存储器120、处理器130以及显示单元140。
所述存储器120、处理器130以及显示单元140各元件相互之间直接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可通过一条或多条通讯总线或信号线实现电性连接。消息处理装置110包括至少一个可以软件或固件(firmware)的形式存储于存储器120中或固化在电子设备100的操作系统中的软件功能模块。处理器130用于执行存储在存储器120中的可执行模块,例如应用程序以及消息处理装置110所包括的软件功能模块和计算机程序等。
其中,存储器120可以是,但不限于,随机存取存储器(Random Access Memory,RAM),只读存储器(Read Only Memory,ROM),可编程只读存储器(Programmable Read-Only Memory,PROM),可擦除只读存储器(Erasable Programmable Read-Only Memory,EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,EEPROM)等。
处理器130可以是一种集成电路芯片,具有信号处理的能力。上述的处理器也可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(DSP))、专用集成电路(ASIC)、现场可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
显示单元140用于建立电子设备100与用户之间的交互界面或用于展示待展示视图(view)。在本实施例中,视图可以理解为安卓(Android)系统中实例化的view对象,可以是图像、文本框等任意可在显示界面展示的信息。
所述显示单元140用于建立电子设备100与用户之间的交互界面,或用于显示待显示信息,例如,应用程序的用户界面。
应当理解,图1所示的结构仅为示意,电子设备100还可以具有比图1所示更多或更少的组件,也可以具有与图1所示不同的配置。需要说明的是,图1所示的各组件可以硬件、软件或其组合实现。
如图2所示,是本发明实施例提供的一种消息处理方法的流程示意图,所述消息处理方法应用于电子设备100中的应用程序,该应用程序可实现多个业务逻辑。下面将对图2所示的具体流程及步骤进行详细阐述。
步骤S110,基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息。
在本实施例中,所述应用程序可以是视频播放器。通常情况下,视频播放器可以包括如下多个业务逻辑:视频播放、控制条展示、礼物特效展示以及用户信息展示等。各个业务逻辑可通过相应的功能模块独立实现,在这一情形下,用于实现一个业务逻辑的功能模块属于一个层级。
在实际应用中,当各个业务逻辑执行某些操作后,可能需要对用户界面上展示的相应控件进行更新。例如,当控制条更新后,相应地也需要对用户界面上展示的控制条控件更新。也就意味着,某些层级需要通过异步消息处理对象异步地将操作执行结果以消息的形式发送给用户界面(User Interface,UI)主线程,以便对UI进行更新。
传统的做法是分别在需要异步处理消息的层级中实例化异步消息处理类得到对应的异步消息处理对象。但这种做法会导致一个应用程序可能实例化有多个异步消息处理对象,将会导致内存开销增大。
在本实施例中,所述异步消息处理类可以为Handler,相应地,异步消息处理对象或异步消息处理类的实例化对象是指Handler对象。
经发明人研究发现,虽然各层级需要通过自己的Handler对象异步处理消息,但同一应用程序中各层级所使用的Handler对象实际是相同的。若只实例化一个Handler对象,在各层级需要时获取该Handler对象进行使用,将能够极大地降低内存开销,提高开发效率。
因而,为解决上述问题,本发明对应用程序的设计架构做了改进。
详细地,构建有一抽象类,并将应用程序中的多个层级都需要实现的业务逻辑在所述抽象类声明和/或实现。该应用程序的各个业务逻辑对应的功能模块则作为继承于所述抽象类的实现类。例如,以上述视频播放器为例,用于实现视频播放的实现类继承于所述抽象类。
针对在多个层级中实现的功能完全一致的业务逻辑,可以直接在所述抽象类中实现。针对在多个层级中实现的功能有差别但差别较小的业务逻辑,可以在抽象类中声明为抽象方法,并在实现该业务逻辑的实现类中通过override指令复写和实现所述抽象方法。
可选地,如图3所示,在本实施例中,步骤S110可以包括步骤S111、步骤S112以及 步骤S113三个子步骤。
步骤S111,在所述抽象类中声明构造方法以及抽象的开关方法。
步骤S112,在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应。
在所述抽象类中声明的开关方法是抽象方法,也即,在抽象类中,所述开关方法只有方法名,没有方法主体。所述开关方法延迟到所述抽象类的子类中实现。在本实施例中,若某一业务逻辑需要异步处理消息,在该业务逻辑为目标业务逻辑,可以使所述目标业务逻辑的实现类继承于所述抽象类,并在所述目标业务逻辑的实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应。
例如,若所述目标业务逻辑需要异步处理消息,则将所述开关方法的返回值设置为true,若所述目标业务逻辑不需要异步处理消息,则将所述开关方法的返回值设置为false。
可选地,在本实施例中,所述开关方法可以通过override指令重写。
步骤S113,在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
构造方法是对象创建的固有方法,抽象类的实现类在被实例化的时候构造方法会被自动调用。在本实施例中,所述构造方法在抽象类中声明并实现。也就是说,抽象类中的构造方法具有方法主体。
可选地,在本实施例中,可以在所述构造方法中调用所述开关方法,针对目标业务逻辑而言,所述开关方法已经在目标业务逻辑的实现类中被重写,因而,构造方法实际执行的是重写后的开关方法。
实施时,电子设备100可根据开关方法的返回值确定目标业务逻辑是否需要异步处理消息。依照上述示例,若所述开关方法的返回值为true,则电子设备100确定目标业务逻辑需要异步处理消息,若所述开关方法的返回值为false,则电子设备100确定目标业务逻辑不需要异步处理消息。
步骤S120,在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息处理类,若未实例化,则实例化所述异步消息处理类。
以异步消息处理类为Handler为例,实施时,若电子设备100基于开关方法的返回值 确定目标业务逻辑需要异步处理消息,则进一步判断抽象类中是否已经有Handler对象,在抽象类中没有Handler对象的情况下,再实例化Handler得到一Handler对象。如此,可以保证抽象类中只有一个Handler对象,从而降低内存开销。
步骤S130,在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
实施时,在目标业务逻辑的实现类中获取抽象类中的Handler对象并通过该Handler对象对消息进行异步处理,而不必再重新实例化一个Handler对象。相当于在需要时可以直接将抽象类中的Handler对象拿过来使用。
可选地,在执行步骤S120中判断所述抽象类中是否实例化有异步消息类的步骤之前,所述方法还可以包括如下步骤:
在所述抽象类中声明对象获取方法,所述对象获取方法用户获取所述异步消息处理类的实例化对象并返回。
以上述Handler对象为例,所述对象获取方法可以是getDefaultHandler()。如此,若抽象类中实例化有Handler对象,则方法getDefaultHandler()会返回一个Handler对象。相应地,当所述开关方法的返回值为false时,电子设备100不会对Handler进行实例化,方法getDefaultHandler()会返回一个空对象。
可选地,在所述抽象类中声明有所述对象获取方法的基础上,步骤S120中的判断所述抽象类中是否实例化有异步消息处理类的步骤,可通过如下子步骤实现:
获取所述对象获取方法的返回值,并在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
进一步地,所述步骤S130可以通过如下步骤实现:
在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象。通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
作为一种实施方式,可以在目标业务逻辑的实现类中调用抽象类中的对象获取方法,以获取抽象类中的Handler对象,以使目标业务逻辑所在层级可通过该Handler对象进行异步消息处理。
如图4所示,本发明实施例还提供一种消息处理装置110,所述消息处理装置110应 用于电子设备100中的应用程序,该应用程序可实现多个业务逻辑。所述消息处理装置110包括判断模块111、实例化模块112以及处理模块113。
所述判断模块111被配置成基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息。
其中,所述实现类继承于所述抽象类。在本实施例中,关于所述判断模块111的描述具体可参考对图2所示步骤S110的详细描述,也即,所述步骤S110可以由所述判断模块111执行。
可选地,所述判断模块111基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式可以包括:
在所述抽象类中声明构造方法以及抽象的开关方法。在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应。在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
所述实例化模块112被配置成在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息处理类,若未实例化,则实例化所述异步消息处理类。
其中,所述异步消息处理类可以是Handler。在本实施例中,关于所述实例化模块112的描述具体可参考对图2所示步骤S120的详细描述,也即,所述步骤S120可以由所述实例化模块112执行。
所述处理模块113被配置成在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
在本实施例中,关于所述处理模块113的描述具体可参考对图2所示步骤S130的详细描述,也即,所述步骤S130可以由所述处理模块113执行。
可选地,如图5所示,所述消息处理装置110还可以包括对象获取模块114。
所述对象获取模块114被配置成在判断所述抽象类中是否实例化有异步消息处理类之前,在所述抽象类中声明对象获取方法,所述对象获取方法用于获取所述异步消息处理类的实例化对象并返回。
在本实施例中,关于所述对象获取模块114的描述具体可参考对上述内容中相关步骤 的详细描述。
进一步地,在所述消息处理装置110包括对象获取模块114的情况下,所述判断模块111可以包括获取子模块和确定子模块1112。
其中,所述获取子模块被配置成获取所述对象获取方法的返回值。
在本实施例中,关于所述获取子模块的描述具体可参考对上述内容中相关步骤的描述。
所述确定子模块1112被配置成在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
在本实施例中,关于所述确定子模块1112的描述具体可参考对上述内容中相关步骤的描述。
进一步地,在所述消息处理装置110包括对象获取模块114的情况下,所述处理模块113可以包括第二获取子模块1131和处理子模块1132。
其中,所述第二获取子模块1131被配置成在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象。
在本实施例中,关于所述第二获取子模块1131的描述具体可参考对上述内容中相关步骤的详细描述。
处理子模块1132,被配置成通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
在本实施例中,关于所述处理子模块1132的描述具体可参考对上述内容中相关步骤的详细描述。
本发明实施例还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被执行时实现本发明实施例提供的消息处理方法。
综上所述,本发明实施例提供的消息处理方法、装置及电子设备100,在抽象类中判断目标业务逻辑是否需要异步处理消息,在需要且抽象类中未实例化有异步消息处理类的情况下实例化异步消息处理类,并在该目标业务逻辑的实现类中调用异步消息处理类的实例化对象,以实现消息的异步处理。如此,可以仅在抽象类中实例化异步消息处理类,应用程序中的各业务逻辑在需要异步处理消息时调用该异步消息处理类的实例化对象即可实现消息的异步处理,大大降低了内存开销,提高了开发效率。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本发明的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
另外,在本发明各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。
所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应所述以权利要求的保护范围为准。
工业实用性
本发明实施例提供的消息处理方法、装置、电子设备及计算机可读存储介质,在抽象类中判断目标业务逻辑是否需要异步处理消息可以仅在抽象类中实例化异步消息处理类,应用程序中的各业务逻辑在需要异步处理消息时调用该异步消息处理类的实例化对象即可实现消息的异步处理,大大降低了内存开销,提高了开发效率。

Claims (18)

  1. 一种消息处理方法,其特征在于,应用于实现多个业务逻辑的应用程序,所述方法包括:
    基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息,所述实现类继承于所述抽象类;
    在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息处理类,若未实例化,则实例化所述异步消息处理类;
    在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
  2. 根据权利要求1所述的方法,其特征在于,基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的步骤,包括:
    在所述抽象类中声明构造方法以及抽象的开关方法;
    在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应;
    在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
  3. 根据权利要求2所述的方法,其特征在于,抽象的所述开关方法仅包括方法名,所述开关方法延迟到所述抽象类的子类中实现。
  4. 根据权利要求3所述的方法,其特征在于,在所述实现类中重写并实现所述开关方法之前还包括:使所述目标业务逻辑的实现类继承于所述抽象类,其中,所述目标业务逻辑为需要异步处理消息的业务逻辑。
  5. 根据权利要求2所述的方法,其特征在于,在判断所述抽象类中是否实例化有异步消息处理类的步骤之前,所述方法还包括:在所述抽象类中声明对象获取方法,所述对象获取方法用于获取所述异步消息处理类的实例化对象并返回。
  6. 根据权利要求2-5任一项所述的方法,其特征在于,判断所述抽象类中是否实例化有异步消息处理类的步骤,包括:
    获取对象获取方法的返回值;
    在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
  7. 根据权利要求6所述的方法,其特征在于,在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理的步骤,包括:
    在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象;
    通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
  8. 根据权利要求7所述的方法,其特征在于,在所述实现类中调用所述对象获取方法的步骤包括:
    在所述目标业务逻辑的实现类中调用抽象类中的对象获取方法,以获取抽象类中的异步消息处理类的实例化对象。
  9. 一种消息处理装置,其特征在于,应用于实现多个业务逻辑的应用程序,所述装置包括:
    判断模块,被配置成基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息,所述实现类继承于所述抽象类;
    实例化模块,被配置成在所述目标业务逻辑需要异步处理消息时,判断所述抽象类中是否实例化有异步消息处理类,若未实例化,则实例化所述异步消息处理类;
    处理模块,被配置成在所述实现类中调用所述异步消息处理类的实例化对象,对所述目标业务逻辑的消息进行处理。
  10. 根据权利要求9所述的装置,其特征在于,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,包括:
    在所述抽象类中声明构造方法以及抽象的开关方法;
    在所述实现类中重写并实现所述开关方法,使所述开关方法的返回值与所述目标业务逻辑是否需要异步处理消息相对应;
    在所述构造方法中调用所述开关方法,并基于所述开关方法的返回值确定所述目标业务逻辑是否需要异步处理消息。
  11. 根据权利要求10所述的装置,其特征在于,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,还包括:
    抽象的所述开关方法仅包括方法名,所述开关方法延迟到所述抽象类的子类中实现。
  12. 根据权利要求11所述的装置,其特征在于,所述判断模块基于设置在目标业务逻辑的实现类中的判断条件,在抽象类中判断所述目标业务逻辑是否需要异步处理消息的方式,还包括:
    在所述实现类中重写并实现所述开关方法之前还包括:使所述目标业务逻辑的实现类继承于所述抽象类,其中,所述目标业务逻辑为需要异步处理消息的业务逻辑。
  13. 根据权利要求9-12任一项所述的装置,其特征在于,所述装置还包括:
    对象获取模块,被配置成在判断所述抽象类中是否实例化有异步消息处理类之前,在所述抽象类中声明所述对象获取方法。
  14. 根据权利要求10-12任一项所述的装置,其特征在于,所述判断模块,包括:
    第一获取子模块,被配置成获取对象获取方法的返回值,所述对象获取方法用于获取所述异步消息处理类的实例化对象并返回;
    确定子模块,被配置成在所述对象获取方法的返回值不为空时,确定所述抽象类中未实例化异步消息处理类。
  15. 根据权利要求14所述的装置,其特征在于,所述处理模块包括:
    第二获取子模块,被配置成在所述实现类中调用所述对象获取方法,获取所述异步消息处理类的实例化对象;
    处理子模块,被配置成通过获取到的实例化对象对所述目标业务逻辑的消息进行处理。
  16. 根据权利要求15所述的装置,其特征在于,所述第二获取子模块被配置成在所述实现类中调用所述对象获取方法,以获取抽象类中的异步消息处理类的实例化对象。
  17. 一种电子设备,其特征在于,包括存储器、处理器以及存储在所述存储器中并在所述处理器中被执行的计算机程序,所述计算机程序被执行时实现权利要求1-8任一项所述的方法。
  18. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被执行时实现权利要求1-8任一项所述的方法。
PCT/CN2017/109572 2017-08-01 2017-11-06 消息处理方法、装置、电子设备及计算机可读存储介质 WO2019024305A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710648064.6A CN107463380B (zh) 2017-08-01 2017-08-01 消息处理方法、装置及电子设备
CN201710648064.6 2017-08-01

Publications (1)

Publication Number Publication Date
WO2019024305A1 true WO2019024305A1 (zh) 2019-02-07

Family

ID=60548056

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/109572 WO2019024305A1 (zh) 2017-08-01 2017-11-06 消息处理方法、装置、电子设备及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN107463380B (zh)
WO (1) WO2019024305A1 (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228168A (zh) * 2017-12-29 2018-06-29 安徽方正医疗信息技术有限公司 一种撤销、恢复操作的抽象方法
CN110018890B (zh) * 2018-01-10 2021-07-30 武汉斗鱼网络科技有限公司 一种线程间的交互方法、电子设备及可读存储介质
CN109246177B (zh) * 2018-07-04 2021-04-27 武汉斗鱼网络科技有限公司 Android中异步通信工具设计方法
CN109298853A (zh) * 2018-09-10 2019-02-01 武汉斗鱼网络科技有限公司 一种消息处理方法、装置、电子设备及存储介质
CN111400058A (zh) * 2020-03-06 2020-07-10 中国平安人寿保险股份有限公司 调用消息的方法、装置、计算机设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6012081A (en) * 1996-07-03 2000-01-04 Siemens Aktiengesellschaft Service and event synchronous/asynchronous manager
CN102455933A (zh) * 2010-10-22 2012-05-16 深圳市科陆电子科技股份有限公司 一种通过线程管理提高多任务处理效率的方法
US20120222022A1 (en) * 2006-10-23 2012-08-30 International Business Machines Corporation Instantiating an Interface or Abstract Class in Application Code
CN105468407A (zh) * 2015-11-19 2016-04-06 国云科技股份有限公司 一种自动发现并按序运行启动类的方法

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5822585A (en) * 1995-02-21 1998-10-13 Compuware Corporation System and method for cooperative processing using object-oriented framework
US6918107B2 (en) * 2001-07-02 2005-07-12 Bea Systems, Inc. Programming language extensions for processing data representation language objects and related applications
CN100498717C (zh) * 2004-08-20 2009-06-10 华为技术有限公司 一种对企业级Java组件的方法进行调用的方法
CN100492302C (zh) * 2006-11-27 2009-05-27 浙江大学 基于Java的进程间异步通信的实现方法
CN101770394B (zh) * 2008-12-29 2012-10-03 上海科泰世纪科技有限公司 基于构件接口的异步调用方法
US9128702B2 (en) * 2012-03-23 2015-09-08 Google Inc. Asynchronous message passing
CN102970353B (zh) * 2012-11-08 2015-04-08 大唐软件技术股份有限公司 一种业务数据处理的方法及系统
CN104407917B (zh) * 2014-11-13 2018-10-16 中国建设银行股份有限公司 一种基于jms的交易处理方法及装置
CN105430070B (zh) * 2015-11-10 2019-01-25 中国建设银行股份有限公司 消息发送方式及装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6012081A (en) * 1996-07-03 2000-01-04 Siemens Aktiengesellschaft Service and event synchronous/asynchronous manager
US20120222022A1 (en) * 2006-10-23 2012-08-30 International Business Machines Corporation Instantiating an Interface or Abstract Class in Application Code
CN102455933A (zh) * 2010-10-22 2012-05-16 深圳市科陆电子科技股份有限公司 一种通过线程管理提高多任务处理效率的方法
CN105468407A (zh) * 2015-11-19 2016-04-06 国云科技股份有限公司 一种自动发现并按序运行启动类的方法

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
SMILYYY, ANDROID ASYNCTASK, 25 July 2016 (2016-07-25), Retrieved from the Internet <URL:https://blog.csdn.net/qq_20521573/article/details/52021204> *

Also Published As

Publication number Publication date
CN107463380B (zh) 2018-07-06
CN107463380A (zh) 2017-12-12

Similar Documents

Publication Publication Date Title
WO2019024305A1 (zh) 消息处理方法、装置、电子设备及计算机可读存储介质
US11231959B2 (en) Foreground and background switching entry generation and display following quit operations
US8468514B2 (en) System and method for updating unified extensible firmware interface setting information
CN108376094B (zh) 通知消息显示方法、装置、计算机设备和存储介质
US10416994B2 (en) Control method
US8504501B2 (en) Dynamic constraint satisfaction problem solver
US10621062B2 (en) Widget provisioning of user experience analytics and user interface / application management
US20170168653A1 (en) Context-driven, proactive adaptation of user interfaces with rules
US10908948B2 (en) Multiple application instances in operating systems that utilize a single process for application execution
US9558014B2 (en) System, method and apparatus for transparently enabling software applications with adaptive user interfaces
US11381655B2 (en) Server-driven notifications to mobile applications
US10972346B2 (en) Customizable event processing for third party infrastructure events
CN107562540B (zh) 向ui线程投递回调函数的方法、装置及客户端
CN113127050A (zh) 一种应用资源打包过程监控方法、装置、设备和介质
US9037994B2 (en) Navigation to a data definition in a diff context
CN103019840A (zh) 用于设置桌面的方法和装置
US10503572B2 (en) Hybrid remote controller
US20210337061A1 (en) Method, device for processing message in screen locked interface and electronic device
CN113254133A (zh) iOS多场景便利弹窗工具、装置、计算机设备及存储介质
CN110045997B (zh) 基础功能模块的对象初始化方法、装置、设备和存储介质
US20140282128A1 (en) System and Method for a User Interface Controller for Mandatory and Shared User Interface Functions
CN110442404A (zh) 一种对象释放方法、装置、设备和存储介质
CN117519875A (zh) 弹窗处理方法、装置、设备及介质
CN113342413B (zh) 用于处理组件的方法、装置、设备、介质和产品
CN115345584A (zh) 一种基于项目自定义设置标签的方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17920496

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17920496

Country of ref document: EP

Kind code of ref document: A1