Problem
The support of the application clients was added in JBoss in the version 3.2.0. That is why it is clear why the application client based on the response of one of the JBoss developers doesn’t support the pool of connections for application clients.
It has been issued in the very first release of JBoss 4.0. All the available documentation at the moment relates to version 3.2. That is why I think that the given information on how to resolve this problem in JBoss 3.2 could still be useful for someone else.
Solution - The Library Apache Common DBCP
One of the distributions of JBoss includes Apache Tomcat which uses for creation of connection tools one of the available implementations in the market is Apache Commons DBCP, an efficient package under the ASF license. This package is also used in other Apache projects such as James (Java Apache Mail Enterprise Server) and Avalon Framework. The package commons-DBCP depends on another Apache package commons-pool.
Implementation
import java.util.*;
import javax.naming.*;
import org.apache.log4j.*;
public abstract class ApplicationClient {
private final String JNDI_NAME = "applicationClientPool";
private static Logger logger = Logger.getLogger(ApplicationClient.class);
public ApplicationClient() throws ApplicationClientException {
Context ctx = null;
boolean isPoolInitialized = false;
try {
ctx = new InitialContext();
try {
isPoolInitialized = ( ctx.lookup( JNDI_NAME ) != null );
} catch (NamingException ne) {
logger.warn("Impossible to perform lookup.");
}
if ( ! isPoolInitialized ) {
Reference ref = new Reference(
"javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory",
null );
ref.add( new StringRefAddr( "driverClassName",
CommonNames.DRIVER_JDBC ) );
ref.add( new StringRefAddr( "url",
CommonNames.DATABASE_URL) );
ref.add( new StringRefAddr( "username",
CommonNames.DATABASE_LOGIN ) );
ref.add( new StringRefAddr( "password",
CommonNames.DATABASE_PASSWORD ) );
ctx.rebind( JNDI_NAME, ref );
logger.debug(
"Executed the bind of the data source." );
}
} catch (NamingException ne) {
logger.fatal( "It is impossibile to use the JNDI service.", ne );
throw new ApplicationClientException(
"It is impossibile to use the JNDI service." );
} catch (Exception ex) {
logger.fatal(
"An unknown error happened during the initialization
of the application client.", ex );
throw new ApplicationClientException(
"An unknown error happened during the initialization
of the application client." );
}
}
}
History
- 5th October, 2004: Initial post