[go: up one dir, main page]

CN113918242B - Application programming interface calling method, device, electronic device and storage medium - Google Patents

Application programming interface calling method, device, electronic device and storage medium Download PDF

Info

Publication number
CN113918242B
CN113918242B CN202011324427.9A CN202011324427A CN113918242B CN 113918242 B CN113918242 B CN 113918242B CN 202011324427 A CN202011324427 A CN 202011324427A CN 113918242 B CN113918242 B CN 113918242B
Authority
CN
China
Prior art keywords
calling
call
application programming
programming interface
asynchronous
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011324427.9A
Other languages
Chinese (zh)
Other versions
CN113918242A (en
Inventor
孙彦旭
樊宁
姚博勋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jingdong Technology Holding Co Ltd
Original Assignee
Jingdong Technology Holding Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Holding Co Ltd filed Critical Jingdong Technology Holding Co Ltd
Priority to CN202011324427.9A priority Critical patent/CN113918242B/en
Publication of CN113918242A publication Critical patent/CN113918242A/en
Application granted granted Critical
Publication of CN113918242B publication Critical patent/CN113918242B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本公开提供了一种应用程序编程接口调用方法、装置、电子设备和存储介质,涉及计算机技术领域。其中,应用程序编程接口调用方法包括:接收非泛型异步调用请求;确定非泛型异步调用请求中用于调用的应用程序编程接口;根据非泛型异步调用请求,将响应监听进程封装至应用程序编程接口,以生成封装接口;在对封装接口调用前,创建封装接口的组合式异步调用任务;在组合式异步调用任务的调用过程中,封装组合式异步调用任务的调用结果,调用结果包括组合式异步调用任务的回调函数的返回值和/或异常结果。通过本公开的技术方案,解决了异步调用过程中的阻塞问题,兼容于任一异步调用框架,降低了异步调用过程中系统抖动的概率。

The present disclosure provides an application programming interface calling method, device, electronic device and storage medium, which relate to the field of computer technology. Among them, the application programming interface calling method includes: receiving a non-generic asynchronous call request; determining the application programming interface used for calling in the non-generic asynchronous call request; according to the non-generic asynchronous call request, encapsulating the response listening process into the application programming interface to generate an encapsulation interface; before calling the encapsulation interface, creating a combined asynchronous call task of the encapsulation interface; in the calling process of the combined asynchronous call task, encapsulating the calling result of the combined asynchronous call task, and the calling result includes the return value and/or abnormal result of the callback function of the combined asynchronous call task. Through the technical solution of the present disclosure, the blocking problem in the asynchronous calling process is solved, it is compatible with any asynchronous calling framework, and the probability of system jitter in the asynchronous calling process is reduced.

Description

Application programming interface calling method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, an electronic device, and a storage medium for calling an application programming interface.
Background
Jingdong Service Framework (JSF for short) is a new standard Java framework for building Web applications.
In the related art, when performing JSF asynchronous call, a call result needs to be monitored, and parameters in the call result are Java base classes, so that a user needs to manually convert the Java base classes into the types required by the next data stream.
In addition, in the JSF asynchronous call process, there may be a case that the call service is failed to be acquired, which causes the call thread to be suspended or blocked, typically, the first time the generic service is acquired is a blocking operation, and when the method is applied to responsive programming, the first time the generic asynchronous call interface causes serious jitter to the JSF system performance.
Finally, in the JSF asynchronous call process, since the asynchronous call process is divided into a plurality of sub-threads that are asynchronously executed, and the completion timing of each sub-thread is chaotic, the print log based on JSF asynchronous call is relatively complex and cumbersome.
It should be noted that the information disclosed in the above background section is only for enhancing understanding of the background of the present disclosure and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
The present disclosure aims to provide an application programming interface calling method, an apparatus, an electronic device and a storage medium, which at least overcome to some extent the problem of blocking during asynchronous calling in the related art.
Other features and advantages of the present disclosure will be apparent from the following detailed description, or may be learned in part by the practice of the disclosure.
According to one aspect of the disclosure, an application programming interface calling method is provided, and comprises the steps of receiving a non-generic asynchronous call request, determining an application programming interface for calling in the non-generic asynchronous call request, packaging a response monitoring process to the application programming interface according to the non-generic asynchronous call request to generate a packaged interface, creating a combined asynchronous call task of the packaged interface before calling the packaged interface, and packaging a calling result of the combined asynchronous call task in a calling process of the combined asynchronous call task, wherein the calling result comprises a return value and/or an abnormal result of a callback function of the combined asynchronous call task.
In one embodiment of the disclosure, encapsulating a response monitor process to an application programming interface according to a non-generic asynchronous call request to generate an encapsulation interface includes creating a response monitor process according to the non-generic asynchronous call request, saving the response monitor process to a call state recorder of the application programming interface, pre-storing classes of callback functions within a call thread of the application programming interface, and encapsulating the classes to the application programming interface to generate an encapsulation interface supporting lambda expressions.
In one embodiment of the disclosure, the application programming interface calling method further comprises the steps of obtaining calling request parameters in a non-generic asynchronous calling request through a filter of an application programming interface, storing the calling request parameters to a local thread variable, determining calling result parameters according to a calling result, associating the calling request parameters with the calling result parameters according to identification information of the calling request parameters and identification information of the calling result parameters, receiving log printing requests of the associated calling request parameters and the calling result parameters, and adding the log printing requests to a combined asynchronous calling task.
In one embodiment of the present disclosure, the application programming interface calling method further includes clearing call request parameters stored in the local thread variable if a completion log print request is detected.
According to one aspect of the disclosure, an application programming interface calling method is provided, and the method comprises the steps of receiving a generic asynchronous call request, determining an application programming interface used for calling in the generic asynchronous call request, requesting a cache area for obtaining generic services of the application programming interface, executing a generic call task according to the generic services, and packaging a call result of the generic call task into a combined asynchronous call task, wherein the call result comprises a return value and/or an abnormal result of a callback function of the combined asynchronous call task.
In one embodiment of the disclosure, requesting to obtain a generic service of an application programming interface from a cache region, and executing a generic call task according to the generic service includes requesting to obtain the generic service of the application programming interface from the cache region, judging whether to obtain the generic service, if so, determining a generic call function according to the generic service, and determining a return value of the generic call function as a call result, and if not, forwarding a request for obtaining the generic service to an asynchronous thread pool, and determining business logic initiating the generic asynchronous call request as a callback function for obtaining the generic service.
In one embodiment of the disclosure, the application programming interface call method further comprises determining parameter information of the generic asynchronous call request before the generic asynchronous call request is called, receiving a log print request of the parameter information, and adding the log print request to the combined asynchronous call task.
According to another aspect of the disclosure, an application programming interface calling device is provided, which comprises a receiving module, a determining module, a packaging module and a calling module, wherein the receiving module is used for receiving a non-generic asynchronous calling request, the determining module is used for determining an application programming interface used for calling in the non-generic asynchronous calling request, the packaging module is used for packaging a response monitoring process to the application programming interface according to the non-generic asynchronous calling request to generate a packaging interface, the calling module is used for creating a combined asynchronous calling task of the packaging interface before the packaging interface is called, and the packaging module is further used for packaging a calling result of the combined asynchronous calling task in a calling process of the combined asynchronous calling task, wherein the calling result comprises a return value and/or an abnormal result of a callback function of the combined asynchronous calling task.
According to another aspect of the disclosure, an application programming interface calling device is provided, which comprises a receiving module, a determining module, a calling module and a packaging module, wherein the receiving module is used for receiving a generic asynchronous call request, the determining module is used for determining an application programming interface used for calling in the generic asynchronous call request, the calling module is used for requesting a cache area to acquire generic services of the application programming interface and executing a generic call task according to the generic services, and the packaging module is used for packaging a call result of the generic call task into a combined asynchronous call task, and the call result comprises a return value and/or an abnormal result of a callback function of the combined asynchronous call task.
According to yet another aspect of the present disclosure, there is provided an electronic device comprising a processor, and a memory for storing executable instructions of the processor, wherein the processor is configured to perform the application programming interface invoking method of any of the above via execution of the executable instructions.
According to yet another aspect of the present disclosure, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the application programming interface invoking method of any of the above.
The application programming interface calling scheme provided by the embodiment of the disclosure solves the problem of blocking an asynchronous calling thread by encapsulating the calling result into a combined asynchronous calling task.
In addition, because the combined type asynchronous call task contains the information such as the asynchronous call request parameter, the class of the call method, the return value of the callback function and the like, the user does not need to perform type conversion on the return value, and the combined type asynchronous call task can be used for the subsequent data flow process.
And secondly, by packaging the application programming interface, the generation of redundant codes is reduced, and the difficulty of code maintenance is reduced.
It is worth particularly pointing out that by optimizing the call process of the generic service, the problem of blocking of the first call of the generic service is solved, the method is generally used for responsive programming scenes, and the jitter of system performance is reduced.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure. It will be apparent to those of ordinary skill in the art that the drawings in the following description are merely examples of the disclosure and that other drawings may be derived from them without undue effort.
FIG. 1 illustrates an architectural diagram of an application programming interface invocation scheme in an embodiment of the present disclosure;
FIG. 2 illustrates a flowchart of an application programming interface calling method in an embodiment of the present disclosure;
FIG. 3 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 4 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 5 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 6 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 7 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 8 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 9 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 10 illustrates a flowchart of another application programming interface invocation method in an embodiment of the present disclosure;
FIG. 11 illustrates a schematic diagram of an application programming interface calling device in an embodiment of the present disclosure;
FIG. 12 illustrates a schematic diagram of another application programming interface calling device in an embodiment of the present disclosure;
Fig. 13 shows a schematic diagram of an electronic device in an embodiment of the disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. However, the exemplary embodiments may be embodied in many forms and should not be construed as limited to the examples set forth herein, but rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Furthermore, the drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus a repetitive description thereof will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in software or in one or more hardware modules or integrated circuits or in different networks and/or processor devices and/or microcontroller devices.
According to the scheme provided by the application, the problem of blocking of an asynchronous calling thread is solved by encapsulating the calling result into the combined asynchronous calling task. In addition, because the combined type asynchronous call task contains the information such as the asynchronous call request parameter, the class of the call method, the return value of the callback function and the like, the user does not need to perform type conversion on the return value, and the combined type asynchronous call task can be used for the subsequent data flow process. And secondly, by packaging the application programming interface, the generation of redundant codes is reduced, and the difficulty of code maintenance is reduced. Finally, through optimizing the call process of the generic service, the problem of blocking of the first call of the generic service is solved, the method is generally used for responsive programming scenes, and the jitter of system performance is reduced.
The scheme provided by the embodiment of the application relates to the technologies of application programming interface calling and the like, and is specifically described through the following embodiments.
FIG. 1 illustrates a schematic diagram of an application programming interface call architecture in an embodiment of the present disclosure.
As shown in fig. 1, an application programming interface call architecture in an embodiment of the disclosure includes at least two servers, such as a first JAVA server 102 and a second JAVA server 104, and jsf is an RPC (Remote Procedure Call Protocol ) tool for micro-inter-service call.
(1) When an application on the first JAVA server 102 initiates a remote procedure call, the parameters of the method need to be transferred to the second JAVA server 104 via an underlying network protocol, such as, for example, binary-based, the values of the parameters in memory are serialized into binary form, i.e., serialized (Serialize) or marshaled (marshal), and the serialized binary is sent to the second JAVA server 104 via addressing and transmission.
(2) After receiving the call request, the second JAVA server 104 needs to deserialize the parameters (the reverse operation of serialization), restore the parameters to the expression mode in the memory, find the corresponding method (part of addressing) to perform local call, and then obtain the return value.
(3) The return value (service data) is also sent back to the application on the first JAVA server 102, and is also sent in a serialized manner, and after the first JAVA server 102 receives the return value, the return value is in reverse serialization, and is restored to the expression mode in the memory, and is handed to the application on the first JAVA server 102.
The steps of the application programming interface calling method in this exemplary embodiment will be described in more detail with reference to the accompanying drawings and examples.
FIG. 2 illustrates a flowchart of an application programming interface call method in an embodiment of the present disclosure. The method provided by the embodiments of the present disclosure may be performed by any electronic device having computing processing capabilities, such as a server or a terminal, but is not limited thereto. In the following illustration, an illustration is made with a terminal as an execution subject.
As shown in fig. 2, the terminal executes an application programming interface calling method, which includes the following steps:
Step S202, receiving a non-generic asynchronous call request.
Step S204, determining an application programming interface for calling in the non-generic asynchronous call request.
Step S206, according to the non-generic asynchronous call request, the response monitor process is encapsulated to the application programming interface to generate an encapsulated interface.
In the above embodiment, by encapsulating the response monitor process to the API (Application Program Interface, application programming interface), it is not necessary to create the response monitor process according to the non-generic asynchronous call request, and it is not necessary to perform cumbersome code maintenance on the response monitor process.
Step S208, before calling the encapsulation interface, creating a combined asynchronous call task of the encapsulation interface.
Step S210, packaging a calling result of the combined type asynchronous call task in the calling process of the combined type asynchronous call task, wherein the calling result comprises a return value and/or an abnormal result of a callback function of the combined type asynchronous call task.
In the above embodiment, the non-generic asynchronous call request may be considered as a normal asynchronous call request, the incoming call is a lambda expression of the remote call, and the outgoing call is the output of the combined asynchronous call task, so that the service system of the application programming interface does not need to pay attention to the internal logic of the asynchronous call process, and the response monitoring process and various exceptions are hidden.
Specifically, by encapsulating the call result of the combined asynchronous call task (CompletableFuture), in the above embodiment, the non-generic asynchronous call request may be considered as a normal asynchronous call request, the incoming is a lambda expression of the remote call, and the outgoing is the output of the combined asynchronous call task, so that the service system of the application programming interface does not need to pay attention to the internal logic of the asynchronous call process, and the response monitoring process and various exceptions are hidden. The actions provided for the dependent completion of the non-asynchronous method may be performed by the thread that completes the current CompletableFuture, or by any other caller that completes the method.
In addition, all asynchronous methods without explicit executor parameters are performed using "fork join pool. Common pool ()" unless it does not support at least two parallel levels, in which case a new Thread (Thread) is created to run each task. To simplify monitoring, debugging and tracking, all generated combined asynchronous call tasks are markup interfaces.
Based on the steps shown in fig. 2, as shown in fig. 3, encapsulating the response snoop process to the application programming interface according to the non-generic asynchronous call request to generate an encapsulated interface includes:
step S3062, a response monitoring process is created according to the non-generic asynchronous call request.
Step S3064, save the response listening process to the call state logger of the application programming interface.
Step S3066, pre-storing the class of the callback function in the calling thread of the application programming interface, and packaging the class to the application programming interface to generate a packaging interface supporting lambda expression.
In the above embodiment, the call state logger (RpcContext) is a temporary state logger of the local thread (ThreadLocal), and the state of RpcContext changes when an RPC request is received or initiated. For example, if the machine A is used for adjusting B and B is used for adjusting C again, then the machine B is used for adjusting B before adjusting C RpcContext, and the machine B is used for adjusting C after adjusting C RpcContext.
In addition, the class of the callback function is prestored in a calling thread of the application programming interface, and is packaged to the application programming interface to generate a packaging interface supporting lambda expressions, the packaging interface is mainly used for packaging the class of the calling method, and when the packaging interface performs universal asynchronous call, a general filter of the packaging interface extracts and stores parameters of the universal asynchronous call request, and a return value of the call result is obtained and correlated.
Based on the steps shown in fig. 2, as shown in fig. 4, the application programming interface calls a method, which further includes:
step S402, obtaining call request parameters in the non-generic asynchronous call request through a filter of the application programming interface, and storing the call request parameters to a local thread variable.
Step S404, determining a calling result parameter according to the calling result.
Step S406, according to the identification information of the calling request parameter and the identification information of the calling result parameter, the calling request parameter and the calling result parameter are associated.
Step S408, a log print request of the associated call request parameter and call result parameter is received, and the log print request is added to the combined asynchronous call task.
In the related art, for single-thread synchronous call processing, a printed log is easy to understand through a thread context, and the log is checked according to the thread name and the log time when the problem is solved. However, the log of asynchronous requests cannot be simply processed in this way, and a large task is divided into N sub-tasks to be processed asynchronously and in parallel, the execution sequence of each sub-task is out of order, and the sub-tasks of the same type are also executed out of order.
In the above embodiment, for a common asynchronous call, the log printing is complex, the method name and parameters of the request are obtained according to the following principle, the original JSF request is intercepted by using a custom Filter, a function for extracting the parameters of the call request after ResponseListener is created, the function is stored in a ThreadLocal (local thread) variable in the Filter, and the function in the ThreadLocal in the Filter is obtained and executed.
Based on the steps shown in fig. 2, as shown in fig. 5, the application programming interface calling method further includes:
step S502, if the log printing request is detected to be completed, the calling request parameters stored in the local thread variable are cleared.
In the above embodiment, according to the call request parameter extracted before the asynchronous call and the relevant parameter of the request is saved, the thread is emptied after the execution is completed, so that the next thread is convenient to use.
FIG. 6 illustrates a flowchart of an application programming interface call method in an embodiment of the present disclosure. The method provided by the embodiments of the present disclosure may be performed by any electronic device having computing processing capabilities, such as a server or a terminal, but is not limited thereto. In the following illustration, an illustration is made with a terminal as an execution subject.
As shown in fig. 6, there is provided an application programming interface calling method, including:
step S602, a response listening process is created.
Step S604, save the response listening process to the call state logger.
Step S606, a RemoteService. Xxx () service, namely a JSF universal filter, storing request data into a response monitoring process, wherein the request data can be used for log printing, and sending a JSF asynchronous call request.
In step S608, the asynchronous call request is sent to end.
In the above embodiment, "remoteservice. Xxx ()" is an instance of a remote service function, encapsulated in an API interface, supporting lambda expressions, which is more convenient to combine with other asynchronous frameworks, and the whole call flow has no blocking operation, so that it is completely suitable for responsive programming.
For example, based on the technical solution of the present disclosure, a callback function for obtaining 200 non-generic asynchronous calls of member services is initiated to the encapsulation interface, but executing the non-generic asynchronous call does not generate a return value due to an exception, and then the exception result is determined as a call result and written to completablefuture. When the next non-generic asynchronous call to get a membership service is initiated, the thread of the callback function is initialized.
FIG. 7 illustrates a flowchart of an application programming interface call method in an embodiment of the present disclosure. The method provided by the embodiments of the present disclosure may be performed by any electronic device having computing processing capabilities, such as a server or a terminal, but is not limited thereto. In the following illustration, an illustration is made with a terminal as an execution subject.
As shown in fig. 7, there is provided an application programming interface calling method, including:
Step S702, a generic asynchronous call request is received.
Step S704, determining an application programming interface for calling in the generic asynchronous call request.
Step S706, requesting the cache area to obtain the generic service of the application programming interface, and executing the generic call task according to the generic service.
Step S708, packaging the call result of the generic call task into a combined asynchronous call task, wherein the call result comprises the return value and/or the abnormal result of the callback function of the combined asynchronous call task.
In the above embodiment, GENERICSERVICE (for example, although 10 methods are provided, ten methods are not written in the interface, and function declarations and parameter declarations are not required to be made for the ten methods) are obtained from the cache, if the result is obtained, a generic asynchronous call is directly initiated, and if the result is not obtained, the obtaining operation of the generic asynchronous call request is submitted to the asynchronous thread pool for processing, and the business logic for initiating the generic asynchronous call request is processed as a callback function for obtaining GENERICSERVICE.
Based on the steps shown in fig. 7, as shown in fig. 8, requesting to obtain a generic service of an application programming interface from a cache area, and executing a generic call task according to the generic service includes:
step S8062, requesting the cache area for obtaining the generic service of the application programming interface, judging whether the generic service is obtained, if yes, executing step S8064, and if not, executing step S8066.
In step S8064, if it is determined that the generic service is acquired, a generic call function is determined according to the generic service, and a return value of the generic call function is determined as a call result.
Step S8066, if it is determined that the generic service is not acquired, forwarding the request for acquiring the generic service to an asynchronous thread pool, and determining the business logic for initiating the generic asynchronous call request as a callback function for acquiring the generic service.
In the above embodiment, when the generic service is initiated, the interface name, the call request parameter and the class of the call method are set to provide asynchronous call services, such as member service and account service, in order to solve the blocking problem of the generic asynchronous call, the call result is encapsulated to completablefuture, if the callback method returns the result, the return value is encapsulated to completablefuture, and if the callback method does not return the result, the call method is encapsulated to completablefuture.
Based on the steps shown in fig. 7, as shown in fig. 9, the application programming interface calling method further includes:
Step S902, before the generic asynchronous call request is called, determining parameter information of the generic asynchronous call request.
Step S904, a log print request of the parameter information is received, and the log print request is added to the combined asynchronous call task.
In the above embodiment, the request interface name, the parameter list and the request parameter can be directly taken before the generic asynchronous call, so that the request interface name, the parameter list and the request parameter can be directly printed, the call result is packaged into CompletableFuture, and the response log printing is directly added in CompletableFuture, thereby simplifying the log printing step of the generic asynchronous call.
FIG. 10 illustrates a flowchart of an application programming interface call method in an embodiment of the present disclosure. The method provided by the embodiments of the present disclosure may be performed by any electronic device having computing processing capabilities, such as a server or a terminal, but is not limited thereto. In the following illustration, an illustration is made with a terminal as an execution subject.
As shown in fig. 10, there is provided an application programming interface calling method, including:
Step S1002, the generic service is acquired asynchronously.
And step S1004, initiating JSF asynchronous call in a callback function of the generic service.
In the above embodiment, GENERICSERVICE (for example, although 10 methods are provided, ten methods are not written in the interface, and function declarations and parameter declarations are not required to be made for the ten methods) are obtained from the cache, if the result is obtained, a generic asynchronous call is directly initiated, and if the result is not obtained, the obtaining operation of the generic asynchronous call request is submitted to the asynchronous thread pool for processing, and the business logic for initiating the generic asynchronous call request is processed as a callback function for obtaining GENERICSERVICE.
An application programming interface calling apparatus 1100 according to this embodiment of the present invention is described below with reference to fig. 11. The application programming interface invoking device 1100 illustrated in FIG. 11 is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
The application programming interface calling device 1100 is embodied in the form of a hardware module. The components of the application programming interface invoking apparatus 1100 may include, but are not limited to, a receiving module 1102, a determining module 1104, an encapsulating module 1106, and an invoking module 1108.
The receiving module 1102 is configured to receive a non-generic asynchronous call request.
The determination module 1104 is used to determine an application programming interface for a call in a non-generic asynchronous call request.
The encapsulation module 1106 is configured to encapsulate the response monitor process to the application programming interface according to the non-generic asynchronous call request, so as to generate an encapsulation interface.
A calling module 1108 is configured to create a combined asynchronous call task of the encapsulation interface before calling the encapsulation interface.
The encapsulation module 1106 is further configured to encapsulate, during a call of the combined asynchronous call task, a call result of the combined asynchronous call task, where the call result includes a return value and/or an exception result of a callback function of the combined asynchronous call task.
An application programming interface calling apparatus 1200 according to this embodiment of the present invention is described below with reference to fig. 12. The application programming interface invoking device 1200 shown in fig. 12 is merely an example, and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
The application programming interface calling device 1200 is embodied in the form of a hardware module. The components of the application programming interface invoking apparatus 1200 may include, but are not limited to, a receiving module 1202, a determining module 1204, an invoking module 1206, and an encapsulating module 1208.
The receiving module 1202 is configured to receive a generic asynchronous call request.
The determining module 1204 is configured to determine an application programming interface for calling in the generic asynchronous call request.
The calling module 1206 is configured to request to the cache area to obtain a generic service of the application programming interface, and execute a generic calling task according to the generic service.
The encapsulation module 1208 is configured to encapsulate a call result of the generic call task to a combined asynchronous call task, where the call result includes a return value and/or an exception result of a callback function of the combined asynchronous call task.
An electronic device 1300 according to this embodiment of the invention is described below with reference to fig. 13. The electronic device 1300 shown in fig. 13 is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 13, the electronic device 1300 is embodied in the form of a general purpose computing device. The components of the electronic device 1300 may include, but are not limited to, at least one processing unit 1310 as described above, at least one memory unit 1320 as described above, and a bus 1330 that connects the different system components (including the memory unit 1320 and the processing unit 1310).
Wherein the storage unit stores program code that is executable by the processing unit 1310 such that the processing unit 1310 performs steps according to various exemplary embodiments of the present invention described in the above section of the "exemplary method" of the present specification. For example, the processing unit 1310 may perform the steps of the application programming interface calling method described above.
The storage unit 1320 may include readable media in the form of volatile storage units, such as Random Access Memory (RAM) 13201 and/or cache memory 13202, and may further include Read Only Memory (ROM) 13203.
The storage unit 1320 may also include a program/utility 13204 having a set (at least one) of program modules 13205, such program modules 13205 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment.
Bus 1330 may be a local bus representing one or more of several types of bus structures including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or using any of a variety of bus architectures.
The electronic device 1300 may also communicate with one or more external devices 1340 (e.g., keyboard, pointing device, bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device, and/or any device (e.g., router, modem, etc.) that enables the electronic device 1300 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 1350. Also, the electronic device 1300 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, for example, the Internet, through a network adapter 1360. The network adapter 1360 communicates with other modules of the electronic device 1300 over the bus 1330. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with the electronic device, including, but not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware. Thus, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disk, a mobile hard disk, etc.) or on a network, including several instructions to cause a computing device (may be a personal computer, a server, a terminal device, or a network device, etc.) to perform the method according to the embodiments of the present disclosure.
In an exemplary embodiment of the present disclosure, a computer-readable storage medium having stored thereon a program product capable of implementing the method described above in the present specification is also provided. In some possible embodiments, the aspects of the invention may also be implemented in the form of a program product comprising program code for causing a terminal device to carry out the steps according to the various exemplary embodiments of the invention as described in the "exemplary method" section of this specification, when the program product is run on the terminal device.
A program product for implementing the above-described method according to an embodiment of the present invention may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a data signal propagated in baseband or as part of a carrier wave with readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
It should be noted that although in the above detailed description several modules or units of a device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit in accordance with embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
Furthermore, although the steps of the methods in the present disclosure are depicted in a particular order in the drawings, this does not require or imply that the steps must be performed in that particular order, or that all illustrated steps be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step to perform, and/or one step decomposed into multiple steps to perform, etc.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware. Thus, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disk, a mobile hard disk, etc.) or on a network, including several instructions to cause a computing device (may be a personal computer, a server, a mobile terminal, or a network device, etc.) to perform the method according to the embodiments of the present disclosure.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any adaptations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

