Java Doc for VirtualMachine.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » attach » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » tools » com.sun.tools.attach 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.tools.attach.VirtualMachine

VirtualMachine
abstract public class VirtualMachine (Code)
A Java virtual machine.

A VirtualMachine represents a Java virtual machine to which this Java virtual machine has attached. The Java virtual machine to which it is attached is sometimes called the target virtual machine, or target VM. An application (typically a tool such as a managemet console or profiler) uses a VirtualMachine to load an agent into the target VM. For example, a profiler tool written in the Java Language might attach to a running application and load its profiler agent to profile the running application.

A VirtualMachine is obtained by invoking the VirtualMachine.attach(String) attach method with an identifier that identifies the target virtual machine. The identifier is implementation-dependent but is typically the process identifier (or pid) in environments where each Java virtual machine runs in its own operating system process. Alternatively, a VirtualMachine instance is obtained by invoking the VirtualMachine.attach(VirtualMachineDescriptor) attach method with a com.sun.tools.attach.VirtualMachineDescriptor VirtualMachineDescriptor obtained from the list of virtual machine descriptors returned by the VirtualMachine.list list method. Once a reference to a virtual machine is obtained, the VirtualMachine.loadAgent loadAgent , VirtualMachine.loadAgentLibrary loadAgentLibrary , and VirtualMachine.loadAgentPath loadAgentPath methods are used to load agents into target virtual machine. The VirtualMachine.loadAgent loadAgent method is used to load agents that are written in the Java Language and deployed in a java.util.jar.JarFile JAR file . (See java.lang.instrument for a detailed description on how these agents are loaded and started). The VirtualMachine.loadAgentLibrary loadAgentLibrary and VirtualMachine.loadAgentPath loadAgentPath methods are used to load agents that are deployed in a dynamic library and make use of the JVM Tools Interface.

In addition to loading agents a VirtualMachine provides read access to the java.lang.System.getProperties system properties in the target VM. This can be useful in some environments where properties such as java.home, os.name, or os.arch are used to construct the path to agent that will be loaded into the target VM.

The following example demonstrates how VirtualMachine may be used:

 // attach to target VM
 VirtualMachine vm = VirtualMachine.attach("2177");
 // get system properties in target VM
 Properties props = vm.getSystemProperties();
 // construct path to management agent
 String home = props.getProperty("java.home");
 String agent = home + File.separator + "lib" + File.separator 
 + "management-agent.jar";
 // load agent into target VM
 vm.loadAgent(agent, "com.sun.management.jmxremote.port=5000");
 // detach
 vm.detach();
 

In this example we attach to a Java virtual machine that is identified by the process identifier 2177. The system properties from the target VM are then used to construct the path to a management agent which is then loaded into the target VM. Once loaded the client detaches from the target VM.

A VirtualMachine is safe for use by multiple concurrent threads.


since:
   1.6



Constructor Summary
protected  VirtualMachine(AttachProvider provider, String id)
     Initializes a new instance of this class.

Method Summary
public static  VirtualMachineattach(String id)
     Attaches to a Java virtual machine.

This method obtains the list of attach providers by invoking the com.sun.tools.attach.spi.AttachProvider.providersAttachProvider.providers() method.

public static  VirtualMachineattach(VirtualMachineDescriptor vmd)
     Attaches to a Java virtual machine.

This method first invokes the com.sun.tools.attach.VirtualMachineDescriptor.provider provider() method of the given virtual machine descriptor to obtain the attach provider.

abstract public  voiddetach()
     Detach from the virtual machine.

After detaching from the virtual machine, any further attempt to invoke operations on that virtual machine will cause an java.io.IOExceptionIOException to be thrown.

public  booleanequals(Object ob)
     Tests this VirtualMachine for equality with another object.

If the given object is not a VirtualMachine then this method returns false.

abstract public  PropertiesgetAgentProperties()
     Returns the current agent properties in the target virtual machine.

The target virtual machine can maintain a list of properties on behalf of agents.

abstract public  PropertiesgetSystemProperties()
     Returns the current system properties in the target virtual machine.

This method returns the system properties in the target virtual machine.

public  inthashCode()
     Returns a hash-code value for this VirtualMachine.
final public  Stringid()
     Returns the identifier for this Java virtual machine.
