Embodiment
In order to make object of the present invention, technical scheme and advantage clearer, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
The embodiment that the embodiment of the present invention provides is as follows:
Refer to Fig. 1 to Fig. 4, the embodiment of the present invention provides a kind of communicator of cross-platform flexible bus, and described device comprises:
Communication thread unit 101, for safeguarding two different connections of two net identical services ports;
Thread pool container 102, for the Manage Containers as described communication thread unit;
Data queue's buffer unit 103, the data queue receiving for buffer memory and the data queue of transmission;
Connect processor 104, for data queue described in preliminary treatment;
Service adapter 105, for sort out two different connections of described pair of net identical services port and when the network segment Network Abnormal assisted network switch.
In the present embodiment, in communication thread unit 101, communication thread is divided into two large classes, three groups, i.e. 2 large classes of TCP thread and UDP thread, TCP service role, TCP client role and 3 groups of UDP thread.Each thread is responsible for safeguarding two different connections (TCP thread) of two net identical services ports.
In the present embodiment, thread pool container 102, as the Manage Containers of all kinds communication thread, or claims thread management person.Thread pool container 102 is responsible for communication thread as management roles such as TCP thread and UDP thread create, destroy, inquire about, dispatch, reuse, recovery.Thread pool container 102 be also flexible bus with the interactive interface of other software modules, with flexible bus, the interface by thread pool container 102 opening carries out other modules.Thread pool container 102, divides work thread pool and two thread pools of buffer memory thread pool by thread pool; Worker thread pond is the thread container of ongoing communication work, and buffer memory thread pool is standby thread container; When having new connection to set up, the its respective thread in described buffer memory thread pool is dispatched in described worker thread pond, when having the disconnection of connection, discharges its respective thread in described worker thread, and the thread of release is recovered as to buffer memory thread, be dispatched in described buffer memory thread pool.
In the present embodiment, data queue's buffer unit 103, as each, connect pending data buffer storage pond, for buffer memory, receive data queue and send data queue, data queue's buffer unit 103 sends buffering and receives buffering similar with TCP, by buffer memory, received data queue and sent data queue, can guarantee in data peak not can be because the deficiency of temporary transient data-handling capacity be on the impact of data communication or obliterated data.
In the present embodiment, connect processor 104, specifically for the data preliminary treatment that data queue is safeguarded, operated, the direct manager of data queue namely.
In the present embodiment, data are divided into two kinds of types of service, when same third party's system communication, adopt not with the data type of heading, adopt the data type with heading in built-in system.In built-in system, adopt the data type with heading to contribute to prevent the interference of invalid data to system, guarantee the legitimacy of connection, when having illegal connection, will be disconnected.
In the present embodiment, service adapter 105 is specially for supporting two Network Communications to arrange.
Described communication thread unit adopts ACE Overpassing Platform by Using technology.
In the present embodiment, described communication thread unit 101 comprises externally provides the XPCOM of interface assembly.
In the present embodiment, described device also comprises:
Heartbeat detection unit, for sending self-defined heartbeat message, when not receiving in the given time response message or normal communication data packet, re-establishes and connects or handover network.
In the present embodiment, the communicator of cross-platform flexible bus is specially the communicator of the cross-platform flexible bus under C/C++ language.
The communicator of the cross-platform flexible bus of the present embodiment, adopts ACE Overpassing Platform by Using technology.Utilize ACE Overpassing Platform by Using characteristic, more complicated for ACE mechanism, skilled grasp, the more difficult feature of use, adopt Object-oriented Technique to encapsulate it again, again reduces and use complexity.
The communicator of the cross-platform flexible bus of the present embodiment, adopts thread pool.ACE not only encapsulates Overpassing Platform by Using socket programming, also makes this concept of thread carry out on each platform abstract, makes the programming of multithreading can be very simple.Even also can move this multi-threaded code on the platform of not supporting thread.The management that socket is connected adopts thread pool mode supervisory communications thread units 101 with the communication port between other modules, there is the management of thread pool container 102, socket network service resource just can well be managed, and avoids causing due to error the phenomenon of the wasting of resources.
The communicator of the cross-platform flexible bus of the present embodiment, adopts the cross-platform component technology of XPCOM.XPCOM is a cross-platform component model, and its full name is Cross Platform Component Object Module.XPCOM has realized a framework (framework), and in this framework, it allows developer to break single holistic software project, and is decomposed into a plurality of less modularization fragments (pieces), and these fragments are also assembly (components).XPCOM assembly externally provides interface, for XPCOM interface, need to consider 2 factors:
(1), interface and programming according to contract (Contract) a: interface is reached contract between assembly and CLIENT PROGRAM.Do not have any compulsory measure and guarantee this contract of approval, but it can be fatal ignoring it.In the programming based on assembly, assembly guarantees that the interface that it provides is constant.The assembly of different editions all will provide same access method.This has just reached a kind of contract with using its CLIENT PROGRAM. and from this angle, the programming based on assembly is conventionally also referred to as programming according to contract.
(2) interface and encapsulation: abstract between assembly border is vital to the maintainability of software and reusability.
The communicator of the cross-platform flexible bus of the present embodiment, adopts Object-oriented Technique, utilizes OO three essential characteristics (encapsulation, succession, polymorphic) can make software realize object and the benefit of easy care, high-quality, high efficiency, easily expansion.The Object-oriented Technique simultaneously also all adopting due to ACE and XPCOM, is the condensate of an Object-oriented Technique so flexible bus employing Object-oriented Technique also can make flexible bus from general frame, and implementation structure is clear, the effect that code is clean and tidy.
The communicator of the cross-platform flexible bus of the present embodiment, supports two network technologies.Electric power software is monitoring software particularly, in order to guarantee communication reliability, conventionally adopts two planar network architectures.The two nets of flexible bus support just can guarantee that program module seamlessly switches to another network segment operation in the situation that of a network segment paralysis, lost data packets not, thereby assurance communication reliability.
The communicator of the cross-platform flexible bus of the present embodiment, utilizes heartbeat detection unit.Can judge whether TCP connects stable, in passage idle, sends self-defined heartbeat, the other side receives rear horse back reply heartbeat.If fail to receive the other side's heartbeat message or proper communication packet in official hour section, judge that this connection breaks, automatically re-establish and connect or switch the network segment.
The communicator of the cross-platform flexible bus of the present embodiment, adopts Double Data type-scheme.Data type, as internal system data, is with internal data heading (two nets are supported in internally communication); Another kind of data type, as same third party's communication data form (correspondence with foreign country is not supported two nets), is not with data message head, and this determines after connecting foundation.
The communicator of the cross-platform flexible bus of the present embodiment, can be applied to following scene: the communication middleware between each service module of automation system for the power network dispatching main station system; Communication middleware between each service module of electrical power distribution automatization system main station system; Communication middleware between each service module of electric substation automation system main station system; Communication middleware between each service module of concentrator station main station system; Communication middleware between each service module of other supervisory control systems.
The communicator of the cross-platform flexible bus of the present embodiment, can be used as dynamic base is deployed on server or PC together with systems soft ware, when systems soft ware need to carry out network service, to flexible bus request, create network and connect, to the thread management person's request scheduling thread in flexible bus and carry out corresponding connection and process.
The communicator of the cross-platform flexible bus that the present embodiment provides, adopt component technology, blocking technology and Object-oriented Technique, form with dynamic base offers developer and running environment, thereby realize to solve in electric power software unit development process for the cross-platform of communication function and reuse the object that requires problem.Cross Platform Technology guarantees that software can move under mixing platform environment.
The communicator of the cross-platform flexible bus that the present embodiment provides, user only need to use the interface that software externally provides just can carry out easily network programming, by work such as communication fault-tolerant processing, give flexible bus inter-process, guarantee can not reduce because communication reason causes robustness.
The embodiment of the present invention also provides a kind of flexible bus, and described flexible bus comprises above-mentioned device.
Fig. 5 has illustrated flexible bus that the present embodiment the provides deployed position in software architecture, flexible bus is deployed on server or PC together with systems soft ware as dynamic base, when systems soft ware need to carry out network service, to flexible bus request, create network and connect, to the thread management person's request scheduling thread in flexible bus and carry out corresponding connection and process.
The communicator of cross-platform flexible bus of the present invention and flexible bus, by communication thread unit, thread pool container, data queue's buffer unit, connection processor, service adapter, realized the unitized of communication mode, is easy to safeguard.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, all any modifications of doing within the spirit and principles in the present invention, be equal to and replace and improvement etc., within all should being included in protection scope of the present invention.