Tinyrmi---RMI package, expansion, and stepped pits solution

Source: Internet
Author: User

In the parallel calculation of tiny, referring to the remote method call project, which is said here Tinyrmi, at that time when writing test cases, just in a single test, all well, but dawn in use, in the multi-machine trial, the result of a problem, and finally spent less than one week, Solved the problem that dawn discovered, finally solved the problem, also discovered some pits in RMI. Perhaps some people have passed, some people if not met, may also fall the same pit, so it is written, readers, avoid the same when.

This article is inseparable from the formation of Dawn in-depth testing and analysis, in this expressed deep gratitude!

Functional Requirements

Expect a certain encapsulation of RMI in the JDK to provide the following features:

    • Support for local object registration and logoff
    • Supports remote object registration and logoff
    • Support for wire break re-connection
      The connection is disconnected due to a network failure and can continue to normal access after the network failure is restored
      Because the rmiserverlocal stops, after restarting, the client registers the object to continue to have normal access
      After restarting, the client registration object needs to be re-registered because Rmiserverremote stopped.
    • Support Object Validation
      If some objects have been invalidated, the server can remove it from the registry to prevent others from getting the failed object


Interface design

075159_d7o2_1245989.png (29.68 KB, download number: 0)

Download attachments

2015-5-26 22:45 Upload

You can see that Rmiserver is an interface that inherits the serializable and remote interfaces, and it provides several methods for registering objects and de-registering objects. There are, of course, some helper methods that look very simple.

There is also a secondary interface verifiable, for the joined remote object, if implemented this interface, you can validate its validity, if it has been invalidated, will be automatically removed from the registration.

    1. /**
    2. * Is it possible to verify that the class that implements this interface can be verified
    3. */
    4. public interface Verifiable {
    5. /**
    6. * Check, if the check does not appear an exception, it means OK
    7. *
    8. * @throws RemoteException
    9. */
    10. void verify () throws RemoteException;
    11. }
Copy Code

Of course, to add to the rmiserver, there must be a certain constraint, so set the interface RemoteObject

    1. Public interface RemoteObject extends Serializable, Remote {
    2. }
Copy Code

OK, so far, the interface is even finished.
Code implementation

The first version of the code implementation, I imagined very simple, how to get registry as an abstract method implemented by subclasses, the others are for the operation of Registry, placed in the abstract class implementation, minutes to write, and then local test pass, complacent, but still do not know that a serious mistake .....

In a stand-alone environment, testing is good, whether it is RMI's own test case or the reuse of its parallel computing engineering.

But dawn in use, using the Linux machine two physical machines for testing, the problem occurred, the error message is as follows:

    1. Java.rmi.AccessException:Registry.Registry.bind disallowed; Origin/192.168.xxx.xxx is non-local host
Copy Code

We test with two physical computers, and we have the same problem.

So Baidu, Google are used, find finally found the reason:

Registry only local can modify the registry, remote only for viewing.

So the rmiserverlocal as a remote object to provide, let rmiserverremote to call, thought this is always OK?? But it still doesn't work, it's the same problem.

Carefully read the Javadoc documentation and find some of the materials, it is understood that the bind process can only be executed in the machine where the rmiserverlocal, even through the remote service invocation, it is considered to be called in the rmiserverremote ... This Nima, this RMI is so difficult to use, the designers know?

This improvement, when the remote machine was registered, was simply added to a queue in rmiserverlocal, and then a scanning thread was opened on the machine where the rmiserverlocal was located to perform the bind,unbind operation, so that the total guarantee was executed in local.

Test it, really OK ... Not happy half-down, Dawn newspaper came, and problems.

Windows is OK for Server,linux as a client, but Linux does not work as long as it is server-side.

Continue to find the reason, see the data is because the Linux lookup to IP and external access to the IP does not cause the need to modify the/etc/hosts file in the 127.0.0.1 to the external IP address.

After the modification, the problem is resolved.

Testing process

After a preliminary run, there are a variety of tests and questions to follow.

Because of the asynchronous registration relationship, the registered object can be accessed for a short period of time after the registration time.

There are object access conflicts, and so on, and so on, in short, is measured change, changed the test, finally corrected, finally there is a stable version of the available.

Finally, because the original idea of the code shared basically no reuse of value, so rmiserverlocal and Rmiserverremote are the respective implementations, no longer have a common base class.

Experience Summary

    • The test case must be written with sufficient coverage.
    • Related to the network aspects of the test, not only in the local test pass can be, must be tested with the real environment.
    • Different operating system processing or there are some differences, do not be too superstitious Java to write all over the place, the fact is that everywhere can run, in most cases can also be run correctly, but some external conditions, may lead to failure.

About RMI:

    • If the client only calls the server-side provided object, then it is very simple.
    • If the client is also registering the remote object with the server, then it needs to be asynchronous to get the registration or logoff queue.

The code itself is not complicated, the students need to see the source code yourself.

Https://git.oschina.net/tinyframework/tiny/tree/master/framework/org.tinygroup.rmi

Tinyrmi---RMI package, expansion, and stepped pits solution

Related Article

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.