Management of distributed conversation servers (5)

Source: Internet
Author: User
Remote access to Mnemosyne
Next we will discuss how to access remote Mnemosyne on the servlet Server. To load an Mnemosyne that contains the conversation information without requiring a specific server to be online, you need to create a FailoverHandler instance. FailoverHandler uses the Proxy API in JDK 1.3 to handle the problem of the dialog server running on the machine. FailoverHandler takes a string array representing the rmi url used to access the remote conversation server as a parameter, and then obtains the Mnemosyne instance from the Proxy class. The initializeMnemosyne () method in the following SessionManager class shows how all of this is done:
Public static void initializeMnemosyne (String [] rmiURLs)
{
// Set the processing program on the server
FailoverHandler fh = new FailoverHandler (null, rmiURLs );
// Obtain an instance of Mnemosyne.
_ Mnemosyne =
(Mnemosyne) Proxy. newProxyInstance (Mnemosyne. class. getClassLoader (),
New Class [] {Mnemosyne. class },
Fh );
}
If you use the Proxy class to obtain the Mnemosyne instance, all method calls must be performed through the FailoverHandler's invoke () method. When there is a method to access Mnemosyne, FailoverHandler will try to call this method to access a remote object. If the method call fails (for example, if the server is shut down), FailoverHandler retrieves the next URL from the URL list provided to the constructor, and then seamlessly redirects to the next dialog server.
// Create a URL list for the remote loading class
Public FailoverHandler (Remote delegate, String [] delegateURLS)
{
This. delegateURLS = delegateURLS;
// If the URL is invalid, obtain the next valid URL.
Try {
This. delegate =
(Delegate = null )? GetNextValidDelegate (): delegate );
} Catch (RemoteException ex ){
// If a remote unexpected error occurs, the URL cannot be used. Send A // IllegalArgumentException event to the caller.
Throw new IllegalArgumentException ("Remote URLs cocould not"
+ "Be found ");
}
}
Public Object invoke (Object proxy,
Method method,
Object [] arguments)
Throws Throwable
{
While (true)
{
Try
{
File: // try to call the called method for the last obtained URL
Return method. invoke (delegate, arguments );
}
Catch (InvocationTargetException invocationTargetException)
{
File: // if the obtained URL is invalid, take the next URL

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.