Claims (6)

1.一种应用程序编程接口调用方法,其特征在于,包括:1. An application programming interface calling method, characterized by comprising: 接收非泛型异步调用请求;Receive non-generic asynchronous call requests; 确定所述非泛型异步调用请求中用于调用的应用程序编程接口;Determine an application programming interface for invoking in the non-generic asynchronous call request; 根据所述非泛型异步调用请求,将响应监听进程封装至所述应用程序编程接口,以生成封装接口;According to the non-generic asynchronous call request, encapsulating the response listening process into the application programming interface to generate an encapsulation interface; 在对所述封装接口调用前,创建所述封装接口的组合式异步调用任务;Before calling the encapsulation interface, creating a combined asynchronous calling task of the encapsulation interface; 在所述组合式异步调用任务的调用过程中,封装所述组合式异步调用任务的调用结果,所述调用结果包括所述组合式异步调用任务的回调函数的返回值和/或异常结果;In the calling process of the combined asynchronous calling task, encapsulating the calling result of the combined asynchronous calling task, the calling result includes the return value and/or abnormal result of the callback function of the combined asynchronous calling task; 通过所述应用程序编程接口的过滤器获取所述非泛型异步调用请求中的调用请求参数,并将所述调用请求参数保存至本地线程变量;Acquire the call request parameters in the non-generic asynchronous call request through the filter of the application programming interface, and save the call request parameters to the local thread variable; 根据所述调用结果确定调用结果参数;Determine a call result parameter according to the call result; 根据所述调用请求参数的标识信息和所述调用结果参数的标识信息,关联所述调用请求参数和所述调用结果参数;Associating the call request parameter with the call result parameter according to the identification information of the call request parameter and the identification information of the call result parameter; 接收关联的所述调用请求参数和所述调用结果参数的日志打印请求,并将所述日志打印请求添加至所述组合式异步调用任务。A log printing request associated with the call request parameter and the call result parameter is received, and the log printing request is added to the combined asynchronous call task. 2.根据权利要求1所述的应用程序编程接口调用方法,其特征在于,根据所述非泛型异步调用请求,将响应监听进程封装至所述应用程序编程接口,以生成封装接口包括:2. The method for calling an application programming interface according to claim 1, wherein encapsulating the response monitoring process into the application programming interface to generate an encapsulated interface comprises: 根据所述非泛型异步调用请求创建所述响应监听进程;Creating the response listening process according to the non-generic asynchronous call request; 将所述响应监听进程保存至所述应用程序编程接口的调用状态记录器;Saving the response monitoring process to a call status recorder of the application programming interface; 在所述应用程序编程接口的调用线程内部预存所述回调函数的类,并将所述类封装至所述应用程序编程接口,以生成支持lambda表达式的封装接口。The class of the callback function is pre-stored inside the calling thread of the application programming interface, and the class is encapsulated into the application programming interface to generate an encapsulation interface supporting lambda expressions. 3.根据权利要求1所述的应用程序编程接口调用方法,其特征在于,还包括:3. The method for calling an application programming interface according to claim 1, further comprising: 若检测到完成所述日志打印请求,则清空所述本地线程变量中存储的调用请求参数。If it is detected that the log printing request is completed, the calling request parameter stored in the local thread variable is cleared. 4.一种应用程序编程接口调用装置,其特征在于,4. An application programming interface calling device, characterized in that: 接收模块,用于接收非泛型异步调用请求;A receiving module, used for receiving non-generic asynchronous call requests; 确定模块,用于确定所述非泛型异步调用请求中用于调用的应用程序编程接口;A determination module, used to determine an application programming interface for calling in the non-generic asynchronous call request; 封装模块,用于根据所述非泛型异步调用请求,将响应监听进程封装至所述应用程序编程接口,以生成封装接口;An encapsulation module, used for encapsulating the response monitoring process into the application programming interface according to the non-generic asynchronous call request to generate an encapsulation interface; 调用模块,用于在对所述封装接口调用前,创建所述封装接口的组合式异步调用任务;A calling module, used for creating a combined asynchronous calling task of the encapsulation interface before calling the encapsulation interface; 所述封装模块还用于,在所述组合式异步调用任务的调用过程中,封装所述组合式异步调用任务的调用结果,所述调用结果包括所述组合式异步调用任务的回调函数的返回值和/或异常结果;The encapsulation module is further used to encapsulate the calling result of the combined asynchronous calling task during the calling process of the combined asynchronous calling task, wherein the calling result includes the return value and/or abnormal result of the callback function of the combined asynchronous calling task; 通过所述应用程序编程接口的过滤器获取所述非泛型异步调用请求中的调用请求参数,并将所述调用请求参数保存至本地线程变量;Acquire the call request parameters in the non-generic asynchronous call request through the filter of the application programming interface, and save the call request parameters to the local thread variable; 根据所述调用结果确定调用结果参数;Determine a call result parameter according to the call result; 根据所述调用请求参数的标识信息和所述调用结果参数的标识信息,关联所述调用请求参数和所述调用结果参数;Associating the call request parameter with the call result parameter according to the identification information of the call request parameter and the identification information of the call result parameter; 接收关联的所述调用请求参数和所述调用结果参数的日志打印请求,并将所述日志打印请求添加至所述组合式异步调用任务。A log printing request associated with the call request parameter and the call result parameter is received, and the log printing request is added to the combined asynchronous call task. 5.一种电子设备,其特征在于,包括:5. An electronic device, comprising: 处理器;以及Processor; and 存储器,用于存储所述处理器的可执行指令;A memory, configured to store executable instructions of the processor; 其中,所述处理器配置为经由执行所述可执行指令来执行权利要求1-3中任一项所述的应用程序编程接口调用方法。The processor is configured to execute the application programming interface calling method according to any one of claims 1 to 3 by executing the executable instructions. 6.一种计算机可读存储介质,其上存储有计算机程序,其特征在于,6. A computer-readable storage medium having a computer program stored thereon, characterized in that: 所述计算机程序被处理器执行时实现权利要求1-3中任一项所述的应用程序编程接口调用方法。When the computer program is executed by a processor, the application programming interface calling method described in any one of claims 1 to 3 is implemented.
CN202011324427.9A 2020-11-23 2020-11-23 Application programming interface calling method, device, electronic device and storage medium Active CN113918242B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011324427.9A CN113918242B (en) 2020-11-23 2020-11-23 Application programming interface calling method, device, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011324427.9A CN113918242B (en) 2020-11-23 2020-11-23 Application programming interface calling method, device, electronic device and storage medium

