Influence of RMI spy on program running (RMI plug-in of eclipse)

Source: Internet
Author: User

This document describes the impact of using RMI spy on the execution of your application.

In most cases, you will not notice any difference during program execution. However, if your program is not executed as expected, you will realize that RMI spy can help you debug the program. This is a technical document, not an Rmi spy help document.

1. What is RMI spy?
RMI spy collects and displays RMI-related events generated when your application is running. Specifically, it monitors all remote calls (including external calls generated by your application and remote services provided by other applications ). It can also display class loading events to help you debug "class loading" problems, which usually occur during RMI system development.

2. How does RMI spy work?
I) Introduction:
RMI spy is based on the logging API, which is used by RMI APIs. If the RMI spy is not enabled, You can manually enable the "logging properties" (you can select enable in the RMI run configuration "RMI launch" tab) and the console window for monitoring the output.

For example, open the "Java. RMI. server. logcils" attribute to generate a line break similar to the following output (for clear display ):

20/05/2006 13:35:06 sun.rmi.server.UnicastServerRef logCallFINER: RMI TCP Connection(2)-192.168.2.100: [192.168.2.100: \       demo.rmi.print.server.RemotePrinterImpl[1]: \       public abstract int demo.rmi.print.server.RemotePrinter.submitJob( \           java.lang.String) throws java.rmi.RemoteException]

This output is not conducive to reading, nor does it provide any meaningful information.


Ii) RMI spy Interface

RMI spy does not analyze program output (although theoretically it can be analyzed), because this method is not reliable-program output may interfere with RMI logs. Instead, it is connected to the RMI log system and can be captured in time when an event is generated. RMI spy running component (run as part of the application) using the log API (logging API) to register its own proxy to collect RMI events and push them to the RMI plug-in for analysis and display them in the RMI spy view.

To avoid modifying the application code, RMI spy uses a launch wrapper ). This means that the running component of RMI spy runs inside your program (the premise is that RMI spy is activated ). After the application starts, RMI spy jar will be added to classpath. Launch wrapper (class net. genady. RMI. Logger. Runner) will be used as the main class ). The main classes and parameters of the application are passed to launch wrapper as parameters.

Launch wrapper is responsible for hosting the logging handlers, establishing a TCP connection with the RMI plug-in, and passing control to the real application. Obviously, running wrapper in the same VM process simultaneously has an impact on your application.
The details of these impacts will be discussed in the next section.

Iii) use of the instrument)
The RMI plug-in uses bytecode instruments (ASM Library) to perform advanced functions (such as time measurement ). It will not have any special impact on your program, because it only executes a few System Classes. It should be noted that the RMI plug-in must use JDK or JDK 1.6 (if the version is incorrect, the plug-in will be automatically disabled), which means that if you use your own instrument tool (-javaagent) you need to be more careful. Of course, in most cases, this is not a problem.

RMI spy calls some methods of some objects. These objects are passed as parameters or return values during Remote calls. In the following classes, it will call the tostring () method: All original types, encapsulation classes, ruls and Uris, inetaddress, enumeration types, character sequences (charsequence) and number class subclass. It also calls the size () method in the collection implementation. The call of these methods will produce unexpected side effects, such as obtaining Locks/monitors and creating network connections.

3. The running mode and debugging mode are different.
RMI spy does not use the debugging API. Therefore, there is no difference between RMI spy operations in running and debugging modes.

4. Supported JDK/JVM providers
RMI spy depends on Sun's internal APIs. However, many JDK providers running RMI are licensed by Sun. Therefore, most standard JVMs can run RMI spy. To obtain the latest compatibility list, visit the website

5. Stack Tracing
RMI spy uses a simple start package to run some configurations, and then passes control to your main class through reflection APIs ). Therefore, all stack traces generated in the main thread will have the following lines of prompts (assuming your main class is demo. RMI. Print. Client. printclient ):

at demo.rmi.print.client.PrintClient.main(PrintClient.java:35)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(                             NativeMethodAccessorImpl.java:39)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(                             DelegatingMethodAccessorImpl.java:25)   at java.lang.reflect.Method.invoke(Method.java:324)   at net.genady.rmi.logger.Runner.main(Runner.java:138)

Stack tracing is generated in other threads without any impact.

6. Auxiliary threads
The application communicates with the RMI plug-in through a local TCP connection. Although it is a local connection, it may still be blocked for various reasons (such as local firewall ). Therefore, if an event is to be sent to the RMI plug-in, the running component will put the event in the event queue, and the dedicated daemon thread will execute all the communication work. In this way, the application thread will never be blocked by the RMI plug-in, and the impact on the application will be minimized. The name of this dedicated daemon thread is "RMI plug-in for eclipse log events Reporter". In most cases, it is idle.

7. Close the hook (a shutdown hook)
It is common for an application to end execution by calling the system. Exit () or similar method. In this case, the running component of RMI spy must ensure that all collected events have been transmitted to the RMI spy part running in eclipse. For this purpose, the RMI plug-in uses the "shutdown hooks" function. Therefore, this may take a long time to close an application (until all applications are transferred ). Generally, this process takes several milliseconds, but for RMI-intensive programs, this process will take 10 to 100 milliseconds until the program ends.

8. Use the logging properties of RMI)
RMI spy does not directly use any logging attribute, so you can enable them to view normal console-based logs. However, setting certain attributes, such as "Sun. RMI. server. suppressstacktraces", will cause RMI spy to lose some information. Therefore, it is recommended that RMI spy be used to display the log information, so you should avoid directly modifying these log attributes.

9. Use the log API

(This requires more technology and knowledge about logging APIs.) RMI spy changes the logging level of RMI loggers to "all ". You cannot see the RMI log on the console because the RMI log controller has a higher level (the default is "silent "). If the log controller level is modified for some reason, or another controller is registered with the RMI log, they will get the events they would not have obtained (if RMI
If spy is not used ). Of course, if you manually modify the RMI log level, you can influence the behavior of RMI spy.

Http://www.genady.net/rmi/v20/docs/spy/spy_effects.html.

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.