Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, and "a" and "an" generally include at least two, but do not exclude at least one, unless the context clearly dictates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
It should be understood that although the terms first, second, third, etc. may be used to describe XXX in embodiments of the present invention, these XXX should not be limited to these terms. These terms are only used to distinguish XXX from each other. For example, a first XXX may also be referred to as a second XXX, and similarly, a second XXX may also be referred to as a first XXX, without departing from the scope of embodiments of the present invention.
The words "if", as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a good or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such good or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a commodity or system that includes the element.
Fig. 1a is a schematic structural diagram of a first embodiment of a proxy-based data communication system according to an embodiment of the present invention, and as shown in fig. 1a, the system includes:
the control background 1, the terminal device 2, a plurality of applications 21 installed in the terminal device 2, and the agent 22 installed in the terminal device 2. In a robot application scenario, the terminal device 2 may be an electronic device installed in a robot.
The agent 22 stores a communication address of the control background 1, and the agent 22 is further configured to establish a communication connection with the control background 1 according to the communication address of the control background 1.
Specifically, the agent 22 is configured and then started, and sends a connection request to the control background 1 through a preset port by using a pre-stored communication address of the control background 1, and if the control background 1 receives the connection request through the preset port, the agent 22 establishes a communication connection.
Optionally, when more than one terminal device 2 is in the application scenario, the connection request may include the identifier of the terminal device 2 currently triggering the connection request and the communication address of the terminal device 2. The agent 22 stores in advance an identifier of the terminal device 2 in which it is installed and a communication address of the terminal device 2, where the identifier of the terminal device may be, for example, a motherboard number or the like, which is used to uniquely identify one terminal device, and the communication address may be, for example, an IP address of the terminal device, such as an internal network address or an external network address, port information, or the like. At this time, the control background 1 further adds communication connection information corresponding to the identifier of the terminal device 2 to the connection pool after establishing communication connection with the agent 22 according to the connection request.
Specifically, the control background 1 creates a connection pool after being started, and after receiving the connection request sent by the agent 22, determines whether the connection pool includes communication connection information corresponding to the connection pool or not according to the identifier of the terminal device 2 carried in the connection request, and if not, adds the identifier of the terminal device 2 and the communication address of the terminal device 2 in the current connection request to the connection pool in a key value manner, where the key is the identifier of the terminal device 2 and the value is the communication address of the terminal device 2.
Further, the agent 22 is provided with identifications of the plurality of applications 21, and the agent 22 is configured to establish communication connections with the plurality of applications 21 according to the identifications of the applications 21.
The agent 22 is configured in the terminal device 2, and the identifier preset in the agent 22 is added to the plurality of applications 21 that need to use the agent 22, so that the agent 22 establishes communication connection with the plurality of applications 21, and the identifier cannot be duplicated.
Also, a service interface set corresponding to a service set provided by the plurality of applications 21 is set in the agent 22.
The identifier of the application program may include an identifier characterizing one application program, and may further include an identifier characterizing a service provided by the application program, such as a service name.
It should be noted that the service interfaces in the service interface set do not necessarily have a one-to-one correspondence with the services in the service set provided by the plurality of application programs, for example, the service interfaces may have a one-to-many correspondence, at this time, the services in the service set may be abstracted in common, and if the processing logics of some services are consistent, the services correspond to the same service interface. In addition, optionally, the service interface set maintained by the control back-end 1 and the service interface set maintained by the agent 22 may not be completely consistent, because similarly, the control back-end 1 may further abstract commonalities for several service interfaces in the service interface set maintained by the agent 22, corresponding to one service interface on the control back-end side.
Specifically, a service interface set may be defined in advance in the agent 22, and a service interface in the service interface set is used for communication between the agent 22 and the corresponding application 21. For example, assuming that the service provided in the application a includes a service a and a service B, and the service provided in the application B includes a service c and a service d, service interfaces corresponding to the service a, the service B, the service c and the service d are predefined in the agent 22, so that when there is a data communication demand between the control background 1 and the service a in the application a, the agent 22 can transmit communication data to the service a through the service interface corresponding to the service a, and similarly, when the service a wants to transmit data to the control background 1, the data can be sent to the agent 22 based on the service interface corresponding to the service a, so that the agent 22 forwards the data to the control background 1.
Specifically, the process of establishing communication between the application 21 and the agent 22 may be, for example:
adding a fixed Service name to the Service of the application 21 that needs to use the agent 22;
after the Service of the application 21 is initialized, the Service interface defined by the Agent is realized, and after the realization is instantiated, the instantiated object is released through a reflection and dynamic proxy mechanism. When a certain service is triggered to generate a data communication demand, acquiring a corresponding service interface of an agent through an Intent mechanism of Android, and sending corresponding communication data; wherein, the terminal device 2 in which the application 21 and the agent 22 are installed is assumed to be based on the Android system;
the agent 22 starts initialization, registers a service name configured by the application 21 in the terminal device 2, acquires a corresponding service interface through the service name after starting, establishes a communication channel, and sends communication data to a corresponding service when a communication demand to the service exists.
Based on the above process, data communication between the control background 1 and the application 21 can be performed through the agent 22. For example, the control background 1 may send version-up information to a certain application 21 through the agent 22; an application 21 may send a version-up request, send running state information, etc. to the control daemon 1 via the agent 22.
In addition, because the number of the applications 21 using the agent 22 in the terminal device 2 is often multiple, and the control background 1 often has communication requirements with different applications under different conditions, based on the embodiment, no matter which application using the agent 22 the control background 1 needs to perform data communication with, the control background 1 is implemented through the agent 22, at this time, the control background 1 only needs to maintain one communication connection with the agent 22, and does not need to maintain the communication connection with each application by the control background 1, so that the maintenance cost of the communication connection of the control background 1 is reduced, that is, the number of the communication connection information in the connection pool of the control background 1 is greatly reduced.
In summary, the data communication system based on proxy provided in this embodiment includes: the system comprises a control background, a terminal device, a plurality of application programs and agents installed in the terminal device. The agent is provided with a plurality of application program identifiers so as to establish communication connection with the application programs according to the application program identifiers; and the agent stores the communication address of the control background so as to establish communication connection with the control background according to the communication address of the control background. In addition, a service interface set corresponding to a service set provided by a plurality of application programs in the terminal equipment is also arranged in the agent, and the control background can realize the service interface set, so that the timely data communication between the control background and the application programs in the terminal equipment can be realized through the agent based on the communication connection between the agent and the control background, the communication connection between the agent and the application programs and each service interface, and the control background can timely discover the abnormal condition of the terminal equipment to perform corresponding processing.
Fig. 1b is a signaling interaction diagram of a data communication method in the scenario of the system shown in fig. 1a, as shown in fig. 1b, including the following steps:
step 101, the agent sends heartbeat messages to the control background at preset time intervals, wherein the heartbeat messages comprise the identification of the terminal equipment.
And step 102, the control background responds to the heartbeat message and inquires whether the connection pool contains communication connection information corresponding to the identifier of the terminal equipment, if not, the communication connection information corresponding to the identifier of the terminal equipment is added into the connection pool, and if so, the updating time of the communication connection information is modified.
And 103, if the control background does not receive the heartbeat message sent by the agent within the preset time or receives an offline notification message sent by the agent, deleting the communication connection information in the connection pool.
In this embodiment, in order to ensure the reliability of the communication connection between the agent 22 and the control background 1, the agent 22 is further configured to send a heartbeat message to the control background 1 at a certain time interval in a cycle, so as to ensure the validity of the previous communication connection between the agent 22 and the control background 1.
Accordingly, the control background 1 is also configured to: after receiving the heartbeat message, inquiring whether the connection pool contains communication connection information corresponding to the identifier of the terminal device, if not, indicating that the communication connection between the agent 22 and the control background 1 is interrupted, at this moment, reestablishing the communication connection between the agent and the control background, and adding corresponding communication connection information into the connection pool; if so, modifying the updating time of the communication connection information to update the time when the communication connection information is detected as valid. If the control background 1 does not receive the heartbeat message sent by the agent 22 within the preset time or receives the offline notification message sent by the agent 22, it indicates that the communication connection between the two is interrupted, and deletes the corresponding communication connection information in the connection pool.
In this embodiment, based on the heartbeat mechanism, validity of communication connection between the agent and the control background can be ensured.
Fig. 1c is a signaling interaction diagram of another data communication method in the context of the system shown in fig. 1a, as shown in fig. 1c, including the following steps:
step 201, the control background receives a data communication request triggered by a user, where the data communication request includes an identifier of a terminal device, an application identifier, and a service interface identifier.
In an application scenario, it is assumed that the control back 1 needs to perform data communication with a certain application 21, and the triggering of the data communication requirement may be optionally triggered actively by a worker on the control back 1 side, i.e. the user.
When the user triggers the data communication request, the user may trigger the data communication request by selecting what service to trigger to which application of which terminal device on the interface of the control back-office 1.
Step 202, the control background inquires communication connection information from the connection pool according to the identifier of the terminal device, so as to send a data communication request to the agent according to the communication connection information and the service interface corresponding to the service interface identifier.
Because communication connection information between agents corresponding to a plurality of different terminal devices 2 may be maintained in the connection pool of the control background 1, when the control background 1 currently needs to perform data communication for a certain service with a certain application 21 in a certain terminal device 2, the corresponding communication connection information is queried from the connection pool based on the identifier of the terminal device 2, so as to send a data communication request to the corresponding agent 22 through a corresponding communication connection based on the communication connection information and by calling a corresponding service interface.
Step 203, the agent sends a data communication request to the application program corresponding to the application identifier through the service interface corresponding to the service interface identifier.
After receiving the data communication request, the agent 22 invokes a corresponding service interface to send the data communication request to a corresponding service of the corresponding application program 21, so as to implement data communication between the control background 1 and the application program 21.
In addition, in another scenario, optionally, when any application 21 in the plurality of applications in a certain terminal device 2 needs to perform data communication with the control background 1, for example, the application 21 is triggered by a user to perform an operation, which results in the need to communicate with the control background 1, at this time, the agent 22 is further configured to: receiving a data communication request sent by the application program 21 through a corresponding service interface; and sending the data communication request to the control background 1 through the service interface based on the communication connection with the control background 1.
For ease of understanding, the data communication process between the control daemon 1 and the application 21 via the agent 22 is described below as a practical example.
For example, when the application 21 needs to be version-upgraded, for example, when a terminal device side user triggers an upgrade request for the application 21, the application 21 sends the upgrade request to the agent 22 through the version-upgrade service interface, where the upgrade request may include an identifier of the terminal device, an identifier of the application, and a current version number. After receiving the upgrade request, the agent 22 sends the upgrade request to the control back-office 1 through the corresponding service interface and the communication connection established with the control back-office 1. After receiving the upgrade request, the control background 1 queries whether the database has new version information corresponding to the upgrade request, and if so, feeds an upgrade response carrying information such as a new version number and a new version download address back to the agent 22, and feeds the agent 22 back to the application program 21, so that the application program 21 completes corresponding upgrade processing based on the upgrade response.
Fig. 1d is a signaling interaction diagram of another data communication method in the context of the system shown in fig. 1a, as shown in fig. 1d, including the following steps:
step 301, the agent collects the running state information of a plurality of applications and/or terminal devices at a first preset time interval.
Step 302, the agent caches the running state information into an agent database.
Step 303, the agent reads the running state information stored in the corresponding time from the agent database at a second preset time interval, wherein the second preset time interval is greater than the first preset time interval.
And step 304, the agent sends the read running state information to the control background.
Step 304, if the agent is successfully sent, deleting the sent running state information from the agent database; and if the transmission is unsuccessful, delaying to the next transmission time to retransmit the running state information.
In this embodiment, a scenario in which the plurality of applications 21 in the terminal device 2 and the operating conditions of the terminal device 2 are monitored is taken as an example, and how to implement data communication between the control background 1 and the plurality of applications 21 in the terminal device 2 based on the agent 22 is described.
After the agent 22 is successfully started, a specific timing task may be started, for example, the running state information of the CPU usage rate, the memory usage rate, the disk usage rate, the electric quantity information, the installed application program in the terminal device, the version thereof, and the like of the terminal device 2 may be collected every 5 seconds, and the collected running state information may be cached in the agent database. For example, every minute, the running state information collected in the minute is uploaded to the control background 1 through the communication connection established between the control background 1 and the control background 1, if the uploading is successful, the corresponding running state information which is sent is deleted from the proxy database, and if the uploading is not successful, the next time of continuing the uploading is waited.
Accordingly, the control background 1 receives and monitors the operation state information transmitted from the agent 22. Specifically, when the agent 22 uploads the operation status information, description information such as a corresponding terminal device identifier, data collection time, and index name is further added to determine the uniqueness of the data. Specifically, if the control background 1 finds that the corresponding running state information already exists in the background database based on the description information, the corresponding running state information is not written into the background database.
Based on this embodiment, the control background 1 may monitor the running states of the terminal device and the application program in time through the agent, so as to send the abnormality of the terminal device and the application program in time, and perform corresponding processing.
Fig. 2 is a flowchart of an embodiment of a proxy-based data communication method according to an embodiment of the present invention, where the proxy-based data communication method according to this embodiment may be executed by a proxy in the proxy-based data communication system. As shown in fig. 2, the method comprises the steps of:
step 401, the agent establishes a first communication connection with the control background according to a pre-stored communication address of the control background.
Step 402, the agent establishes a second communication connection with the plurality of application programs respectively according to the pre-stored identifiers of the plurality of application programs in the terminal equipment.
Step 403, the agent performs data communication processing between the control background and the plurality of application programs according to the first communication connection, the second communication connection and a preset service interface set, where a service interface in the preset service interface set corresponds to a service set provided by the plurality of application programs.
The data communication method based on the proxy provided in this embodiment is only an explanation of how to implement data communication between the control background and the application program in the terminal device based on the proxy, and details that are not described in detail may refer to relevant explanations in the foregoing embodiments, and are not described herein again.
The above-described system embodiments are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and certainly, the embodiments can also be implemented by hardware. With this understanding in mind, the above technical solutions may be embodied in the form of a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., which includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the various embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.