Publications (2)

Publication Number Publication Date
CN113918242A CN113918242A (en) 2022-01-11
CN113918242B true CN113918242B (en) 2025-04-15

Family

ID=79231420

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011324427.9A Active CN113918242B (en) 2020-11-23 2020-11-23 Application programming interface calling method, device, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN113918242B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114595081A (en) * 2022-03-04 2022-06-07 中信银行股份有限公司 A responsive RPC calling method and system based on cache storage
CN118642695B (en) * 2024-08-15 2024-10-25 江西求是高等研究院 Lightweight single-thread asynchronous method and system based on development environment

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106161537B (en) * 2015-04-10 2019-12-13 阿里巴巴集团控股有限公司 Method, device and system for processing remote procedure call and electronic equipment
CN106371900B (en) * 2015-07-23 2020-06-05 腾讯科技(深圳)有限公司 Data processing method and device for realizing asynchronous call
CN107179951A (en) * 2016-03-09 2017-09-19 北京京东尚科信息技术有限公司 Remote procedure calling (PRC) method and device

Also Published As

Publication number Publication date
CN113918242A (en) 2022-01-11

Similar Documents

Publication Publication Date Title
CN104317591B (en) A kind of web interface frame system and web method for processing business based on OSGi
CN112035276B (en) Cross-platform extensible RPC framework design method based on java
US7877091B2 (en) Method and system for executing a container managed application on a processing device
CN109815025B (en) Service model calling method, device and storage medium
US11656902B2 (en) Distributed container image construction scheduling system and method
CN106293887A (en) Data base processing method and device
JPH0827775B2 (en) Method and system for calling processing procedure from remote node
CN111737022A (en) Interface calling method, system, equipment and medium based on micro-service
CN112306979B (en) Message queue-based log information processing method and device and readable medium
CN113918242B (en) Application programming interface calling method, device, electronic device and storage medium
CN111552568A (en) Cloud service calling method and device
CN110287267A (en) A cross-node data processing method and device
EP3872630B1 (en) Request processing method and apparatus, electronic device, and computer storage medium
CN112688915A (en) Cross-protocol communication method, device and server
CN111274047A (en) Information processing method, terminal, system, computer device and storage medium
CN111343239B (en) Communication request processing method, communication request processing device and transaction system
US12224897B2 (en) Active network node resilience pattern for cloud service
CN114860468A (en) SDK calling method and device, computer equipment and storage medium
CN108769249B (en) iOS high-performance high-expansion network device, implementation method, server and medium
CN117478590A (en) Message processing method and device, electronic equipment and storage medium
CN114003391B (en) Openresty-based computationally intensive application deployment method and system
CN114448703B (en) Request processing method, request processing device, electronic equipment and storage medium
CN116561013A (en) Test method, device, electronic equipment and medium based on target service framework
CN113342540B (en) Terminal user fee-paying starting method, system, computer equipment and storage medium
CN115484149A (en) Network switching method, network switching device, electronic device and storage medium

Legal Events

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