Intelligent gateway management method and system based on event-driven model
Technical Field
The invention relates to the field of intelligent equipment control, in particular to an intelligent gateway management method and system based on an event-driven model.
Background
Various intelligent hardware devices form an intelligent home system, and in order to uniformly manage all the intelligent hardware, an intelligent gateway is needed to manage all the intelligent hardware. By adding an intelligent gateway device at the user side, all intelligent hardware can be uniformly managed by the intelligent gateway, so that the simplification of operation and the mutual operation of the intelligent hardware are realized. The user can control the intelligent hardware through a mobile phone application program, the user binds the intelligent gateway after registering in the intelligent gateway background management system, then sends an instruction to the intelligent gateway background management system through the mobile phone, the background management system sends the instruction to the intelligent gateway after processing, and finally the intelligent gateway controls the intelligent hardware. The intelligent gateway also needs to feed back the real-time state of the intelligent hardware to the background management system, and the background management system feeds back the real-time state to the user through the mobile phone after processing.
The invention discloses an intelligent home management system based on operation service, which is provided by patent document with application number CN201510265376.X and comprises an intelligent home operation platform, a client terminal, an intelligent gateway and controlled equipment. The intelligent home operation platform communicates with the intelligent gateway through the Ethernet, and users can remotely operate the equipment in the home through the operation platform without fixing IP addresses. The functions of user account opening registration, use, logout, equipment change, system setting and the like are managed through the operation platform. And a complete and stable intelligent home remote control solution is provided. And the client terminal accesses the server of the intelligent home operation platform through the Internet to acquire the intelligent home remote operation service. And the intelligent gateway is responsible for local networking management and network starting, and remotely operates the equipment in the family through the operation platform.
Also, as disclosed in patent document CN201610087803.4, "a method for associating a mobile terminal with a background management system task", the present invention relates to a method for associating a mobile terminal with a background management system task, including the following steps: s1, the mobile terminal receives a work instruction sent by the background management system, the work instruction is generated after the background management system receives an internal and external work task request or a set work plan, and the work instruction is associated with a folder generated by the background management system; s2, the mobile terminal automatically generates a file package which is also associated with the work order; and S3, after the mobile terminal generates information to be uploaded to the background management system, packaging the information to be uploaded together, automatically storing the information in a file package, and then uploading the information.
The prior art has the disadvantage that each intelligent device is an entity object in the background management system, and a background thread is required to be started for processing the operation and monitoring of the entity objects. An intelligent gateway backend server may need to manage millions of intelligent devices simultaneously, which requires a balance between the use of resources and the number of devices managed. And a common multithreading mode is used, each intelligent device generates one thread for management, about 4096 threads occupy 1G of memory space in the mode, and a server cannot meet the resources required by the system. Even if the memory is available, the execution of each thread needs to be switched between contexts in the CPU, and a timing cycle mode is also needed when a new service needs to be processed, so that the resources of the CPU are consumed finally, and the service processing cannot be effectively performed by using the system.
The instructions for an intelligent hardware also cause problems in multi-threaded operation, such as issuing two commands to turn on and adjust the brightness of the intelligent lamp, and in multi-threaded environment, accessing and modifying the business object of the intelligent lamp are executed concurrently, and locks are added to the business object to ensure sequentiality, thereby increasing the complexity of the system.
Disclosure of Invention
In view of the current state of the prior art, the present invention aims to solve the performance problem of the system and the sequential processing problem of the instructions in the environment where a large amount of intelligent hardware is controlled and managed by the background management system.
The technical scheme adopted by the invention for solving the technical problems is as follows:
an intelligent gateway management method based on an event-driven model, wherein the event-driven model comprises a multi-level role management directory, and the management method comprises the following steps:
s1, searching an intelligent gateway role corresponding to the intelligent gateway when the intelligent gateway is in an online state;
s2, when the intelligent equipment managed by the intelligent gateway is in an online state, establishing an intelligent equipment role;
s3, receiving a control instruction sent by a user, and sending the control instruction to an intelligent device role;
and S4, the intelligent device role judges whether the control instruction is an executable instruction, if so, the intelligent device role sends the control instruction to the intelligent gateway role, and the intelligent gateway role sends the control instruction to the intelligent gateway.
Further, step S1 is preceded by:
and creating a root node, wherein the root node is used for creating an intelligent gateway role corresponding to the intelligent gateway.
Further, in step S1, the intelligent gateway role corresponding to the intelligent gateway is searched according to the intelligent gateway serial number information.
Further, in step S1, if the intelligent gateway role corresponding to the intelligent gateway cannot be found according to the serial number information of the intelligent gateway, a new intelligent gateway role is created.
Further, in step S2, a smart device role is created in the smart gateway role according to the smart device serial number information.
Further, step S2 includes:
after the intelligent device role is established, starting state monitoring on the intelligent device role;
and when the role of the intelligent device is abnormal, sending a notification message to the role of the intelligent gateway.
Further, after the connection between the background management system and the intelligent gateway is interrupted, a stop message is sent to the role of the intelligent gateway;
and after receiving the stop message, the intelligent gateway role sends the stop message to all intelligent hardware roles managed by the intelligent gateway role.
An intelligent gateway management system based on an event-driven model, comprising:
the searching module is used for searching the intelligent gateway role corresponding to the intelligent gateway when the intelligent gateway is in an online state;
the creating module is used for creating the role of the intelligent equipment when the intelligent equipment managed by the intelligent gateway is in an online state;
the forwarding module is used for receiving a control instruction sent by a user and sending the control instruction to the role of the intelligent equipment;
and the judging module is used for judging whether the control instruction is an executable instruction.
Further, the creating module is further configured to create a new role of the intelligent gateway when the role of the intelligent gateway corresponding to the intelligent gateway cannot be found according to the serial number information of the intelligent gateway.
Further, still include:
and the state monitoring module is used for starting state monitoring of the intelligent device role after the intelligent device role is established.
The invention reduces the consumption of memory and CPU resources and improves the manageable hardware quantity by using the event-driven model. Through the single-thread model of the role, the complexity of the system is reduced, and the concurrent processing capacity and the response speed of the system are improved.
Drawings
Fig. 1 is a flowchart of an intelligent gateway management method based on an event-driven model according to an embodiment of the present invention;
fig. 2 is a structural diagram of an intelligent gateway management system based on an event-driven model according to an embodiment of the present invention;
fig. 3 is a system role structure diagram in the second embodiment of the present invention.
Detailed Description
The following are specific embodiments of the present invention and are further described with reference to the drawings, but the present invention is not limited to these embodiments.
An intelligent gateway background server needs to have the capacity of managing millions of intelligent hardware, and in order to achieve the service requirement, the invention uses the event-driven model of Akka to achieve the capacity of managing a large amount of intelligent hardware. The main purpose of Akka is to write applications so that they can be more easily deployed on the cloud or run in a distributed environment, and can effectively utilize all computer resources for business processing. Akka is a Scala-written library for simplifying the writing of fault-tolerant, highly scalable Java and Scala role model applications.
These intelligent devices act as an Actor in the intelligent gateway background management system. It has the following characteristics:
1. the role is a very small module, and 250 ten thousand roles can be deployed in the memory of 1G, so that the capacity requirement of the memory is met.
2. The roles are single-threaded and interact with each other by transmitting messages, if no message is sent to the roles, the roles do not consume resources, data is not required to be acquired in a polling mode, context switching under a thread environment is avoided, and the use of a CPU is reduced.
3. The role can only process one message request at a time, so no matter the role is an action message or a message requesting a certain response or state, the role is processed sequentially, and the role ensures that the instructions are processed according to the issuing sequence.
4. If one role is abnormal in the process of processing the service, the role can be automatically terminated or restarted, and other roles in the system cannot be influenced, so that the stability of the system is improved.
5. The role uses the invariable data, fundamentally eliminates the thread synchronization problem, reduces the complexity of the system and is beneficial to later maintenance and upgrading.
By using the event-driven model based on roles, the intelligent gateway background management system can realize the management capability of a large amount of intelligent hardware and ensure the running reliability of the system.
The following are specific examples of the present invention.
Example one
Fig. 1 is a flowchart of an intelligent gateway management method based on an event-driven model in this embodiment, where the event-driven model includes a multi-level role management directory, and the management method includes:
s1, searching an intelligent gateway role corresponding to the intelligent gateway when the intelligent gateway is in an online state;
before the step, after the system is started, a root node is automatically created, and the root node is used for creating an intelligent gateway role corresponding to the intelligent gateway.
In this step, when monitoring that the intelligent gateway is in an online state, the background management system starts to search the intelligent gateway role corresponding to the intelligent gateway according to the intelligent gateway serial number information.
And if the intelligent gateway role corresponding to the intelligent gateway cannot be found according to the serial number information of the intelligent gateway, creating a new intelligent gateway role.
S2, when the intelligent equipment managed by the intelligent gateway is in an online state, establishing an intelligent equipment role;
in the step, when monitoring that the intelligent equipment managed by the intelligent gateway is in an online state, the background management system creates an intelligent equipment role according to the serial number information of the intelligent equipment.
S3, receiving a control instruction sent by a user, and sending the control instruction to an intelligent device role;
in the step, after receiving a control instruction sent by a user, the background management system sends the control instruction to the role of the intelligent device.
And S4, the intelligent device role judges whether the control instruction is an executable instruction, if so, the intelligent device role sends the control instruction to the intelligent gateway role, and the intelligent gateway role sends the control instruction to the intelligent gateway.
In this step, the role of the intelligent device receives a user control instruction sent by a background management system, and judges whether the control instruction is an executable instruction according to the state of the intelligent device:
and if the control instruction is an executable instruction, the intelligent device role sends the control instruction to the intelligent gateway role, and the intelligent gateway role sends the control instruction to the intelligent gateway.
Fig. 2 is a structural diagram of an intelligent gateway management system based on an event-driven model in this embodiment, where the system includes:
the searching module 100 is configured to search, when the intelligent gateway is in an online state, an intelligent gateway role corresponding to the intelligent gateway;
a creating module 200, configured to create an intelligent device role when the intelligent device managed by the intelligent gateway is in an online state;
the forwarding module 300 is configured to receive a control instruction sent by a user, and send the control instruction to an intelligent device role;
the determining module 400 is configured to determine whether the control instruction is an executable instruction.
The creating module 200 is further configured to create a new role of the intelligent gateway when the role of the intelligent gateway corresponding to the intelligent gateway cannot be found according to the serial number information of the intelligent gateway.
The embodiment aims to solve the problem of system operation efficiency when the intelligent gateway background management system controls a large amount of intelligent hardware.
Example two
The present embodiment uses philips smart lamp business model to describe the detailed scheme of the first embodiment.
Fig. 3 is a diagram of a system role structure in this embodiment, and the system model corresponds to a tree structure.
In this embodiment, the hardware system is composed of an intelligent gateway, a philips network controller (hub), and a philips intelligent lamp.
After the system is started, a root node is automatically created, the name of the root node is super, the root node is responsible for creating roles of the intelligent gateway, and the path in the system is as follows: user/super.
After receiving the online information of the intelligent gateway, the intelligent gateway background management system searches the intelligent gateway role corresponding to the intelligent gateway in the root role according to the serial number of the intelligent gateway.
If not, a new intelligent gateway role is created, and the name of the intelligent gateway is as follows: gateway-SN value, the path in the system is: user/super/gateway-SN.
After the intelligent device managed by the intelligent gateway is on line, generating an intelligent device role under the intelligent gateway role according to the manufacturer serial number of the intelligent device, for example, the path of an intelligent lamp in the system is as follows: user/super/gateway-SN/led-SN.
Because the role is based on a message event-driven model, in order to control the action of the role, an event message needs to be sent to the role, and after the role receives the event message (onReceive method), the role processes according to the event type.
The intelligent gateway role is composed of the following message events:
1, OnLine: gateway online
And after receiving the online information of the intelligent gateway, the background management system sends the online information of the gateway to the role of the intelligent gateway.
And the role of the intelligent gateway generates or updates gateway objects in the database according to the SN in the background management system, such as creation time, latest online time, online state of the gateway, software version and the like, and finally returns the processing result of the online command of the intelligent gateway to the returned intelligent gateway, wherein the returned value needs to comprise the ID value (database table primary key) of the intelligent gateway in the background management system.
OffLine: gateway offline
And when the background management system is disconnected with the TCP connection channel of the intelligent gateway, sending a stop message to the role of the intelligent gateway.
And after receiving the stop message, the role of the intelligent gateway sends the stop message to all the roles of the intelligent equipment managed by the role of the intelligent gateway, and the intelligent gateway stops (stop method) after the stop message is completed to release resources.
The stop command is sent as follows:
DeviceOnLine: intelligent hardware on-line
After the intelligent hardware managed by the intelligent gateway is on line, different intelligent device roles are created in the intelligent gateway roles according to the setting types, and the intelligent device roles belong to children of the intelligent gateway roles.
The name of the role of the intelligent device is: device type-device SN.
For example, the network controller corresponds to the paths:
/user/supervisor/gateway-FXGW00000001/hub-00:17:88:01:02:31:a5-0b
OnLineRsp: replying to a message
After the background management system finishes processing the message sent by the intelligent gateway or the intelligent hardware, the background management system needs to send a processing result message to the intelligent gateway.
The messages are processed uniformly by the intelligent gateway role so as to ensure the sequentiality of command processing. After receiving the message, the intelligent gateway role stores the message in a message queue and processes the message in sequence.
DeviceSet: intelligent hardware control messages
And when the user manages the intelligent hardware through the mobile phone application program, the user sends the related command to the background management system.
After receiving a control instruction sent by a user, the background management system sends the control instruction to the role of the intelligent device specifically comprises the following steps:
(1) generating a path of the intelligent device role;
(2) and the control instruction stream is packaged into a control message, and the message is sent to the intelligent device role.
The role of the intelligent device judges whether the control instruction is an executable instruction:
if yes, the intelligent device role sends the control instruction to the intelligent gateway role, and the intelligent gateway role sends the control instruction to the intelligent gateway.
An example light-on process is as follows:
(1) role of sending light-on instruction to intelligent light
LED intelligent lamp
userId-handset user identifier
Power 1-on 0-off
(2) Judging the command in the role of the intelligent lamp, if the command is an executable command, handing the control command to the role of the intelligent gateway (equivalent to the father of the role of the intelligent lamp) for processing
getContext (). parent (). tell (new gateway actor. deviceset (instruction), this. getset ());
the instruction format is:
{"type":"set","commandId":4,"userId":"2","deviceId":"2","devData":{"power":"1"}}
it should be noted that in this embodiment, when the intelligent gateway role stops, all the intelligent device roles generated by it will automatically stop running, so as to release the resources.
The embodiment has the following advantages:
1) the memory consumption is reduced through roles, and the requirement on resources is easily met;
2) through an event trigger mechanism, the use amount of a CPU is reduced, and the throughput of system processing is improved;
3) and a thread model is cancelled, the complexity of the system is reduced, and the later maintenance and operation stability are achieved.
EXAMPLE III
The difference between this embodiment and the previous embodiment is that this embodiment further includes monitoring the state of the smart device role.
In this embodiment, the role of the intelligent gateway further includes the following message events:
terminating: smart device role termination message
And when the intelligent device role is created, monitoring the state information of the intelligent device role by using a monitoring method (watch).
When the monitored role of the intelligent device is abnormally terminated, a message is sent to the role of the intelligent gateway, and after the role of the intelligent gateway obtains the message, the role information of the intelligent device is obtained from a message body so as to be further processed.
In this embodiment, an intelligent gateway management method based on an event-driven model includes:
s1, searching an intelligent gateway role corresponding to the intelligent gateway when the intelligent gateway is in an online state;
s2, when the intelligent equipment managed by the intelligent gateway is in an online state, establishing an intelligent equipment role;
in this embodiment, step S2 further includes:
after the intelligent device role is established, starting state monitoring on the intelligent device role;
and when the role of the intelligent device is abnormal, sending a notification message to the role of the intelligent gateway.
S3, receiving a control instruction sent by a user, and sending the control instruction to an intelligent device role;
and S4, the intelligent device role judges whether the control instruction is an executable instruction, if so, the intelligent device role sends the control instruction to the intelligent gateway role, and the intelligent gateway role sends the control instruction to the intelligent gateway.
An intelligent gateway management system based on an event-driven model in this embodiment includes:
a lookup module 100;
a creation module 200;
a forwarding module 300;
a decision block 400.
Further comprising:
and the state monitoring module 500 is configured to start state monitoring on the role of the intelligent device after the role of the intelligent device is created.
According to the embodiment, the state of the intelligent device role is monitored, and the system stability can be effectively improved.
The specific embodiments described herein are merely illustrative of the spirit of the invention. Various modifications or additions may be made to the described embodiments or alternatives may be employed by those skilled in the art without departing from the spirit or ambit of the invention as defined in the appended claims.