Skip to content

Commit

Permalink
Fixed unresolved log messages, dead code
Browse files Browse the repository at this point in the history
- this package should get more attention

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Apr 11, 2023
1 parent ef37323 commit c0b09d1
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,11 @@ public void deleteConnectorConnectionPool(PoolInfo poolInfo, boolean cascade) th
throw new ConnectorRuntimeException(i18nMsg);
}

boolean errorOccured = false;
killPool(poolInfo);
boolean result = _registry.removeManagedConnectionFactory(poolInfo);

if (!result) {
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.mcf_removal_failure", poolInfo);
}
_logger.log(Level.FINE, "Failed to remove the MCF: {0}", poolInfo);
return;
}

Expand All @@ -187,18 +184,7 @@ public void deleteConnectorConnectionPool(PoolInfo poolInfo, boolean cascade) th
} catch (NamingException ne) {
_logger.log(SEVERE, "rardeployment.connectionpool_removal_from_jndi_error", poolInfo);
String i18nMsg = I18N.getString("ccp_adm.failed_to_remove_from_jndi", poolInfo);
ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
cre.initCause(ne);
_logger.log(SEVERE, "", cre);
throw cre;
}
if (errorOccured){
String i18nMsg = I18N.getString("ccp_adm.failed_to_delete_conn_res", poolInfo);
ConnectorRuntimeException cre = new
ConnectorRuntimeException(i18nMsg);
_logger.log(SEVERE, "rardeployment.all_resources_removal_error", poolInfo);
_logger.log(SEVERE, "", cre);
throw cre;
throw new ConnectorRuntimeException(i18nMsg, ne);
}
}

Expand Down Expand Up @@ -985,9 +971,7 @@ public void recreateConnectorConnectionPool(ConnectorConnectionPool ccp) throws
} catch (NamingException ne) {
_logger.log(SEVERE, "rardeployment.pool_jndi_bind_failure", poolInfo);
String i18nMsg = I18N.getString("ccp_adm.could_not_recreate_pool", poolInfo);
ConnectorRuntimeException crex = new ConnectorRuntimeException(i18nMsg);
crex.initCause(ne);
throw crex;
throw new ConnectorRuntimeException(i18nMsg, ne);
} finally {
if (mcf == null) {
try {
Expand Down Expand Up @@ -1018,35 +1002,18 @@ private void unloadAndKillPool(PoolInfo poolInfo) throws ConnectorRuntimeExcepti
killPool(poolInfo);
boolean result = _registry.removeManagedConnectionFactory(poolInfo);
if (!result) {
_logger.log(SEVERE,
"rardeployment.mcf_removal_failure", poolInfo);
String i18nMsg = I18N.getString(
"ccp_adm.wrong_params_for_create", poolInfo);
ConnectorRuntimeException cre = new
ConnectorRuntimeException(i18nMsg);
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "", cre);
}
throw cre;
_logger.log(SEVERE, "Failed to remove the MCF {0}", poolInfo);
String i18nMsg = I18N.getString("ccp_adm.wrong_params_for_create", poolInfo);
throw new ConnectorRuntimeException(i18nMsg);
}
try {
SimpleJndiName jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
_runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
} catch (NamingException ne) {
String i18nMsg = I18N.getString(
"ccp_adm.failed_to_remove_from_jndi", poolInfo);
ConnectorRuntimeException cre = new
ConnectorRuntimeException(i18nMsg);
cre.initCause(ne);
_logger.log(SEVERE,
"rardeployment.connectionpool_removal_from_jndi_error",
poolInfo);
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "", cre);
}
throw cre;
_logger.log(SEVERE, "rardeployment.connectionpool_removal_from_jndi_error", poolInfo);
String i18nMsg = I18N.getString("ccp_adm.failed_to_remove_from_jndi", poolInfo);
throw new ConnectorRuntimeException(i18nMsg, ne);
}

}


