org.objectweb.cjdbc.requestplayer
Class ClientEmulator

java.lang.Object
  extended byorg.objectweb.cjdbc.requestplayer.ClientEmulator

public class ClientEmulator
extends java.lang.Object

C-JDBC client emulator. Reads SQL requests in a file and forwards them to the controller.

Version:
1.0
Author:
Emmanuel Cecchet , Julie Marguerite , Mathieu Peltier

Field Summary
protected  Stats beginStats
          Statistics concerning transaction begin.
protected  Stats closeStats
          Statistics about closing a connection
protected  Stats commitStats
          Statistics concerning transaction commit.
private  int connectionType
          Type of connection management: standard, optimized or pooling.
protected  Stats deleteStats
          Statistics concerning the DELETE requests.
private  java.util.Stack freeConnections
          Stack of available connections (pool).
protected  Stats getConnectionStats
          Statistics about get connection from driver
protected  Stats getRequestStats
          Statistics about getting request from the log file
private  java.util.HashSet ignoredTids
           
protected  Stats insertStats
          Statistics concerning the INSERT requests.
static int MAJOR_VERSION
          Major version.
private  int maxRequests
          Max number of requests.
static int MINOR_VERSION
          Minor version.
private  int nbRequests
          Number of requests.
private  int poolSize
          Connection pool size.
private  java.lang.String propPassword
          Database password.
private  java.lang.String propUrl
          Database URL.
private  java.lang.String propUsername
          Database login.
private  RequestPlayerProperties requestPlayerProp
          Access to the properties file.
protected  Stats rollbackStats
          Statistics concerning transaction rollback.
protected  Stats selectStats
          Statistics concerning the SELECT requests.
protected  java.io.BufferedReader sqlTrace
          To read the SQL requests in the file.
private  java.util.Hashtable tidList
          Transaction id list.
private  int timeout
          Query timeout.
private  java.lang.Integer transactionId
          Transaction id.
protected  Stats unknownStats
          Statistics concerning the unknown requests.
protected  Stats updateStats
          Statistics concerning the UPDATE requests.
private static java.lang.Integer ZERO
          Zero value.
 
Constructor Summary
ClientEmulator(java.lang.String configFile)
          Creates a new ClientEmulator instance.
 
Method Summary
 void closeConnection(java.sql.Connection connection)
          Closes a given connection.
private static org.apache.commons.cli.Options createOptions()
          Creates Options object that contains all available options that can be used launching C-JDBC request player.
 void finalizeConnections()
          Releases all the connections to the database.
 Stats getBeginStats()
          Returns the beginStats value.
 Stats getCloseStats()
          Returns the closeStats value.
 Stats getCommitStats()
          Returns the commitStats value.
 java.sql.Connection getConnection()
          Gets a new connection from the driver.
 java.sql.Connection getConnectionFromPool()
          Gets a connection from the pool (round-robin).
 Stats getDeleteStats()
          Returns the DELETE requests statictics.
 java.util.Stack getFreeConnections()
          Returns the freeConnections value.
 Stats getGetConnectionStats()
          Returns the getConnectionStats value.
 Stats getGetRequestStats()
          Returns the getRequestStats value.
 Stats getInsertStats()
          Returns the INSERT requests statictics.
 Stats getRollbackStats()
          Returns the rollbackStats value.
 Stats getSelectStats()
          Returns the SELECT requests statictics.
 int getTimeout()
          Returns the query timeout.
 Stats getUnknownStats()
          Returns the unknown requests statictics.
 Stats getUpdateStats()
          Returns the UPDATE requests statictics
 void ignoreTid(int tid)
          Ignores all requests belonging to a specific transaction id.
 void initializeConnections()
          Initializes the pool of connections to the database.
static void main(java.lang.String[] args)
          Main method.
 java.lang.String parallelGetNextSQLRequest(int tid)
          Gets the next SQL request from the trace file.
private static void printUsage(org.apache.commons.cli.Options options)
          Displays usage message.
private  java.lang.String readRequest()
          Must be called from a synchronized statement.
 void releaseConnectionToPool(java.sql.Connection connection)
          Releases a connection to the pool.
 java.lang.String sequentialGetNextSQLRequest(int tid)
          Gets the next SQL request from the trace file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAJOR_VERSION

public static final int MAJOR_VERSION
Major version.

See Also:
Constant Field Values

MINOR_VERSION

public static final int MINOR_VERSION
Minor version.

See Also:
Constant Field Values

ZERO

private static final java.lang.Integer ZERO
Zero value.


propUrl

private java.lang.String propUrl
Database URL.


propUsername

private java.lang.String propUsername
Database login.


propPassword

private java.lang.String propPassword
Database password.


requestPlayerProp

private RequestPlayerProperties requestPlayerProp
Access to the properties file.


sqlTrace

protected java.io.BufferedReader sqlTrace
To read the SQL requests in the file.


selectStats

protected Stats selectStats
Statistics concerning the SELECT requests.


unknownStats

protected Stats unknownStats
Statistics concerning the unknown requests.


updateStats

protected Stats updateStats
Statistics concerning the UPDATE requests.


insertStats

