Management of distributed conversation server (3)

Source: Internet
Author: User
Tags zookeeper
When a Memory object is added or deleted, all Mnemosyne objects need to be updated after Synchronization. You can use the Y () method to complete this task. Whether a write or take event occurs, Mnemosyne calls the notify () method of the listener for the event. In the synchronize () method, we register the local Mnemosyne as the listener for all the remote Mnemosyne take and write events. Once a take and write event occurs on the remote Mnemosyne, call the running y () method of the local Mnemosyne. Then, the local Mnemosyne must respond to the event. The following is an example of how Mnemosyne synchronizes with remote Mnemosyne:
Public void policy (RemoteEvent remoteEvent) throws RemoteException
{
// Write back the written memory, but no Mnemosyne notification is required.
If (remoteEvent instanceof WriteRemoteEvent)
{
WriteRemoteEvent wre = (WriteRemoteEvent) remoteEvent;
CommonContext. silentWrite (wre. getMemory ());
}
File: // get the written Memory, but no Mnemosyne notification is required.
If (remoteEvent instanceof TakeRemoteEvent)
{
TakeRemoteEvent tre = (TakeRemoteEvent) remoteEvent;
CommonContext. silentTake (tre. getMemory ());
}
}
Now you have created an Mnemosyne that controls all memory Objects. It is automatically synchronized with the remote Mnemosyne. If any remote Mnemosynes gets or loses a Memory object, can keep it up to date.
To manage HTTP dialogs through Mnemosyne, servlet needs to create an instance of HttpSession (use getSession () from HttpServletRequest) and encapsulate the conversation in the class that implements the Memory object, and call the write () method of the Mnemosyne object to write the encapsulation class to a Mnemosyne.
By calling the write () method, the Memory object of the conversation is encapsulated and sent to Mnemosyne along the network, and the remote machine is notified. When an object is written to Mnemosyne, WriteRemoteEvent is sent to all WriteRemoteEventListeners registered on Mnemosyne. In this way, all other Mnemosynes can add new objects as Mnemosynes to their conversation information repositories.
To query the stored dialog, the servlet calls the read () method to find the Memory object containing the dialog. If Mnemosyne finds the object to be searched, the object is returned to the servlet Server through RMI.
Finally, to delete the dialog, the servlet will call the take () method of Mnemosyne, and Mnemosyne will return the Memory object as if there was a read event, delete the Memory object from its storage object library. At the same time, send the TakeRemoteEvent event to all TakeRemoteEventListeners to notify all remote Mnemosynes that the Memory object has been deleted.
Create a dialog server
We have discussed how to maintain the dialog repository on multiple servers. Next we will discuss how to create a dialog server. During initialization, the dialog server completes the following tasks:
Zookeeper creates a local Mnemosyne object.
Zookeeper binds the local Mnemosyne to RMI.
Zookeeper synchronizes the local Mnemosyne with other remote Mnemosyne.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.