Embodiment
Functional overview
Consider in the correlation technique to synchronous communication between implementation process and asynchronous communication and transform each other; System design complicacy and the problem that is not easy to safeguard, the embodiment of the invention provides a kind of interprocess synchronization communication implementation, on the basis of the original asynchronous communication means of reservation process; Through between two processes, increasing the sync agent unit; With the asynchronous communication seamless switching between the process is synchronous communication, has both needed interprocess asynchronous communication at some, needs the occasion of interprocess asynchronous communication again; Use this method can greatly reduce the exploitation amount and the maintenance work of module process; The module process can all be used asynchronous call when design, if need synchronization call on the business, only need to convert asynchronous call into synchronization call through agent unit and get final product.Therefore, it is clear to make that the module process structure upgrades, and the design of system is also simpler.
Need to prove that under the situation of not conflicting, embodiment and the characteristic among the embodiment among the application can make up each other.Below with reference to accompanying drawing and combine embodiment to specify the present invention.
Method embodiment
According to the embodiment of the invention, a kind of interprocess synchronization communication implementation method is provided at first.
Fig. 2 is the flow chart according to the interprocess synchronization communication implementation method of the embodiment of the invention.Wherein, between first process that intercoms mutually and second process, agent unit is set.As shown in Figure 2, comprise following processing (step S201-step S209) according to the interprocess synchronization communication implementation method of the embodiment of the invention:
Step S201: agent unit receives first request message that comes from first process, and first process is blocked, and wherein, first request message carries the identification information of first process;
Preferably, agent unit blocks first process and comprises: agent unit blocks first process through the synchronization of access interface; Above-mentioned synchronization of access interface is the interface that agent unit offers process.
Step S203: agent unit is according to first message constructing, second request message and be sent to second process, and wherein, second request message carries the private data information of sign agent unit, and private data information generates according to identification information;
Preferably, above-mentioned first request message can also carry following information: the identification information of second process, message data information, message-length information, message id information; Then comprise following processing according to first message constructing, second request message:
(1) agent unit obtains identification information, the identification information of second process, message data information, message-length information, the message id information that comes from first process in first request message;
(2) identification information with first process is generated as private data information;
(3) identification information, the identification information of second process, message data information, message-length information, the message id information with the private data information and first process is reassembled as second request message.
Step S205: agent unit receives and comes from first response message that second process is returned, and recovers identification information according to the private data information that first response message carries;
Step S207: agent unit is constructed second response message according to first response message, and is sent to first process, and wherein, second response message carries identification information;
Preferably, above-mentioned first response message comprises: response message data message, response-message length information, private data information; Then construct second response message and comprise following processing according to first response message:
(2) obtain response message data message, response-message length information, private data information in first response message;
(2) private data information is reverted to the identification information of first process;
(3) identification information, response message data message, the response-message length information sets of first process are synthesized second response message.
Step S209: agent unit is removed first process and is stoped.
Preferably, above-mentioned agent unit is removed first process through the synchronization of access interface and is stoped.
Through the execution of step S202-step S209, can realize the synchronous communication between first process and second process, through increasing the processing of agent unit, can simplified system design, be easy to carry out system maintenance.
Fig. 3 passes through the sequential chart that proxy module is realized synchronous communication according to the preferred embodiment of the invention between the process (process A and process B).As shown in Figure 3, mainly may further comprise the steps (step S301-step S313):
Step S301: module process A (being equivalent to first process) constructs a message M1; Be used for module process B alternately, wherein, comprise among the message M1: the sign of module process A; The discernible message id of module process B; The discernible message data of module process B (being equivalent to second process), message-length, the sign of module process B.
Step S303: module process A is a parameter with the message of step S301, the SyncAccess interface (being synchronization of access interface above-mentioned) of visit SYNC_PROCXY (and agent unit above-mentioned).
Further, in the SyncAccess interface, the message M1 with module process A structure among the step S301 sends to sync agent module SYNC_PROXY with asynchronous system, and afterwards, the SyncAccess interface is blocked on the waiting list QUEUE_A module process A.
After step S305:SYNC_PROXY receives the message M1 of step S303; Take out the sign of message id in M1 message, message data, message-length, module process B; Simultaneously; SYNC_PROXY is with private data X of sign structure of module process A, and SYNC_PROXY is dealt into module process B with message M3 with asynchronous system according to sign and these five parametric configuration message M3 of private data X of message id, message data, message-length, module process B.
After step S307, module process B receive the message M3 that SYNC_PROXY sends among the step S305, take out message id, message data, message-length in the message, carry out handled; After finishing dealing with, process B constructs a response message M3, and wherein, this response message M3 comprises: private data X, and the response message data, response message length, module process B sends to proxy module SYNC_PROXY with response message M3 with asynchronous system.
After step S309:SYNC_PROXY receives the response message M3 of step S307 module process B transmission, take out: private data X, response message data, response message length.Afterwards; SYNC_PROXY restores the sign of module process A according to private data X; Afterwards; SYNC_PROXY sends to M4 the waiting list QUEUE_A of module process A with identifier, response message data, these three parametric configuration message M4 of response message length of module process A with asynchronous system.
Step S311: after the waiting list QUEUE_A of module process A receives the response message M4 of SYNC_PROXY, unblocking at once, afterwards, the SyncAccess interface makes module process A from waiting list, take out response message M4.
Step S313: module process A returns from the SyncAccess interface, and the response message M4 that obtains with step S311 handles.
So far, a Synchronous Processing flow process of asking module process B to reply from module process A finishes.
Fig. 4 is certain sequential chart in the asynchronous interactive process between process according to the preferred embodiment of the invention.Wherein, ClientP (being equivalent to first process) is to ServerP (being equivalent to second process) synchronization request ServiceData, and is as shown in Figure 4, comprises following processing (step S401-step S411) through proxy module SYNC_PROXY reciprocal process:
Step S401:ClientP is to ServerP initiation request 11, desires synchronization request business datum ServiceData, but ClientP is directly to the ServerP request, but called the SyncAccess (synchronization of access interface) of SYNC_PROX (agent unit);
The SyncAccess interface of step S403:SYNC_PROXY arrives SYNC_PROXY with request 11 asynchronous transmissions of ClientP, and simultaneously, the SyncAccess interface makes ClientP block wait synchronously on QUEUE_Client;
After the step S405:SYNC_PROXY request of receiving 11, according to parameter and the request content in the request 11, the request of re-assemblying 22, SYNC_PROXY will ask 22 asynchronous transmissions to ServerP;
The step S407:ServerP request of receiving 22 is handled it, after finishing dealing with, assembles out the reply data of band ServiceData: reply 22 '; ServerP will reply 22 ' and send to SYNC_PROXY with asynchronous system;
After step S409:SYNC_PROXY received and replys 22 ', parameter and response content according to replying in 22 ' re-assemblied and reply 11 ', reply 11 ' and have comprised ServiceData.SYNC_PROXY will reply the QUEUE_Client of 11 ' asynchronous transmission to ClientP.
The QUEUE_Client of step S411:ClientP receives and replys 11 ', unblocking, and SyncAccess takes out and to reply 11 ', and ClientP is to reply ServiceData processing in 11 '.
Through the foregoing description, a kind of interprocess synchronization communication implementation method is provided, on the basis of the original asynchronous communication means of reservation process,, be synchronous communication with the asynchronous communication seamless switching between the process through between two processes, increasing the sync agent module.Thereby can simplified system design, and be easy to safeguard.
Device embodiment
According to the embodiment of the invention, a kind of agent unit is provided also.
Fig. 5 is the structured flowchart according to the agent unit of the embodiment of the invention.Fig. 6 is the structured flowchart of agent unit according to the preferred embodiment of the invention.As shown in Figure 5; Agent unit according to the embodiment of the invention comprises: first receiving element 1, stop module 2, first constructing module 3, first sending module 4, second receiver module 5, second constructing module 6, second sending module 7, remove and stop module 8, describe below in conjunction with Fig. 6.
First receiver module 1 is used to receive first request message that comes from first process, and wherein, first request message carries the identification information of first process;
Stop module 2, be connected, be used for first process is stoped with first receiver module 1;
First constructing module 3 is connected with stoping module 2, is used for according to first message constructing, second request message, and wherein, second request message carries the private data information of sign agent unit, and private data information generates according to identification information;
Preferably; As shown in Figure 6; First constructing module 3 comprises: first obtains submodule 30, generation submodule 32, the first recon module 34; Wherein, first obtains submodule 30, is used for obtaining identification information, the identification information of second process, message data information, message-length information, the message id information of first process that comes from first request message; Generate submodule 32, be used for the identification information of first process is generated private data information; The first recon module 34 is used for identification information, the identification information of second process, message data information, message-length information, the message id information of the private data information and first process are reassembled as second request message.
First sending module 4 is connected with first constructing module 3, is used for second request message is sent to second process;
Second receiver module 5 comes from first response message that second process is returned with being used to receive, and wherein, first response message carries private data information;
Second constructing module 6 is used for constructing second response message according to first response message;
Preferably; As shown in Figure 6; Second constructing module 6 comprises: second obtains submodule 60, recovery submodule 62, the second recon module 64; Wherein, second obtains submodule 60, is used for obtaining response message data message, response-message length information, the private data information of first response message; Recover submodule 62, be used for the identification information of first process that private data information is reverted to; The second recon module 64 is used for synthetic second response message of identification information, response message data message, response-message length information sets with first process.
Second sending module 7 is used for second response message is sent to first process, and wherein, second response message carries the identification information that recovers according to private data information;
Remove prevention module 8, be used for first process is removed prevention.
Preferably, above-mentioned prevention module 2 stops module 8 all can be the synchronization of access interface of agent unit with removing.
Preferably, first receiver module 1, second receiver module 5 receive message through asynchronous system; First sending module 4, second sending module 7 send message through asynchronous system.
Through the foregoing description, a kind of agent unit is provided, interact through each intermodule of this agent unit, can implementation process between asynchronous communication transfer the purpose of synchronous communication to.The module process can all be used asynchronous call when design, if need synchronization call on the business, only need to convert asynchronous call into synchronization call through proxy module and get final product.Thereby it is clear to make that the module process structure upgrades, and the design of system is also simpler.
In sum, through the above embodiment of the present invention, the interprocess synchronization communication implementation that provides interacts through each intermodule of this agent unit, can implementation process between asynchronous communication transfer the purpose of synchronous communication to.The module process can all be used asynchronous call when design, if need synchronization call on the business, only need to convert asynchronous call into synchronization call through proxy module and get final product.Thereby it is clear to make that the module process structure upgrades, and the design of system is also simpler.And both needed interprocess asynchronous communication at some, needed the occasion of interprocess asynchronous communication again, and can greatly reduce the exploitation amount and the maintenance work of module process.
Obviously, it is apparent to those skilled in the art that above-mentioned each module of the present invention or each step can realize with the general calculation device; They can concentrate on the single calculation element; Perhaps be distributed on the network that a plurality of calculation element forms, alternatively, they can be realized with the executable program code of calculation element; Thereby; Can they be stored in the storage device and carry out, perhaps they are made into each integrated circuit modules respectively, perhaps a plurality of modules in them or step are made into the single integrated circuit module and realize by calculation element.Like this, the present invention is not restricted to any specific hardware and software combination.
The above is merely the preferred embodiments of the present invention, is not limited to the present invention, and for a person skilled in the art, the present invention can have various changes and variation.All within spirit of the present invention and principle, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.