public static  List<VirtualMachineDescriptor>list()
     Return a list of Java virtual machines.
abstract public  voidloadAgent(String agent, String options)
     Loads an agent.

The agent provided to this method is a path name to a JAR file on the file system of the target virtual machine.

public  voidloadAgent(String agent)
     Loads an agent.
abstract public  voidloadAgentLibrary(String agentLibrary, String options)
     Loads an agent library.

A JVM TI client is called an agent.

public  voidloadAgentLibrary(String agentLibrary)
     Loads an agent library.
abstract public  voidloadAgentPath(String agentPath, String options)
     Load a native agent library by full pathname.

A JVM TI client is called an agent.

public  voidloadAgentPath(String agentPath)
     Load a native agent library by full pathname.
final public  AttachProviderprovider()
     Returns the provider that created this virtual machine.
public  StringtoString()
     Returns the string representation of the VirtualMachine.


Constructor Detail
VirtualMachine
protected VirtualMachine(AttachProvider provider, String id)(Code)
Initializes a new instance of this class.
Parameters:
  provider - The attach provider creating this class.
Parameters:
  id - The abstract identifier that identifies the Java virtual machine.
throws:
  NullPointerException - If provider or id is null.




Method Detail
attach
public static VirtualMachine attach(String id) throws AttachNotSupportedException, IOException(Code)
Attaches to a Java virtual machine.

This method obtains the list of attach providers by invoking the com.sun.tools.attach.spi.AttachProvider.providersAttachProvider.providers() method. It then iterates overs the list and invokes each provider's com.sun.tools.attach.spi.AttachProvider.attachVirtualMachine(java.lang.String)attachVirtualMachine method in turn. If a provider successfully attaches then the iteration terminates, and the VirtualMachine created by the provider that successfully attached is returned by this method. If the attachVirtualMachine method of all providers throws com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException then this method also throws AttachNotSupportedException. This means that AttachNotSupportedException is thrown when the identifier provided to this method is invalid, or the identifier corresponds to a Java virtual machine that does not exist, or none of the providers can attach to it. This exception is also thrown if com.sun.tools.attach.spi.AttachProvider.providersAttachProvider.providers() returns an empty list.


Parameters:
  id - The abstract identifier that identifies the Java virtual machine. A VirtualMachine representing the target VM.
throws:
  SecurityException - If a security manager has been installed and it deniescom.sun.tools.attach.AttachPermission AttachPermission("attachVirtualMachine"), or another permissionrequired by the implementation.
throws:
  AttachNotSupportedException - If the attachVirtualmachine method of all installed providers throws AttachNotSupportedException, orthere aren't any providers installed.
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If id is null.



attach
public static VirtualMachine attach(VirtualMachineDescriptor vmd) throws AttachNotSupportedException, IOException(Code)
Attaches to a Java virtual machine.

This method first invokes the com.sun.tools.attach.VirtualMachineDescriptor.provider provider() method of the given virtual machine descriptor to obtain the attach provider. It then invokes the attach provider's com.sun.tools.attach.spi.AttachProvider.attachVirtualMachine(VirtualMachineDescriptor)attachVirtualMachine to attach to the target VM.
Parameters:
  vmd - The virtual machine descriptor. A VirtualMachine representing the target VM.
throws:
  SecurityException - If a security manager has been installed and it deniescom.sun.tools.attach.AttachPermission AttachPermission("attachVirtualMachine"), or another permissionrequired by the implementation.
throws:
  AttachNotSupportedException - If the attach provider's attachVirtualmachinethrows AttachNotSupportedException.
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If vmd is null.




detach
abstract public void detach() throws IOException(Code)
Detach from the virtual machine.

After detaching from the virtual machine, any further attempt to invoke operations on that virtual machine will cause an java.io.IOExceptionIOException to be thrown. If an operation (such as VirtualMachine.loadAgentloadAgent for example) is in progress when this method is invoked then the behaviour is implementation dependent. In other words, it is implementation specific if the operation completes or throws IOException.

If already detached from the virtual machine then invoking this method has no effect.


throws:
  IOException - If an I/O error occurs



equals
public boolean equals(Object ob)(Code)
Tests this VirtualMachine for equality with another object.