Expand Down Expand Up @@ -1110,49 +1077,35 @@ public boolean flushConnectionPool(PoolInfo poolInfo) throws ConnectorRuntimeExc
* @throws java.sql.SQLException in case of errors
*/
public Connection getConnection(ResourceInfo resourceInfo, String user, String password) throws SQLException {
java.sql.Connection con = null;
try {
//DASResourcesUtil.setAdminConfigContext();
PoolInfo poolInfo = getPoolNameFromResourceJndiName(resourceInfo);
if(poolInfo == null){
throw new SQLException("No pool by name exists ");
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorRuntime.getConnection :: poolName : " + poolInfo);
PoolInfo poolInfo = getPoolInfo(resourceInfo);
if (poolInfo == null) {
throw new SQLException("No pool found for resource name " + resourceInfo.getName());
}
_logger.log(Level.FINE, "ConnectorRuntime.getConnection :: poolName {0}", poolInfo.getName());
//Maintain consitency with the ConnectionManagerImpl change to be checked in later
String passwd = (password == null) ? "" : password;
String passwd = password == null ? "" : password;

//From what we have seen so far, the user cannot be null
//but password can be
//if user is null we will use default authentication
//TODO: Discuss if this is the right thing to do
ResourcePrincipalDescriptor prin = (user == null) ?
null : new ResourcePrincipalDescriptor(user, passwd);
con = (java.sql.Connection) getUnpooledConnection(poolInfo, prin, true);
ResourcePrincipalDescriptor prin = user == null ? null : new ResourcePrincipalDescriptor(user, passwd);
Connection con = (java.sql.Connection) getUnpooledConnection(poolInfo, prin, true);
if (con == null) {
String i18nMsg = I18N.getString(
"ccp_adm.null_unpooled_connection");
throw new SQLException(i18nMsg);
throw new SQLException(I18N.getString("ccp_adm.null_unpooled_connection"));
}
} catch (ResourceException re) {
SQLException sqle = new SQLException(re.getMessage());
sqle.initCause(re);
_logger.log(WARNING, "jdbc.exc_get_conn", re.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" getConnection in ConnectorRuntime failed : " + re);
}
throw sqle;
} catch (Exception ex) {
SQLException sqle = new SQLException(ex.getMessage());
sqle.initCause(ex);
_logger.log(WARNING, "jdbc.exc_get_conn", ex.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" getConnection in ConnectorRuntime failed : " + ex);
}
throw sqle;
return con;
} catch (SQLException e) {
_logger.log(WARNING, "Error allocating connection: [{0}]", e.getMessage());
_logger.log(Level.FINE, "The getConnection failed.", e);
throw e;
} catch (Exception e) {
_logger.log(WARNING, "Error allocating connection: [{0}]", e.getMessage());
_logger.log(Level.FINE, "The getConnection failed.", e);
throw new SQLException(e.getMessage(), e);
}
return con;
}


Expand All @@ -1172,54 +1125,36 @@ public Connection getConnection(ResourceInfo resourceInfo, String user, String p
* @throws java.sql.SQLException in case of errors
*/
public Connection getConnection(ResourceInfo resourceInfo) throws SQLException {
java.sql.Connection con = null;
try {
//DASResourcesUtil.setAdminConfigContext();
PoolInfo poolInfo = getPoolNameFromResourceJndiName(resourceInfo);
if(poolInfo == null){
throw new SQLException("No pool by name exists ");
PoolInfo poolInfo = getPoolInfo(resourceInfo);
if (poolInfo == null) {
throw new SQLException("No pool found for resource name " + resourceInfo.getName());
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorRuntime.getConnection :: poolName : "
+ poolInfo);
}
con = (java.sql.Connection) getUnpooledConnection(poolInfo, null,
true);
_logger.log(Level.FINE, "ConnectorRuntime.getConnection :: poolName {0}", poolInfo.getName());
Connection con = (java.sql.Connection) getUnpooledConnection(poolInfo, null, true);
if (con == null) {
String i18nMsg = I18N.getString(
"ccp_adm.null_unpooled_connection");
throw new SQLException(i18nMsg);
throw new SQLException(I18N.getString("ccp_adm.null_unpooled_connection"));
}
} catch (ResourceException re) {
SQLException sqle = new SQLException(re.getMessage());
sqle.initCause(re);
_logger.log(WARNING, "jdbc.exc_get_conn", re.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Exception : " + re);
}
throw sqle;
} catch (Exception ex) {
SQLException sqle = new SQLException(ex.getMessage());
sqle.initCause(ex);
_logger.log(WARNING, "jdbc.exc_get_conn", ex.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" getConnection in ConnectorRuntime failed : " + ex);
}
throw sqle;
return con;
} catch (SQLException e) {
_logger.log(WARNING, "Error allocating connection: [{0}]", e.getMessage());
_logger.log(Level.FINE, "The getConnection failed.", e);
throw e;
} catch (Exception e) {
_logger.log(WARNING, "Error allocating connection: [{0}]", e.getMessage());
_logger.log(Level.FINE, "The getConnection failed.", e);
throw new SQLException(e.getMessage(), e);
}
return con;
}


