com.bluemarsh.jswat
Class VMConnection

java.lang.Object
  |
  +--com.bluemarsh.jswat.VMConnection

public class VMConnection
extends java.lang.Object

Class VMConnection contains the parameters necessary for making and maintaining a connection to a debuggee VM. It provides methods for constructing a connection and launching a debuggee VM.

Author:
Nathan Fiedler

Field Summary
protected  com.sun.jdi.connect.Connector connector
          Connector.
protected  java.util.Map connectorArgs
          Connector arguments.
protected  com.sun.jdi.VirtualMachine debuggeeVM
          Debuggee VM.
 
Constructor Summary
VMConnection(com.sun.jdi.connect.Connector connector, java.util.Map args)
          Constructs a new VMConnection with the given connector and arguments.
 
Method Summary
 boolean attachDebuggee(Session session)
          Attaches to a remote debuggee using this connection.
static VMConnection buildConnection(java.lang.String name)
          Builds the connection parameters object using the given shared memory name for the debuggee VM.
static VMConnection buildConnection(java.lang.String host, java.lang.String port)
          Builds the connection parameters object using the given host and port for the remote debuggee VM.
static VMConnection buildConnection(java.lang.String javaHome, java.lang.String jvmExecutable, java.lang.String options, java.lang.String cmdline)
          Builds a VMConnection object to contain all the necessary parameters for launching a debuggee VM.
protected static void dumpStream(java.io.InputStream is, Log out)
          Dumps the contents of the input stream to the message log.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 java.lang.String getConnectArg(java.lang.String name)
          Returns the named connector argument.
 java.util.Map getConnectArgs()
          Returns the connector arguments used to launch, listen, or attach to the debuggee VM.
 com.sun.jdi.connect.Connector getConnector()
          Returns the connector used to launch, listen, or attach to the debuggee VM.
 java.lang.String getMainClass()
          Returns the "main" connector argument.
 com.sun.jdi.VirtualMachine getVM()
          Returns the debuggee VirtualMachine associated with this connection.
 boolean launchDebuggee(Session session)
          Launches the debuggee VM using this connection.
 void setVM(com.sun.jdi.VirtualMachine vm)
          Sets the VirtualMachine that is associated with this connection.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connector

protected com.sun.jdi.connect.Connector connector
Connector.

connectorArgs

protected java.util.Map connectorArgs
Connector arguments.

debuggeeVM

protected com.sun.jdi.VirtualMachine debuggeeVM
Debuggee VM.
Constructor Detail

VMConnection

public VMConnection(com.sun.jdi.connect.Connector connector,
                    java.util.Map args)
Constructs a new VMConnection with the given connector and arguments.
Parameters:
connector - connector.
args - connector arguments.
Method Detail

attachDebuggee

public boolean attachDebuggee(Session session)
Attaches to a remote debuggee using this connection.
Parameters:
session - Session to activate when attached.
Returns:
true if successful, false if error.

buildConnection

public static VMConnection buildConnection(java.lang.String name)
                                    throws NoAttachingConnectorException
Builds the connection parameters object using the given shared memory name for the debuggee VM.
Parameters:
name - shared memory name.
Returns:
VMConnection, or null if error.
Throws:
NoAttachingConnectorException - Thrown if the appropriate connector could not be found.

buildConnection

public static VMConnection buildConnection(java.lang.String host,
                                           java.lang.String port)
                                    throws NoAttachingConnectorException
Builds the connection parameters object using the given host and port for the remote debuggee VM.
Parameters:
host - Host machine name.
port - Port of remote machine.
Returns:
VMConnection, or null if error.
Throws:
NoAttachingConnectorException - Thrown if the appropriate connector could not be found.

buildConnection

public static VMConnection buildConnection(java.lang.String javaHome,
                                           java.lang.String jvmExecutable,
                                           java.lang.String options,
                                           java.lang.String cmdline)
Builds a VMConnection object to contain all the necessary parameters for launching a debuggee VM.
Parameters:
javaHome - home of JVM or null for default.
jvmExecutable - name of JVM executable file or null for default.
options - VM options to pass or null for none.
cmdline - class to launch (with optional arguments).
Returns:
new VMConnection instance.

dumpStream

protected static void dumpStream(java.io.InputStream is,
                                 Log out)
                          throws java.io.IOException
Dumps the contents of the input stream to the message log.
Parameters:
is - input stream to read from.
out - output Log to dump to.
Throws:
java.io.IOException - Thrown if error occurs.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one. Compares just the main class argument for equality.
Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

getConnector

public com.sun.jdi.connect.Connector getConnector()
Returns the connector used to launch, listen, or attach to the debuggee VM. This is one of the com.sun.jdi.connect.Connector subclasses.
Returns:
Connector, or null if there has never been a connection.

getConnectArgs

public java.util.Map getConnectArgs()
Returns the connector arguments used to launch, listen, or attach to the debuggee VM.
Returns:
Map, or null if there has never been a connection.

getConnectArg

public java.lang.String getConnectArg(java.lang.String name)
Returns the named connector argument.
Parameters:
name - name of argument to retrieve.
Returns:
Named argument, or null if none (or no arguments).

getMainClass

public java.lang.String getMainClass()
Returns the "main" connector argument. This is the class name of the class that is being debugged.
Returns:
Main class name, or null if undefined.

getVM

public com.sun.jdi.VirtualMachine getVM()
Returns the debuggee VirtualMachine associated with this connection.
Returns:
VirtualMachine, or none if no connection.

launchDebuggee

public boolean launchDebuggee(Session session)
Launches the debuggee VM using this connection. If there are problems, this method will dump the errors to the Session's status Log.
Parameters:
session - Session to activate.
Returns:
true if VM launched, false if error.

setVM

public void setVM(com.sun.jdi.VirtualMachine vm)
Sets the VirtualMachine that is associated with this connection. xxx - replace this method with more appropriate "detach" or something like that
Parameters:
vm - VirtualMachine.