If the given object is not a VirtualMachine then this method returns false. For two VirtualMachines to be considered equal requires that they both reference the same provider, and their VirtualMachineDescriptor.id identifiers are equal.

This method satisfies the general contract of the java.lang.Object.equals(Object) Object.equals method.


Parameters:
  ob - The object to which this object is to be compared true if, and only if, the given object isa VirtualMachine that is equal to thisVirtualMachine.



getAgentProperties
abstract public Properties getAgentProperties() throws IOException(Code)
Returns the current agent properties in the target virtual machine.

The target virtual machine can maintain a list of properties on behalf of agents. The manner in which this is done, the names of the properties, and the types of values that are allowed, is implementation specific. Agent properties are typically used to store communication end-points and other agent configuration details. For example, a debugger agent might create an agent property for its transport address.

This method returns the agent properties whose key and value is a String. Properties whose key or value is not a String are omitted. If there are no agent properties maintained in the target virtual machine then an empty property list is returned. The agent properties
throws:
  IOException - If an I/O error occurs




getSystemProperties
abstract public Properties getSystemProperties() throws IOException(Code)
Returns the current system properties in the target virtual machine.

This method returns the system properties in the target virtual machine. Properties whose key or value is not a String are omitted. The method is approximately equivalent to the invocation of the method java.lang.System.getProperties System.getProperties in the target virtual machine except that properties with a key or value that is not a String are not included.

This method is typically used to decide which agent to load into the target virtual machine with VirtualMachine.loadAgent loadAgent , or VirtualMachine.loadAgentLibrary loadAgentLibrary . For example, the java.home or user.dir properties might be use to create the path to the agent library or JAR file. The system properties
throws:
  IOException - If an I/O error occurs
See Also:   java.lang.System.getProperties
See Also:   VirtualMachine.loadAgentLibrary
See Also:   VirtualMachine.loadAgent




hashCode
public int hashCode()(Code)
Returns a hash-code value for this VirtualMachine. The hash code is based upon the VirtualMachine's components, and satifies the general contract of the java.lang.Object.hashCodeObject.hashCode method. A hash-code value for this virtual machine



id
final public String id()(Code)
Returns the identifier for this Java virtual machine. The identifier for this Java virtual machine.



list
public static List<VirtualMachineDescriptor> list()(Code)
Return a list of Java virtual machines.

This method returns a list of Java com.sun.tools.attach.VirtualMachineDescriptor elements. The list is an aggregation of the virtual machine descriptor lists obtained by invoking the com.sun.tools.attach.spi.AttachProvider.listVirtualMachineslistVirtualMachines method of all installed com.sun.tools.attach.spi.AttachProvider attach providers . If there are no Java virtual machines known to any provider then an empty list is returned. The list of virtual machine descriptors.




loadAgent
abstract public void loadAgent(String agent, String options) throws AgentLoadException, AgentInitializationException, IOException(Code)
Loads an agent.

The agent provided to this method is a path name to a JAR file on the file system of the target virtual machine. This path is passed to the target virtual machine where it is interpreted. The target virtual machine attempts to start the agent as specified by the java.lang.instrument specification. That is, the specified JAR file is added to the system class path (of the target virtual machine), and the agentmain method of the agent class, specified by the Agent-Class attribute in the JAR manifest, is invoked. This method completes when the agentmain method completes.
Parameters:
  agent - Path to the JAR file containing the agent.
Parameters:
  options - The options to provide to the agent's agentmainmethod (can be null).
throws:
  AgentLoadException - If the agent does not exist, or cannot be started in the mannerspecified in the java.lang.instrument specification.
throws:
  AgentInitializationException - If the agentmain throws an exception
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agent is null.




loadAgent
public void loadAgent(String agent) throws AgentLoadException, AgentInitializationException, IOException(Code)
Loads an agent.

This convenience method works as if by invoking:

VirtualMachine.loadAgent(String,String) loadAgent (agent, null);

Parameters:
  agent - Path to the JAR file containing the agent.
throws:
  AgentLoadException - If the agent does not exist, or cannot be started in the mannerspecified in the java.lang.instrument specification.
throws:
  AgentInitializationException - If the agentmain throws an exception
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agent is null.



loadAgentLibrary
abstract public void loadAgentLibrary(String agentLibrary, String options) throws AgentLoadException, AgentInitializationException, IOException(Code)
Loads an agent library.

