JProfiler API

com.jprofiler.api.platform.connection
Class ConnectionFactory

java.lang.Object
  extended by com.jprofiler.api.platform.connection.ConnectionFactory

public abstract class ConnectionFactory
extends java.lang.Object

Factory for creating connections to profiled JVMs and saved snapshots.

You can create multiple concurrent connections. For example, you could aggregate information from multiple remote JVMs.

See Also:
Connection

Constructor Summary
ConnectionFactory()
           
 
Method Summary
static Connection createRemoteConnection(java.lang.String hostname, int port, int timeout)
          Opens a connection to a remote JVM.
static Connection createSnapshotConnection(java.io.File snapshot, java.io.File configFile)
          Opens a connection to a saved snapshot file.
static Connection getLocalConnection()
          Opens a connection to the JVM of the current process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactory

public ConnectionFactory()
Method Detail

getLocalConnection

public static Connection getLocalConnection()
                                     throws java.io.IOException
Opens a connection to the JVM of the current process. This works only if the current JVM is being profiled, i.e. if the -agentlib:jprofilerti... (JVMTI) or -Xrunjprofiler... (JVMPI) VM parameters were passed to the JVM when the JVM was started.

For technical reasons this implies that the JVM was started with the "nowait" option in the -agentlib:jprofilerti (JVMTI) or -Xrunjprofiler (JVMPI) VM parameters, otherwise the profiling agent would be waiting for a connection and you would not be able to execute this method call.

Returns:
the connection
Throws:
java.io.IOException - if the connection fails

createSnapshotConnection

public static Connection createSnapshotConnection(java.io.File snapshot,
                                                  java.io.File configFile)
                                           throws java.io.IOException
Opens a connection to a saved snapshot file.

Parameters:
snapshot - the snapshot file
configFile - the config.xml file of JProfiler. If this parameter is null, the default config file from the current user's home directory will be used (if it exists).
Returns:
the connection
Throws:
java.io.IOException - if the file does not exist or the connection fails for some other reason

createRemoteConnection

public static Connection createRemoteConnection(java.lang.String hostname,
                                                int port,
                                                int timeout)
                                         throws java.io.IOException
Opens a connection to a remote JVM. This works only if

Parameters:
hostname - the host name or the IP address of the remote computer
port - the port on which the remote profiling agent is listening. The default value is 8849.
timeout - the timeout in seconds
Returns:
the connection
Throws:
java.io.IOException - if the connection fails or times out

JProfiler API