Data updating method, storage medium, electronic device and program product
By synchronously updating the local file directory object collection and comparing the updated objects, and dynamically updating the listener objects with the configuration update data of the server, the problem of not being able to dynamically update the file directory and listeners in the existing technology is solved, and efficient file directory updates and reduce operation and maintenance workloads are achieved.
Patent Information
- Application Number
- CN202411879155.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-04
AI Technical Summary
The existing technology cannot dynamically update file directories and listeners, and requires modifying code and restarting services, which increases the workload of development and operation and maintenance.
Through the configuration update data that has been updated on the server side, the local file directory object collection is synchronously updated, and compared it with the set before the record update, determine the file directory object that has been updated, and then update the listener object in the listener object collection based on the updated file directory and listening attributes.
It realizes dynamic updates of file directories and listeners, reduces the workload of development and operation and maintenance, and improves the efficiency of file directories updates without modifying code and restarting services.
Smart Images

Figure CN119759844A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a data updating method, a storage medium, an electronic device, and a program product. Background Art
[0002] In related technologies, file monitoring is usually implemented based on a file monitoring tool library, such as Commons-io. For the file directory to be monitored, a monitor (FileAlterationMonitor) object is created, which contains an observer (FileAlterationObserver) object, and a listener (FileAlterationListener) object is added to implement file directory monitoring. Summary of the invention
[0003] The present disclosure provides a data updating method, a storage medium, an electronic device and a program product, which are used to realize the dynamic updating of a file directory and a listener.
[0004] According to a first aspect of an embodiment of the present disclosure, a data updating method is provided, the method comprising: Synchronously updating a local first file directory object set according to configuration update data updated on the server; the configuration update data includes at least one of the first file directory and a first monitoring attribute, the monitoring attribute indicating whether the file directory can be monitored; The updated first file directory object set is compared with the second file directory object set to obtain the updated first file directory object in the first file directory object set; the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory; According to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated; the listener object is used to monitor the second file directory objects in the second file directory object set, and one listener object corresponds to one second file directory object.
[0005] According to a second aspect of an embodiment of the present disclosure, a data updating device is provided, including: The first update module is configured to synchronously update the local first file directory object set according to the configuration update data updated on the server; the configuration update data includes at least one of the first file directory and the first monitoring attribute, and the monitoring attribute represents whether the file directory can be monitored.
[0006] The comparison module is configured to compare the updated first file directory object set with the second file directory object set to obtain the first file directory object that has been updated in the first file directory object set; the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory.
[0007] The second update module is configured to update the listener object in the listener object set according to the second file directory and the second monitoring attribute; the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object.
[0008] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the steps of the method described in the first aspect of the embodiment of the present disclosure are implemented.
[0009] According to a fourth aspect of an embodiment of the present disclosure, there is provided an electronic device, including: a memory having a computer program stored thereon; A processor is used to execute the computer program in the memory to implement the steps of the data updating method described in the first aspect of the embodiment of the present disclosure.
[0010] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps of the data updating method described in the first aspect of the embodiment of the present disclosure.
[0011] Through the above technical solution, the present invention firstly updates the local first file directory object set synchronously according to the configuration update data updated on the server side, and compares the updated first file directory object set with the second file directory object set to obtain the first file directory object that has been updated in the first file directory object set, wherein the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory. Then, according to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated, wherein the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object. In this way, when the data on the server side is updated, the local first file directory object set is firstly updated synchronously according to the configuration update data updated on the server side, and then the listener object is updated according to the updated first file directory object. Since the update of the file directory object and the listener object is a hot update, there is no need to modify the code and restart the service, and the client's file directory and listener can be dynamically updated, which reduces the workload of development and operation and maintenance, and improves the efficiency of file directory update.
[0012] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings: Figure 1 It is a schematic diagram of an application environment of a data updating method provided by an embodiment of the present disclosure.
[0014] Figure 2 The figure is a flow chart of a data updating method according to an exemplary embodiment.
[0015] Figure 3 is a flow chart of another data updating method according to an exemplary embodiment.
[0016] Figure 4 The figure is a flowchart of a data updating method according to an exemplary embodiment.
[0017] Figure 5 It is a block diagram of a data updating device according to an exemplary embodiment.
[0018] Figure 6 is a block diagram of another data updating device according to an exemplary embodiment.
[0019] Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment.
[0020] Figure 8 is a block diagram of another electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0021] The specific implementation of the present disclosure is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the present disclosure, and is not used to limit the present disclosure.
[0022] Before introducing a data updating method, a storage medium, an electronic device, and a program product shown in an embodiment of the present disclosure, the application scenario of the embodiment of the present disclosure is first introduced.
[0023] In the related art, the file directory monitoring solution based on Commons-io cannot dynamically modify the monitored file directory and stop the monitoring directory function. It is necessary to modify the code and restart the service, which increases the workload of development and operation and maintenance.
[0024] The embodiments of the present disclosure can be implemented based on Nacos (Dynamic Naming and Configuration Service) or Consul service management platform. Nacos or Consul can serve as a configuration center to centrally manage the configuration information of microservices and support dynamic configuration updates, so that the latest configuration data can be obtained in real time without restarting the service.
[0025] Reference Figure 1 , Figure 1 FIG. 1 shows a schematic diagram of an application environment of a data update method provided by an embodiment of the present disclosure. The server of Nacos or Consul can be deployed in Figure 1 On the first server 110 shown in FIG. , the Nacos or Consul client can be deployed as follows Figure 1 . The first server 110 may be connected to the terminal device 120 or the second server 130 via a network. The network is used to provide a medium for a communication link between the first server 110 and the terminal device 120. The network may include various connection types, such as a wired communication link, a wireless communication link, etc., which is not limited in the embodiments of the present application.
[0026] It should be understood that Figure 1The first server 110, network, terminal device 120, and second server 130 are merely illustrative. Depending on the implementation requirements, there may be any number of first servers, networks, terminal devices, and second servers. Exemplarily, the first server 110 and the second server 130 may be physical servers, or a server cluster composed of multiple servers, etc. The terminal device 120 may be a mobile phone, a tablet, a desktop computer, a laptop computer, and the like. It is understandable that the embodiments of the present application may also allow multiple terminal devices 120 or second servers 130 to access the first server 110 at the same time.
[0027] The data updating method shown in the embodiment of the present disclosure can dynamically update the file directory object and the listener object corresponding to the file directory of the client according to the configuration update data of the server when the configuration data corresponding to the file directory of the server is updated, without modifying the code and restarting the service, thereby reducing the workload of development and operation and maintenance, improving the efficiency of file directory updating, and being able to provide services uninterruptedly during the update process of the file directory, thereby improving the stability of the service.
[0028] Figure 2 is a flow chart of a data updating method according to an exemplary embodiment. Figure 2 As shown, the method includes: Step S101: Synchronously update the local first file directory object set according to the configuration update data updated on the server.
[0029] For example, the server in the embodiment of the present disclosure may be a server configured with Nacos or Consul, the client may be a client configured with Nacos or Consul, and the user may configure or update relevant data of the file directory on the server.
[0030] Among them, Nacos is a dynamic service discovery, configuration management and service management platform. It is mainly used to help register and discover services in distributed systems, and manage service configuration information. In scenarios such as microservice architecture, Nacos plays a key role, enabling microservices to easily find each other and flexibly obtain and update configurations. Nacos can serve as a storage center for file directory-related configurations. When the configuration of a file directory is updated, such as when information such as file storage path, file directory permission settings, and file cache policies changes, these configurations can be updated in Nacos.
[0031] Among them, Consul is a tool for service discovery and configuration. It provides functions such as service registration and discovery, health check, key-value storage, etc. Consul's key-value storage function can be used to store configuration information related to file directories. When the configuration of the file directory is updated, such as changes in the file storage path, changes in permission settings, etc., these new configuration information can be stored in Consul's key-value storage. Other applications or services can obtain these updated configurations from Consul and adjust their access and operation methods for the file directory accordingly.
[0032] When the configuration data of the server is updated, the first file directory object set of the client can be synchronously updated according to the updated configuration update data. The configuration update data may include only the first file directory, or only the first monitoring attribute, or both the first file directory and the first monitoring attribute. The monitoring attribute in the embodiment of the present disclosure may indicate whether the file directory can be monitored.
[0033] In the case where the configuration update data includes the first file directory and the first monitoring attribute, the first monitoring attribute may be a monitoring attribute corresponding to the first file directory, or may be another monitoring attribute except the first file directory.
[0034] The first file directory may include one file directory or multiple file directories, and the first monitoring attribute may include the monitoring attribute of one file directory or multiple file directories. Furthermore, the first file directory may be an original file directory of the server or a newly added file directory, that is, the update of the first file directory may be an update of the original first file directory or a newly added first file directory. The first file directory object set may include at least one file directory object, and the file directory object may include a file directory and the monitoring attribute corresponding to the file directory.
[0035] In some embodiments, the file directory object can be a JavaBean object, and the @RefreshScope annotation can be used for the JavaBean object. Through the @RefreshScope annotation, when the configuration data of the server is updated, the configuration update data of the server can be obtained in real time, and the corresponding JavaBean object in the first file directory object set can be updated according to the configuration update data, thereby realizing dynamic real-time update of the file directory in the client. Since the update of the JavaBean object is a hot update, the service can be provided uninterruptedly during the update process of the file directory, thereby improving the stability of the service.
[0036] Step S102: compare the updated first file directory object set with the second file directory object set to obtain the updated first file directory object in the first file directory object set.
[0037] For example, the second file directory object set may be used to record the first file directory object set before updating, and the second file directory object set may include at least one file directory object.
[0038] When the configuration file of the server is updated, the first file directory object may be updated first, and then the updated first file directory object set is compared with the second file directory object set to obtain a comparison result.
[0039] Since the second file directory object set has not been updated at this time, the first file directory object that has been updated in the first file directory object set can be determined by comparison. The comparison result may include file directory objects in the first file directory object set that are different from the second file directory object set, that is, the first file directory object that has been updated, and the first file directory object may include the second file directory and the second monitoring attribute of the second file directory.
[0040] In some embodiments, the file directory object may be a JavaBean object, and the second file directory object set may be a locally cached Map1, wherein the key value of Map1 may be the ID of the JavaBean object, and the value of Map1 may be a JavaBean object.
[0041] Step S103: updating the listener object in the listener object set according to the second file directory and the second listening attribute.
[0042] Among them, the listener object can be used to monitor the second file directory object in the second file directory object set. Specifically, it can be understood that the listener object can be used to monitor the file directory included in the corresponding second file directory object. One listener object can correspond to one second file directory object. The listener object can be, for example, a FileAlterationMonitor object.
[0043] It should be noted that, since not all file directories need to be monitored, each listener object in the listener set can correspond to a second file directory object, but a second file directory object may not have a corresponding listener object in the listener set. For example, the second file directory object set may include 100 second file directory objects, and the listener object set may include 80 listener objects, that is, 80 second file directory objects in the second file directory object set may have corresponding listener objects in the listener object set, and 20 second file directory objects may not have corresponding listener objects in the listener object set.
[0044] For example, the client can set a listener to monitor the specified file directory in the server. When the configuration data of the specified file directory on the server is updated, the listener can call a method to let the client know that the configuration data of the specified file directory on the server has been updated. Since the first file directory object set of the client has been updated in real time when the configuration data of the server is updated, the client can update the listener object set of the client according to the updated first file directory object when it is determined that the configuration data of the server has been updated.
[0045] In some embodiments, it can be determined that the first file directory object is a file directory object obtained by updating the original file directory object in the first file directory object set, and can also be a file directory object newly added in the first file directory object. If the first file directory object is a file directory object obtained by updating the original file directory object in the first file directory object set, then the listener corresponding to the second file directory object in the listener object set can be updated according to the second monitoring attribute included in the second file directory object. If the first file directory object is a newly added file directory object, and the monitoring attribute of the newly added file directory object indicates that the file directory corresponding to the file directory object can be monitored, then a corresponding listener object can be added to the listener object set, wherein the monitoring function of the newly added listener object can be in the on state.
[0046] In some other embodiments, the second file directory object set may also be updated according to the updated first file directory object set and the second file directory object set. For example, if the file directory object is a JavaBean object, the listener object is a FileAlterationMonitor object, the second file directory object set is a local cache Map1, and the listener object set is a local cache Map2, the JavaBean objects in the local cache Map1 may be updated, and the FileAlterationMonitor object in the local cache Map2 may be updated, according to the JavaBean objects in the first file directory object set and the JavaBean objects in the local cache Map1.
[0047] In summary, the present disclosure firstly updates the local first file directory object set synchronously according to the configuration update data updated on the server side, and compares the updated first file directory object set with the second file directory object set to obtain the first file directory object that is updated in the first file directory object set, wherein the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory. Then, according to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated, wherein the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object. In this way, when the data on the server side is updated, the local first file directory object set is firstly updated synchronously according to the configuration update data updated on the server side, and then the listener object is updated according to the updated first file directory object. Since the update of the file directory object and the listener object is a hot update, there is no need to modify the code and restart the service, and the dynamic update of the local file directory and the listener can be realized, which reduces the workload of development and operation and maintenance, and improves the efficiency of file directory update.
[0048] In some other embodiments, an implementation of step S103 may be: When there is no third file directory object matching the first file directory object in the second file directory object set, and the second monitoring attribute indicates that the second file directory can be monitored, a first listener object corresponding to the first file directory object is generated, and the first listener object is added to the listener object set.
[0049] Alternatively, when there is a third file directory object matching the first file directory object in the second file directory object set, the listener object in the listener object set is updated according to the second listening attribute.
[0050] For example, it can be determined in the second file directory object set whether there is a third file directory object that matches the first file directory object, wherein the third file directory object may include a third file directory and a third monitoring attribute, and the first file directory object matches the third file directory object if the identifier of the first file directory object is the same as the identifier of the third file directory object, that is, if the identifier of the first file directory object is the same as the identifier of the third file directory object, then it can be determined that the first file directory object matches the third file directory object.
[0051] If there is no third file directory object matching the first file directory object in the second file directory object set, indicating that the first file directory object is a newly added file directory object, it can be further determined whether the second monitoring attribute of the first file directory object is capable of being monitored.
[0052] If the second monitoring attribute indicates that the second file directory can be monitored, it means that a listener object is required in the listener object set to monitor the second file directory object, then a first listener object corresponding to the first file directory object can be generated, and the first listener object is added to the listener object set. Among them, the monitoring function in the first listener object set can be in the on state. If the second monitoring attribute indicates that the second file directory cannot be monitored, it means that a listener object is not required to monitor the second file directory, then a new listener object may not be created in the listener object set.
[0053] If there is a third file directory object matching the first file directory object in the second file directory object set, indicating that the first file directory object is a file directory object obtained by updating the original file directory object in the first file directory object set, then the listener object in the listener object set can be updated according to the second listening attribute.
[0054] In some embodiments, if the second monitoring attribute indicates that the second file directory can be monitored, and the third monitoring attribute indicates that the third file directory cannot be monitored, that is, the second file directory object in the updated first file directory object can be monitored, which means that there needs to be a listener object in the listener object set to monitor the second file directory object, and the first file directory object cannot be monitored before being updated. The inability to be monitored indicates that there may be a second listener object corresponding to the third file directory object in the listener object set, or there may not be a second listener object corresponding to the third file directory object. Then, the listener object in the listener object set can be updated according to the listener object set and the third file directory object.
[0055] For example, if the second listener object corresponding to the third file directory object does not exist in the listener object set, then a second listener object corresponding to the third file directory object can be generated, and the second listener object can be added to the listener object set, wherein the monitoring function of the second listener object can be turned on. If the second listener object corresponding to the third file directory object exists in the listener object set, because the first file directory object matching the third file directory object is updated, then a new second listener object corresponding to the third file directory object can be generated, and the second listener object in the listener object set can be replaced with the new second listener object to update the listener object set, wherein the monitoring function of the new second listener object can be turned on.
[0056] In other embodiments, if the second listening attribute indicates that the second file directory cannot be listened to, and the third listening attribute indicates that the third file directory can be listened to, it means that the first file directory object can be listened to before being updated, that is, there is a second listener object corresponding to the third file directory object in the listener object set, but the second file directory in the updated first file directory object cannot be listened to, that is, the updated second file directory object does not need to be listened to, then the listening function of the second listener object corresponding to the third file directory object in the listener object set can be turned off.
[0057] Figure 3 is a flow chart of another data updating method according to an exemplary embodiment. Figure 3 As shown, the method also includes: Step S201: Synchronously update the local first file directory object set according to the configuration update data updated on the server.
[0058] Step S202: compare the updated first file directory object set with the second file directory object set to obtain the updated first file directory object in the first file directory object set.
[0059] Step S203: Update the listener object in the listener object set according to the second file directory and the second listening attribute.
[0060] The above steps S201 - S203 are the same as steps S101 - S103 in the above embodiment and are not described again.
[0061] Step S204: update the second file directory object set according to the first file directory object.
[0062] For example, it can be determined in the second file directory object set whether there is a third file directory object that matches the first file directory object. If there is no third file directory object that matches the first file directory object in the second file directory object set, it means that the first file directory object is a newly added file directory object, and the first file directory object can be added to the second file directory object set. If there is a third file directory object that matches the first file directory object in the second file directory object set, it means that the first file directory object is a file directory object obtained by updating the original file directory object in the first file directory object set, and the third file directory object in the second file directory object set can be updated according to the first file directory object. In one possible implementation, the third file directory object can be replaced with the first file directory object to obtain an updated second file directory object set.
[0063] In this way, by constructing file directory objects and listener objects, after the first file directory object set, the locally cached second file directory object set is further updated. When the configuration data of the server is updated next time, the first file directory object set is synchronously updated, and then compared with the second file directory object set that has not been updated, the updated first file directory object can be obtained, and the listener object set is updated according to the first file directory object. Similarly, each time the configuration data of the server is updated, the first file directory object set, the listener object set, and the second file directory object set can be dynamically updated according to the data update method shown in the embodiment of the present disclosure. Since the above-mentioned update method is a hot update, there is no need to modify the code and restart the service, and the client's file directory and listener can be dynamically updated, which reduces the workload of development and operation and maintenance and improves the efficiency of file directory updates.
[0064] In other embodiments, during the initialization phase of the client, the client may obtain the configuration data of the server and generate a first file directory object set based on the configuration data, wherein the configuration data may be understood as initial data manually configured by the user on the server, and the configuration data may include at least one fourth file directory, a file directory identifier of each fourth file directory, and a fourth listening attribute of each fourth file directory.
[0065] In other embodiments, after generating the first file directory object set, a corresponding listener object can also be generated according to the fourth monitoring attribute of the fourth file directory object in the first file directory object set, wherein the listener object can be the FileAlterationMonitor object of apache commons.io. If the fourth monitoring attribute of the fourth file directory object indicates that the fourth file directory in the fourth file directory object can be monitored, a corresponding listener object can be generated and added to the listener object set. If the monitoring attribute of the fourth file directory object indicates that the fourth file directory in the fourth file directory object cannot be monitored, there is no need to generate a corresponding listener object. In this way, by constructing file directory objects and listener objects, when the configuration data corresponding to the file directory of the server is updated, the file directory objects and listener objects corresponding to the file directory of the client can be dynamically updated according to the configuration update data of the server. Since the update mode of the file directory objects and the listener objects is hot update, there is no need to modify the code and restart the service, which reduces the workload of development and operation and maintenance and improves the efficiency of file directory update.
[0066] In some other embodiments, after the first file directory object set is generated, the second file directory object set and the listener object set can also be cached locally. The second file directory object set can include at least one file directory object and a file directory identifier of each file directory object, as well as a corresponding relationship between the file directory object and the file directory identifier, and the file directory identifiers in the second file directory object set correspond to the file directory objects one by one. The listener object set can include at least one listener object and at least one file directory identifier, as well as a corresponding relationship between the listener object and the file directory identifier, the listener object can correspond to the file directory identifier one by one, and the listener object can be used to listen to the file directory object indicated by the corresponding file directory identifier.
[0067] For example, if the file directory object is a JavaBean object and the listener object is a FileAlterationMonitor object, the second file directory object set may be a local cache Map1, and the listener object set may be a local cache Map2. The key value of Map1 may be the ID of the JavaBean object, and the value of Map1 may be the JavaBean object; the key value of Map2 may be the ID of the JavaBean object, and the value of Map2 may be the FileAlterationMonitor object.
[0068] The following example takes the file directory object as a JavaBean object, the listener object as a FileAlterationMonitor object, the second file directory object collection as the local cache Map1, and the listener object collection as the local cache Map2 as an example. Figure 4 , providing a specific embodiment.
[0069] During the initialization phase of the client, the client may obtain configuration data of the server, generate a first file directory object set according to the configuration data, and generate a local cache Map1 and a local cache Map2 according to the first file directory object set.
[0070] When the configuration data of the server is updated, the first file directory object set is updated synchronously according to the updated configuration update data through the @RefreshScope annotation, and the updated first file directory object set is compared with Map1 to obtain the updated first file directory object in the first file directory object set, wherein the first file directory object includes the second file directory and the second monitoring attribute of the second file directory. If the second file directory identifier corresponding to the second file directory does not exist in the local cache Map1, the client can determine that the second file directory is a newly added file directory, and then a key-value pair of the JavaBean object corresponding to the first file directory and the second file directory identifier can be added to the local cache Map1. Further, it can be judged whether the second monitoring attribute represents whether the second file directory corresponding to the second file directory identifier can be monitored. If the second file directory can be monitored, a FileAlterationMonitor object corresponding to the second file directory can be generated, and the FileAlterationMonitor. Start() method can be called to start monitoring the second file directory. And a key-value pair of the FileAlterationMonitor object corresponding to the second file directory identifier and the second file directory identifier can be added to the local cache Map2.
[0071] If the second file directory identifier corresponding to the second file directory exists in the local cache Map1, it means that the first file directory object is a file directory object obtained by updating the original file directory object in the first file directory object set, then the local cache Map2 can be updated according to the second monitoring attribute.
[0072] For example, if the second monitoring property of the JavaBean object corresponding to the second file directory indicates that the second file directory can be monitored, the third monitoring property of the JavaBean object corresponding to the third file directory matching the second file directory in the local cache Map1 indicates that the third file directory cannot be monitored, and there is no FileAlterationMonitor object corresponding to the third file directory in the listener object collection, then a FileAlterationMonitor object corresponding to the third file directory can be generated, and the FileAlterationMonitor object can be added to the listener object collection, and the FileAlterationMonitor. Start() method can be called to start monitoring the third file directory.
[0073] If the second monitoring attribute of the JavaBean object corresponding to the second file directory indicates that the second file directory can be monitored, the third monitoring attribute of the JavaBean object corresponding to the third file directory matching the second file directory in the local cache Map1 indicates that the second file directory cannot be monitored, and there is a FileAlterationMonitor object corresponding to the third file directory in the listener object collection, then the FileAlterationMonitor object corresponding to the third file directory in the listener object collection can be deleted, and a new FileAlterationMonitor object corresponding to the third file directory can be generated and added to the local cache Map2.
[0074] If the second monitoring attribute indicates that the second file directory cannot be monitored, and the third monitoring attribute indicates that the third file directory matching the second file directory can be monitored, then the FileAlterationMonitor.Stop() method of the FileAlterationMonitor object can be called to turn off the monitoring function of the listener object corresponding to the third file directory in the listener object collection, thereby stopping monitoring the third file directory.
[0075] In other embodiments, when a listener in the listener object set turns on the listening function, other listeners are prevented from listening to the file directory that the listener is listening to.
[0076] For example, since there may be multiple instances of a file monitoring service, multiple listeners will repeat the data update steps when monitoring the same file directory. Therefore, a distributed lock can be added when the listener object calls the FileAlterationMonitor.Start() method to prevent other listeners from monitoring the file directory that the listener is monitoring, ensuring that only one file monitoring service is executed at the same time. The distributed lock can be a Redis distributed lock, a ZooKeeper distributed lock, etc.
[0077] In summary, the present disclosure firstly updates the local first file directory object set synchronously according to the configuration update data updated on the server side, and compares the updated first file directory object set with the second file directory object set to obtain the first file directory object that is updated in the first file directory object set, wherein the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory. Then, according to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated, wherein the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object. In this way, when the data on the server side is updated, the local first file directory object set is firstly updated synchronously according to the configuration update data updated on the server side, and then the listener object is updated according to the updated first file directory object. Since the update of the file directory object and the listener object is a hot update, there is no need to modify the code and restart the service, and the dynamic update of the local file directory and the listener can be realized, which reduces the workload of development and operation and maintenance, and improves the efficiency of file directory update.
[0078] Figure 5 is a block diagram of a data updating device according to an exemplary embodiment. Figure 5 As shown, the device 300 includes: The first update module 301 is configured to synchronously update the local first file directory object set according to the configuration update data updated on the server; the configuration update data includes at least one of the first file directory and the first monitoring attribute, and the monitoring attribute represents whether the file directory can be monitored.
[0079] The comparison module 302 is configured to compare the updated first file directory object set with the second file directory object set to obtain the first file directory object that has been updated in the first file directory object set; the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory.
[0080] The second update module 303 is configured to update the listener object in the listener object set according to the second file directory and the second monitoring attribute; the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object.
[0081] In some embodiments, the second update module 303 is configured to: If there is no third file directory object matching the first file directory object in the second file directory object set, and the second monitoring attribute indicates that the second file directory can be monitored, a first listener object corresponding to the first file directory object is generated, and the first listener object is added to the listener object set. Or, When there is a third file directory object matching the first file directory object in the second file directory object set, the listener object in the listener object set is updated according to the second listening attribute.
[0082] In some other embodiments, the second updating module 303 is configured to: When the second monitoring attribute indicates that the second file directory can be monitored and the third monitoring attribute indicates that the third file directory cannot be monitored, the listener objects in the listener object set are updated according to the listener object set and the third file directory object.
[0083] In some other embodiments, the second updating module 303 is configured to: If the second listener object corresponding to the third file directory object does not exist in the listener object set, generate the second listener object corresponding to the third file directory object, and add the second listener object to the listener object set. In the case that the second listener object exists in the listener object set, a new second listener object corresponding to the third file directory object is generated, and the second listener object in the listener object set is replaced with the new second listener object.
[0084] In some other embodiments, the second updating module 303 is configured to: When the second monitoring attribute indicates that the second file directory cannot be monitored, and the third monitoring attribute indicates that the third file directory can be monitored, the monitoring function of the second listener object corresponding to the third file directory object in the listener object set is turned off.
[0085] Figure 6 is a block diagram of another data updating device according to an exemplary embodiment. Figure 6 As shown, the device 300 also includes: The third updating module 304 is configured to update the second file directory object set according to the first file directory object.
[0086] In some other embodiments, the third update module 304 is configured to: Determine whether there is a third file directory object matching the first file directory object in the second file directory object set.
[0087] If the third file directory object does not exist in the second file directory object set, the first file directory object is added to the second file directory object set. Or, In the case that the third file directory object exists in the second file directory object set, the third file directory object in the second file directory object set is updated according to the first file directory object.
[0088] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0089] In summary, the present disclosure firstly updates the local first file directory object set synchronously according to the configuration update data updated on the server side, and compares the updated first file directory object set with the second file directory object set to obtain the first file directory object that is updated in the first file directory object set, wherein the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory. Then, according to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated, wherein the listener object is used to monitor the second file directory object in the second file directory object set, and one listener object corresponds to one second file directory object. In this way, when the data on the server side is updated, the local first file directory object set is firstly updated synchronously according to the configuration update data updated on the server side, and then the listener object is updated according to the updated first file directory object. Since the update of the file directory object and the listener object is a hot update, there is no need to modify the code and restart the service, and the dynamic update of the local file directory and the listener can be realized, which reduces the workload of development and operation and maintenance, and improves the efficiency of file directory update.
[0090] Figure 7 FIG. 1 is a block diagram of an electronic device according to an exemplary embodiment. Figure 7 As shown, the first electronic device 700 may include: a first processor 701 and a first memory 702. The first electronic device 700 may also include one or more of a multimedia component 703, a first I / O (input / output) interface 704, and a first communication component 705.
[0091] The first processor 701 is used to control the overall operation of the first electronic device 700 to complete all or part of the steps in the above-mentioned data updating method. The first memory 702 is used to store various types of data to support the operation of the first electronic device 700. For example, these data may include instructions for any application or method used to operate on the first electronic device 700, and application-related data, such as contact data, sent and received messages, pictures, audio, video, etc. The first memory 702 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Read-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, magnetic disk or optical disk. The multimedia component 703 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone, which is used to receive external audio signals. The received audio signal may be further stored in the first memory 702 or sent through the first communication component 705. The audio component also includes at least one speaker for outputting audio signals. The first I / O interface 704 provides an interface between the first processor 701 and other interface modules, and the above-mentioned other interface modules may be keyboards, mice, buttons, etc. These buttons may be virtual buttons or physical buttons. The first communication component 705 is used for wired or wireless communication between the first electronic device 700 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, so the corresponding first communication component 705 may include: Wi-Fi module, Bluetooth module, NFC module.
[0092] In an exemplary embodiment, the first electronic device 700 can be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned data update method.
[0093] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the above-mentioned data updating method are implemented. For example, the computer-readable storage medium can be the above-mentioned first memory 702 including program instructions, and the above-mentioned program instructions can be executed by the first processor 701 of the first electronic device 700 to complete the above-mentioned data updating method.
[0094] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program executable by a processor. When the computer program is executed by the processor, the steps of the above data updating method are implemented.
[0095] Figure 8 8 is a block diagram of another electronic device according to an exemplary embodiment. For example, the second electronic device 800 may also be provided as a server. Figure 8 The second electronic device 800 includes a second processor 822, which may be one or more, and a second memory 832 for storing a computer program executable by the second processor 822. The computer program stored in the second memory 832 may include one or more modules each corresponding to a set of instructions. In addition, the second processor 822 may be configured to execute the computer program to perform the above-mentioned data updating method.
[0096] In addition, the second electronic device 800 may further include a power supply component 826 and a second communication component 850, the power supply component 826 may be configured to perform power management of the second electronic device 800, and the second communication component 850 may be configured to implement communication of the second electronic device 800, for example, wired or wireless communication. In addition, the second electronic device 800 may further include a second I / O (input / output) interface 858. The second electronic device 800 may operate based on an operating system stored in the second memory 832, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, etc.
[0097] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by the processor, the steps of the above-mentioned data updating method are implemented. For example, the computer-readable storage medium can be the above-mentioned second memory 832 including program instructions, and the above-mentioned program instructions can be executed by the second processor 822 of the second electronic device 800 to complete the above-mentioned data updating method.
[0098] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program executable by a processor. When the computer program is executed by the processor, the steps of the above data updating method are implemented.
[0099] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments. Within the technical concept of the present disclosure, a variety of simple modifications can be made to the technical solution of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.
[0100] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present disclosure will not further describe various possible combinations.
[0101] In addition, various embodiments of the present disclosure may be arbitrarily combined, and as long as they do not violate the concept of the present disclosure, they should also be regarded as the contents disclosed by the present disclosure.
Claims
1. A data updating method, characterized in that: The method comprises: Synchronously updating a local first file directory object set according to configuration update data updated on the server; the configuration update data includes at least one of the first file directory and a first monitoring attribute, the monitoring attribute indicating whether the file directory can be monitored; The updated first file directory object set is compared with the second file directory object set to obtain the updated first file directory object in the first file directory object set; the second file directory object set is used to record the first file directory object set before the update, and the first file directory object includes the second file directory and the second monitoring attribute of the second file directory; According to the second file directory and the second monitoring attribute, the listener object in the listener object set is updated; the listener object is used to monitor the second file directory objects in the second file directory object set, and one listener object corresponds to one second file directory object.
2. The method according to claim 1, characterized in that The updating of the listener object in the listener object set according to the second file directory and the second listening attribute includes: If there is no third file directory object matching the first file directory object in the second file directory object set, and the second monitoring attribute indicates that the second file directory can be monitored, generate a first listener object corresponding to the first file directory object, and add the first listener object to the listener object set; or, In the case that the third file directory object matching the first file directory object exists in the second file directory object set, the listener objects in the listener object set are updated according to the second listening attribute.
3. The method according to claim 2, characterized in that The third file directory object includes a third file directory and a third monitoring attribute; and updating the listener object in the listener object set according to the second monitoring attribute includes: When the second monitoring attribute indicates that the second file directory can be monitored and the third monitoring attribute indicates that the third file directory cannot be monitored, the listener objects in the listener object set are updated according to the listener object set and the third file directory object.
4. The method according to claim 3, characterized in that The updating of the listener objects in the listener object set according to the listener object set and the third file directory object comprises: If the second listener object corresponding to the third file directory object does not exist in the listener object set, generate the second listener object corresponding to the third file directory object, and add the second listener object to the listener object set; or, In the case that the second listener object exists in the listener object set, a new second listener object corresponding to the third file directory object is generated, and the second listener object in the listener object set is replaced with the new second listener object.
5. The method according to claim 3, characterized in that: The updating of the listener object in the listener object set according to the second listening attribute includes: When the second monitoring attribute indicates that the second file directory cannot be monitored and the third monitoring attribute indicates that the third file directory can be monitored, the monitoring function of the second listener object corresponding to the third file directory object in the listener object set is disabled.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: The second file directory object set is updated according to the first file directory object.
7. The method according to claim 6, characterized in that The updating of the second file directory object set according to the first file directory object comprises: Determine whether there is a third file directory object matching the first file directory object in the second file directory object set; If the third file directory object does not exist in the second file directory object set, add the first file directory object to the second file directory object set; or, In the case that the third file directory object exists in the second file directory object set, the third file directory object in the second file directory object set is updated according to the first file directory object.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the data updating method described in any one of claims 1 to 7 are implemented.
9. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the data updating method according to any one of claims 1 to 7.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the data updating method described in any one of claims 1 to 7 are implemented.