A JVM TI client is called an agent. It is developed in a native language. A JVM TI agent is deployed in a platform specific manner but it is typically the platform equivalent of a dynamic library. This method causes the given agent library to be loaded into the target VM (if not already loaded). It then causes the target VM to invoke the Agent_OnAttach function as specified in the JVM Tools Interface specification. Note that the Agent_OnAttach function is invoked even if the agent library was loaded prior to invoking this method.

The agent library provided is the name of the agent library. It is interpreted in the target virtual machine in an implementation-dependent manner. Typically an implementation will expand the library name into an operating system specific file name. For example, on UNIX systems, the name foo might be expanded to libfoo.so, and located using the search path specified by the LD_LIBRARY_PATH environment variable.

If the Agent_OnAttach function in the agent library returns an error then an com.sun.tools.attach.AgentInitializationException is thrown. The return value from the Agent_OnAttach can then be obtained by invoking the com.sun.tools.attach.AgentInitializationException.returnValue returnValue method on the exception.


Parameters:
  agentLibrary - The name of the agent library.
Parameters:
  options - The options to provide to the Agent_OnAttachfunction (can be null).
throws:
  AgentLoadException - If the agent library does not exist, or cannot be loaded foranother reason.
throws:
  AgentInitializationException - If the Agent_OnAttach function returns an error
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agentLibrary is null.
See Also:   com.sun.tools.attach.AgentInitializationException.returnValue



loadAgentLibrary
public void loadAgentLibrary(String agentLibrary) throws AgentLoadException, AgentInitializationException, IOException(Code)
Loads an agent library.

This convenience method works as if by invoking:

VirtualMachine.loadAgentLibrary(String,String) loadAgentLibrary (agentLibrary, null);

Parameters:
  agentLibrary - The name of the agent library.
throws:
  AgentLoadException - If the agent library does not exist, or cannot be loaded foranother reason.
throws:
  AgentInitializationException - If the Agent_OnAttach function returns an error
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agentLibrary is null.



loadAgentPath
abstract public void loadAgentPath(String agentPath, String options) throws AgentLoadException, AgentInitializationException, IOException(Code)
Load a native agent library by full pathname.

A JVM TI client is called an agent. It is developed in a native language. A JVM TI agent is deployed in a platform specific manner but it is typically the platform equivalent of a dynamic library. This method causes the given agent library to be loaded into the target VM (if not already loaded). It then causes the target VM to invoke the Agent_OnAttach function as specified in the JVM Tools Interface specification. Note that the Agent_OnAttach function is invoked even if the agent library was loaded prior to invoking this method.

The agent library provided is the absolute path from which to load the agent library. Unlike VirtualMachine.loadAgentLibrary loadAgentLibrary , the library name is not expanded in the target virtual machine.

If the Agent_OnAttach function in the agent library returns an error then an com.sun.tools.attach.AgentInitializationException is thrown. The return value from the Agent_OnAttach can then be obtained by invoking the com.sun.tools.attach.AgentInitializationException.returnValue returnValue method on the exception.


Parameters:
  agentPath - The full path of the agent library.
Parameters:
  options - The options to provide to the Agent_OnAttachfunction (can be null).
throws:
  AgentLoadException - If the agent library does not exist, or cannot be loaded foranother reason.
throws:
  AgentInitializationException - If the Agent_OnAttach function returns an error
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agentPath is null.
See Also:   com.sun.tools.attach.AgentInitializationException.returnValue



loadAgentPath
public void loadAgentPath(String agentPath) throws AgentLoadException, AgentInitializationException, IOException(Code)
Load a native agent library by full pathname.

This convenience method works as if by invoking:

VirtualMachine.loadAgentPath(String,String) loadAgentPath (agentLibrary, null);

Parameters:
  agentPath - The full path to the agent library.
throws:
  AgentLoadException - If the agent library does not exist, or cannot be loaded foranother reason.
throws:
  AgentInitializationException - If the Agent_OnAttach function returns an error
throws:
  IOException - If an I/O error occurs
throws:
  NullPointerException - If agentPath is null.



provider
final public AttachProvider provider()(Code)
Returns the provider that created this virtual machine. The provider that created this virtual machine.



toString
public String toString()(Code)
Returns the string representation of the VirtualMachine.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.