/**
* Gets the Pool name that this JDBC resource points to. In case of a PMF resource
* gets the pool name of the pool pointed to by jdbc resource being pointed to by
* the PMF resource
*
* @param jndiName the jndi name of the resource being used to get Connection from
* This resource can either be a pmf resource or a jdbc resource
* @return poolName of the pool that this resource directly/indirectly points to
* Gets the {@link PoolInfo} that this JDBC resource points to.
* In case of a PMF resource gets the pool name of the pool pointed to by jdbc resource being
* pointed to by the PMF resource
*/
private PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
private PoolInfo getPoolInfo(ResourceInfo resourceInfo) {
PoolInfo poolInfo = null;
Collection<ConnectorRuntimeExtension> extensions = Globals.getDefaultHabitat()
.getAllServices(ConnectorRuntimeExtension.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,11 @@

package com.sun.enterprise.resource.pool;

import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.resource.ResourceHandle;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.logging.LogDomains;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -27,11 +32,6 @@

import org.glassfish.resourcebase.resources.api.PoolInfo;

import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.resource.ResourceHandle;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.logging.LogDomains;

/**
* Connection leak detector, book keeps the caller stack-trace during getConnection()<br>
* Once the leak-timeout expires, assumes a connection leak and prints the caller stack-trace<br>
Expand All @@ -40,13 +40,13 @@
* @author Kshitiz Saxena, Jagadish Ramu
*/
public class ConnectionLeakDetector {
private HashMap<ResourceHandle, StackTraceElement[]> connectionLeakThreadStackHashMap;
private HashMap<ResourceHandle, ConnectionLeakTask> connectionLeakTimerTaskHashMap;
private final HashMap<ResourceHandle, StackTraceElement[]> connectionLeakThreadStackHashMap;
private final HashMap<ResourceHandle, ConnectionLeakTask> connectionLeakTimerTaskHashMap;
private boolean connectionLeakTracing;
private long connectionLeakTimeoutInMillis;
private boolean connectionLeakReclaim;
private PoolInfo connectionPoolInfo;
private Map<ResourceHandle, ConnectionLeakListener> listeners;
private final PoolInfo connectionPoolInfo;
private final Map<ResourceHandle, ConnectionLeakListener> listeners;

// Lock on HashMap to trace connection leaks
private final Object connectionLeakLock;
Expand Down Expand Up @@ -153,19 +153,15 @@ private void potentialConnectionLeakFound(ResourceHandle resourceHandle) {
* @param threadStackTrace Application(caller) thread stack trace
*/
private void printConnectionLeakTrace(StackTraceElement[] threadStackTrace, ConnectionLeakListener connLeakListener) {
StringBuffer stackTrace = new StringBuffer();
String msg = localStrings.getStringWithDefault("potential.connection.leak.msg",
"A potential connection leak detected for connection pool " + connectionPoolInfo
+ ". The stack trace of the thread is provided below : ",
new Object[] { connectionPoolInfo });
stackTrace.append(msg);
stackTrace.append("\n");
StringBuffer stackTrace = new StringBuffer(1024);
stackTrace.append("A potential connection leak detected for connection pool ").append(connectionPoolInfo);
stackTrace.append(". The stack trace of the thread is provided below:\n");
for (int i = 2; i < threadStackTrace.length; i++) {
stackTrace.append(threadStackTrace[i].toString());
stackTrace.append("\n");
stackTrace.append(threadStackTrace[i]);
stackTrace.append('\n');
}
connLeakListener.printConnectionLeakTrace(stackTrace);
_logger.log(Level.WARNING, stackTrace.toString(), "ConnectionPoolName=" + connectionPoolInfo);
_logger.log(Level.WARNING, stackTrace.toString());
}

/**
Expand All @@ -190,7 +186,7 @@ private Timer getTimer() {

private class ConnectionLeakTask extends TimerTask {

private ResourceHandle resourceHandle;
private final ResourceHandle resourceHandle;

ConnectionLeakTask(ResourceHandle resourceHandle) {
this.resourceHandle = resourceHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public void resourceClosed(ResourceHandle handle) throws IllegalStateException {
if (poolLifeCycleListener != null && !handle.getDestroyByLeakTimeOut()) {
poolLifeCycleListener.connectionReleased(handle.getId());
}
LOG.log(FINE, "Resource was freed after it's closure: {0}", handle);
LOG.log(FINE, "Resource was freed after it`s closure: {0}", handle);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ rardeployment.non_1.5_compliant_rar=RAR6028 : This adapter is not 1.5 compliant
RAR6028.diag.cause.1=Resource Adapter doesnt contain resource adapter java bean.
RAR6028.diag.check.1=Make sure that the resource adapter is 1.5 compliant.
rardeployment.admin_object_delete_failure=RAR6029 : Failed to delete admin object from jndi : {0}
rardeployment.mcf_removal_failure=RAR6030 : Failed to remove the MCF : {0}
RAR6030.diag.cause.1=MCF cleanup in connector runtime failed.
RAR6030.diag.check.1=Check whether connection pool has already been deleted.
RAR6030.diag.check.2=There is an internal server error. Please contact Sun Microsystems with the complete log message
rardeployment.connectionpool_removal_from_jndi_error=RAR6031 : Failed to unbind connectionPool from jndi : {0}
RAR6031.diag.check.1=There is an internal server error. Please contact Sun Microsystems with the complete log message
rardeployment.start_failed=RAR6035 : Resource adapter start failed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -113,7 +113,7 @@ public Connection getConnection() throws SQLException {
*/
private void logNonTransientException(ResourceException re) {
if (!BadConnectionEventListener.POOL_RECONFIGURED_ERROR_CODE.equals(re.getErrorCode())) {
_logger.log(WARNING, "jdbc.exc_get_conn", re.getMessage());
_logger.log(WARNING, "Error allocating connection: [{0}]", re.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ RAR5113.diag.cause.3=The Database server threw some unexpected exception. Please
RAR5113.diag.check.1=Check that the Database server is up and running
RAR5113.diag.check.2=Check if the size of your connection pool is sufficiently large for serving all requests
RAR5113.diag.check.3=Check the server log and please contact Sun Microsystems with the full error log
jdbc.exc_get_conn=RAR5114 : Error allocating connection : [{0}]
RAR5114.diag.cause.1=There was an SQLException while acquiring connection from the Database. Please see the detailed exception message for more information
RAR5114.diag.cause.2=The Connection pool is full and incapable of serving more requests at this point. Please try later.
RAR5114.diag.cause.3=There is an internal server error. Please contact Sun Microsystems with the complete log message
RAR5114.diag.check.1=Check if the database server is correctly configured
RAR5114.diag.check.2=Check if your pool size is sufficient to server all simultaneous connection requests
RAR5114.diag.check.3=Check the server log and contact Sun Microsystems with the complete error message
jdbc.exc_cleanup=RAR5115 : Error cleaning up handles associated with this ManagedConnection
jdbc.exc_create_xa_conn=RAR5116 : The XA connection could not be allocated:
RAR5116.diag.cause.1=The Database server is not up and running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public Connection getConnection() throws SQLException {
return (Connection) cm.allocateConnection(mcf,null);
} catch (ResourceException re) {
// This is temporary. This needs to be changed to SEVERE after TP
_logger.log(Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
throw new SQLException (re.getMessage());
_logger.log(Level.WARNING, "Error allocating connection: [{0}]", re.getMessage());
throw new SQLException(re.getMessage(), re);
}
}

Expand All @@ -98,8 +98,8 @@ public Connection getConnection(String user, String pwd) throws SQLException {
return (Connection) cm.allocateConnection(mcf,info);
} catch (ResourceException re) {
// This is temporary. This needs to be changed to SEVERE after TP
_logger.log(Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
throw new SQLException (re.getMessage());
_logger.log(Level.WARNING, "Error allocating connection: [{0}]", re.getMessage());
throw new SQLException(re.getMessage(), re);
}
}

Expand Down
Loading

0 comments on commit c0b09d1

Please sign in to comment.