Methods Summary |
---|
public java.lang.Object | allocateConnection(javax.resource.spi.ManagedConnectionFactory mcf, javax.resource.spi.ConnectionRequestInfo cri)
if (poolingStrategy == null)
throw new ResourceException(
"You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is null.");
//it is an explicit spec requirement that equals be used for matching rather than ==.
if (!poolingStrategy.getManagedConnectionFactory().equals(mcf))
throw new ResourceException("Wrong ManagedConnectionFactory sent to allocateConnection!");
// Pick a managed connection from the pool
Subject subject = getSubject();
ConnectionListener cl = getManagedConnection(subject, cri);
// Tell each connection manager the managed connection is active
reconnectManagedConnection(cl);
// Ask the managed connection for a connection
Object connection = null;
try
{
connection = cl.getManagedConnection().getConnection(subject, cri);
}
catch (Throwable t)
{
managedConnectionDisconnected(cl);
JBossResourceException.rethrowAsResourceException(
"Unchecked throwable in ManagedConnection.getConnection() cl=" + cl, t);
}
// Associate managed connection with the connection
registerAssociation(cl, connection);
if (ccm != null)
ccm.registerConnection(this, cl, connection, cri);
return connection;
|
public void | disconnect(java.util.Collection crs, java.util.Set unsharableResources)
// if we have an unshareable connection do not remove the association
// nothing to do
if (unsharableResources.contains(jndiName))
{
log.trace("disconnect for unshareable connection: nothing to do");
return;
}
Set cls = new HashSet();
for (Iterator i = crs.iterator(); i.hasNext();)
{
ConnectionRecord cr = (ConnectionRecord) i.next();
ConnectionListener cl = cr.cl;
cr.setConnectionListener(null);
unregisterAssociation(cl, cr.connection);
if (!cls.contains(cl))
{
cls.add(cl);
}
}
for (Iterator i = cls.iterator(); i.hasNext();)
disconnectManagedConnection((ConnectionListener) i.next());
|
protected void | disconnectManagedConnection(ConnectionListener cl)Invoked when a managed connection is no longer associated
try
{
managedConnectionDisconnected(cl);
}
catch (Throwable t)
{
log.warn("Unchecked throwable in managedConnectionDisconnected() cl=" + cl, t);
}
|
public javax.management.ObjectName | getCachedConnectionManager()
return ccmName;
|
protected final CachedConnectionManager | getCcm()
return ccm;
|
public int | getConnectionCount()
return poolingStrategy.getConnectionCount();
|
public org.jboss.resource.connectionmanager.BaseConnectionManager2 | getInstance()
return this;
|
public javax.management.ObjectName | getJaasSecurityManagerService()
return jaasSecurityManagerService;
|
public java.lang.String | getJndiName()
return jndiName;
|
public ConnectionListener | getManagedConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cri)Public for use in testing pooling functionality by itself.
called by both allocateConnection and reconnect.
return getManagedConnection(null, subject, cri);
|
protected ConnectionListener | getManagedConnection(javax.transaction.Transaction transaction, javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cri)Get the managed connection from the pool
return poolingStrategy.getConnection(transaction, subject, cri);
|
public javax.resource.spi.ManagedConnectionFactory | getManagedConnectionFactory()
return poolingStrategy.getManagedConnectionFactory();
|
public javax.management.ObjectName | getManagedConnectionPool()
return managedConnectionPoolName;
|
public javax.management.MBeanNotificationInfo[] | getNotificationInfo()
// TODO: implement this javax.management.NotificationBroadcaster method
return super.getNotificationInfo();
|
public ManagedConnectionPool | getPoolingStrategy()For testing
return poolingStrategy;
|
public java.lang.String | getSecurityDomainJndiName()
return securityDomainJndiName;
|
private javax.security.auth.Subject | getSubject()
Subject subject = null;
if (securityDomain != null)
{
/* Authenticate using the caller info and obtain a copy of the Subject
state for use in establishing a secure connection. A copy must be
obtained to avoid problems with multiple threads associated with
the same principal changing the state of the resulting Subject.
*/
Principal principal = GetPrincipalAction.getPrincipal();
Object credential = GetCredentialAction.getCredential();
subject = new Subject();
if (securityDomain.isValid(principal, credential, subject) == false)
throw new SecurityException("Invalid authentication attempt, principal=" + principal);
}
if (trace)
log.trace("subject: " + subject);
return subject;
|
public long | getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
return -1;
|
public javax.transaction.TransactionManager | getTransactionManagerInstance()
return null;
|
public int | getTransactionTimeout()
throw new NotImplementedException("NYI: getTransactionTimeout()");
|
public boolean | isTransactional()
return false;
|
protected void | managedConnectionDisconnected(ConnectionListener cl)For polymorphism.
Do not invoke directly use disconnectManagedConnection
which does the relevent exception handling
|
protected void | managedConnectionReconnected(ConnectionListener cl)For polymorphism.
Do not invoke directly use reconnectManagedConnection
which does the relevent exception handling
|
public void | reconnect(java.util.Collection conns, java.util.Set unsharableResources)
// if we have an unshareable connection the association was not removed
// nothing to do
if (unsharableResources.contains(jndiName))
{
log.trace("reconnect for unshareable connection: nothing to do");
return;
}
Map criToCLMap = new HashMap();
for (Iterator i = conns.iterator(); i.hasNext();)
{
ConnectionRecord cr = (ConnectionRecord) i.next();
if (cr.cl != null)
{
//This might well be an error.
log.warn("reconnecting a connection handle that still has a managedConnection! "
+ cr.cl.getManagedConnection() + " " + cr.connection);
}
ConnectionListener cl = (ConnectionListener) criToCLMap.get(cr.cri);
if (cl == null)
{
cl = getManagedConnection(getSubject(), cr.cri);
criToCLMap.put(cr.cri, cl);
//only call once per managed connection, when we get it.
reconnectManagedConnection(cl);
}
cl.getManagedConnection().associateConnection(cr.connection);
registerAssociation(cl, cr.connection);
cr.setConnectionListener(cl);
}
criToCLMap.clear();//not needed logically, might help the gc.
|
protected void | reconnectManagedConnection(ConnectionListener cl)Invoked to reassociate a managed connection
try
{
//WRONG METHOD NAME!!
managedConnectionReconnected(cl);
}
catch (Throwable t)
{
disconnectManagedConnection(cl);
JBossResourceException.rethrowAsResourceException("Unchecked throwable in managedConnectionReconnected() cl="
+ cl, t);
}
|
private void | registerAssociation(ConnectionListener cl, java.lang.Object c)
cl.registerConnection(c);
|
protected static void | rethrowAsResourceException(java.lang.String message, java.lang.Throwable t)Rethrow a throwable as resource exception
JBossResourceException.rethrowAsResourceException(message, t);
|
public void | returnManagedConnection(ConnectionListener cl, boolean kill)
ManagedConnectionPool localStrategy = cl.getManagedConnectionPool();
if (localStrategy != poolingStrategy)
kill = true;
try
{
if (kill == false && cl.getState() == ConnectionListener.NORMAL)
cl.tidyup();
}
catch (Throwable t)
{
log.warn("Error during tidyup " + cl, t);
kill = true;
}
try
{
localStrategy.returnConnection(cl, kill);
}
catch (ResourceException re)
{
// We can receive notification of an error on the connection
// before it has been assigned to the pool. Reduce the noise for
// these errors
if (kill)
log.debug("resourceException killing connection (error retrieving from pool?)", re);
else
log.warn("resourceException returning connection: " + cl.getManagedConnection(), re);
}
|
public void | setCachedConnectionManager(javax.management.ObjectName ccmName)
this.ccmName = ccmName;
|
public void | setJaasSecurityManagerService(javax.management.ObjectName jaasSecurityManagerService)
this.jaasSecurityManagerService = jaasSecurityManagerService;
|
public void | setJndiName(java.lang.String jndiName)
this.jndiName = jndiName;
|
public void | setManagedConnectionPool(javax.management.ObjectName newManagedConnectionPool)
this.managedConnectionPoolName = newManagedConnectionPool;
|
public void | setSecurityDomainJndiName(java.lang.String securityDomainJndiName)
if (securityDomainJndiName != null && securityDomainJndiName.startsWith(SECURITY_MGR_PATH))
{
securityDomainJndiName = securityDomainJndiName.substring(SECURITY_MGR_PATH.length());
log.warn("WARNING: UPDATE YOUR SecurityDomainJndiName! REMOVE " + SECURITY_MGR_PATH);
}
this.securityDomainJndiName = securityDomainJndiName;
|
protected void | startService()
try
{
ccm = (CachedConnectionManager) server.getAttribute(ccmName, "Instance");
}
catch (Exception e)
{
JMXExceptionDecoder.rethrow(e);
}
if (ccm == null)
throw new DeploymentException("cached ConnectionManager not found: " + ccmName);
if (securityDomainJndiName != null && jaasSecurityManagerService == null)
throw new DeploymentException("You must supply both securityDomainJndiName and jaasSecurityManagerService to use container managed security");
if (securityDomainJndiName != null)
securityDomain = (SubjectSecurityManager) new InitialContext().lookup(SECURITY_MGR_PATH
+ securityDomainJndiName);
if (managedConnectionPoolName == null)
throw new DeploymentException("managedConnectionPool not set!");
try
{
poolingStrategy = (ManagedConnectionPool) server.getAttribute(managedConnectionPoolName,
"ManagedConnectionPool");
}
catch (Exception e)
{
JMXExceptionDecoder.rethrow(e);
}
poolingStrategy.setConnectionListenerFactory(this);
// Give it somewhere to tell people things
String categoryName = poolingStrategy.getManagedConnectionFactory().getClass().getName() + "." + jndiName;
Logger log = Logger.getLogger(categoryName);
PrintWriter logWriter = new LoggerPluginWriter(log.getLoggerPlugin());
try
{
poolingStrategy.getManagedConnectionFactory().setLogWriter(logWriter);
}
catch (ResourceException re)
{
log.warn("Unable to set log writer '" + logWriter + "' on " + "managed connection factory", re);
log.warn("Linked exception:", re.getLinkedException());
}
if (poolingStrategy instanceof PreFillPoolSupport)
{
PreFillPoolSupport prefill = (PreFillPoolSupport) poolingStrategy;
if(prefill.shouldPreFill()){
prefill.prefill();
}
}
|
protected void | stopService()
//notify the login modules the mcf is going away, they need to look it up again later.
sendNotification(new Notification(STOPPING_NOTIFICATION, getServiceName(), getNextNotificationSequenceNumber()));
if (jaasSecurityManagerService != null && securityDomainJndiName != null)
server.invoke(jaasSecurityManagerService, "flushAuthenticationCache", new Object[] { securityDomainJndiName }, new String[] { String.class.getName() });
poolingStrategy.setConnectionListenerFactory(null);
poolingStrategy = null;
securityDomain = null;
ccm = null;
|
public void | transactionStarted(java.util.Collection conns)
//reimplement in subclasses
|
protected void | unregisterAssociation(ConnectionListener cl, java.lang.Object c)
cl.unregisterConnection(c);
|