protected Stats insertStats
Statistics concerning the INSERT requests.


deleteStats

protected Stats deleteStats
Statistics concerning the DELETE requests.


beginStats

protected Stats beginStats
Statistics concerning transaction begin.


commitStats

protected Stats commitStats
Statistics concerning transaction commit.


rollbackStats

protected Stats rollbackStats
Statistics concerning transaction rollback.


getConnectionStats

protected Stats getConnectionStats
Statistics about get connection from driver


closeStats

protected Stats closeStats
Statistics about closing a connection


getRequestStats

protected Stats getRequestStats
Statistics about getting request from the log file


nbRequests

private int nbRequests
Number of requests.


maxRequests

private int maxRequests
Max number of requests.


tidList

private java.util.Hashtable tidList
Transaction id list.


ignoredTids

private java.util.HashSet ignoredTids

timeout

private int timeout
Query timeout.


connectionType

private int connectionType
Type of connection management: standard, optimized or pooling.


freeConnections

private java.util.Stack freeConnections
Stack of available connections (pool).


poolSize

private int poolSize
Connection pool size.


transactionId

private java.lang.Integer transactionId
Transaction id.

Constructor Detail

ClientEmulator

public ClientEmulator(java.lang.String configFile)
Creates a new ClientEmulator instance. The program is stopped on any error reading the configuration files.

Parameters:
configFile - configuration file to used.
Method Detail

getConnection

public java.sql.Connection getConnection()
Gets a new connection from the driver.

Returns:
a connection

initializeConnections

public void initializeConnections()
Initializes the pool of connections to the database. The caller must ensure that the driver has already been loaded else an exception will be thrown.


closeConnection

public void closeConnection(java.sql.Connection connection)
Closes a given connection.

Parameters:
connection - connection to close

getConnectionFromPool

public java.sql.Connection getConnectionFromPool()
Gets a connection from the pool (round-robin).

Returns:
a Connection instance or null if no connection is available

releaseConnectionToPool

public void releaseConnectionToPool(java.sql.Connection connection)
Releases a connection to the pool.

Parameters:
connection - the connection to release

finalizeConnections

public void finalizeConnections()
                         throws java.sql.SQLException
Releases all the connections to the database.

Throws:
java.sql.SQLException - if an error occurs

parallelGetNextSQLRequest

public java.lang.String parallelGetNextSQLRequest(int tid)
Gets the next SQL request from the trace file. Requests are executed in parallel for each separate transaction.

Parameters:
tid - transaction id
Returns:
a String containing the SQL request or null if no more requests are available (end of file or maximum number of requests reached)

ignoreTid

public void ignoreTid(int tid)
Ignores all requests belonging to a specific transaction id. Only used for sequential request execution.

Parameters:
tid - the tid to ignore

sequentialGetNextSQLRequest

public java.lang.String sequentialGetNextSQLRequest(int tid)
Gets the next SQL request from the trace file. If the current request does not match the request transaction id, the current thread waits until the current request transaction id matches the requested one.

Parameters:
tid - transaction id
Returns:
a String containing the SQL request or null if no more requests are available (end of file or maximum number of requests reached)

readRequest

private java.lang.String readRequest()
Must be called from a synchronized statement.


getDeleteStats

public Stats getDeleteStats()
Returns the DELETE requests statictics.

Returns:
a Stats instance.

getInsertStats

public Stats getInsertStats()
Returns the INSERT requests statictics.

Returns:
a Stats instance.

getSelectStats

public Stats getSelectStats()
Returns the SELECT requests statictics.

Returns:
a Stats instance.

getUnknownStats

public Stats getUnknownStats()
Returns the unknown requests statictics.

Returns:
a Stats instance.

getUpdateStats

public Stats getUpdateStats()
Returns the UPDATE requests statictics. *

Returns:
a Stats instance.

getBeginStats

public Stats getBeginStats()
Returns the beginStats value.

Returns:
Returns the beginStats.

getCloseStats

public Stats getCloseStats()
Returns the closeStats value.

Returns:
Returns the closeStats.

getCommitStats

public Stats getCommitStats()
Returns the commitStats value.

Returns:
Returns the commitStats.

getFreeConnections

public java.util.Stack getFreeConnections()
Returns the freeConnections value.

Returns:
Returns the freeConnections.

getGetConnectionStats

public Stats getGetConnectionStats()
Returns the getConnectionStats value.

Returns:
Returns the getConnectionStats.

getGetRequestStats

public Stats getGetRequestStats()
Returns the getRequestStats value.

Returns:
Returns the getRequestStats.

getRollbackStats

public Stats getRollbackStats()
Returns the rollbackStats value.

Returns:
Returns the rollbackStats.

getTimeout

public int getTimeout()
Returns the query timeout.

Returns:
int value.

main

public static void main(java.lang.String[] args)
Main method. The available options are:

Parameters:
args - command line arguments (see above)

createOptions

private static org.apache.commons.cli.Options createOptions()
Creates Options object that contains all available options that can be used launching C-JDBC request player.

Returns:
an Options instance

printUsage

private static void printUsage(org.apache.commons.cli.Options options)
Displays usage message.

Parameters:
options - available command line options


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.