| Method from org.jboss.resource.connectionmanager.BaseConnectionManager2 Detail: |
public Object allocateConnection(ManagedConnectionFactory mcf,
ConnectionRequestInfo cri) throws ResourceException {
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)
{
try {
managedConnectionDisconnected(cl);
}
catch (ResourceException re)
{
log.trace("Get exception from managedConnectionDisconnected, maybe delist() have problem" + re);
returnManagedConnection(cl, true);
}
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 checkTransactionActive() throws SystemException, RollbackException {
// Nothing
}
|
public void disconnect(Collection crs,
Set unsharableResources) throws ResourceException {
// 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) {
try
{
managedConnectionDisconnected(cl);
}
catch (Throwable t)
{
log.warn("Unchecked throwable in managedConnectionDisconnected() cl=" + cl, t);
}
}
Invoked when a managed connection is no longer associated |
public ObjectName getCachedConnectionManager() {
return ccmName;
}
|
protected final CachedConnectionManager getCcm() {
return ccm;
}
|
public int getConnectionCount() {
return poolingStrategy.getConnectionCount();
}
|
public BaseConnectionManager2 getInstance() {
return this;
}
|
public ObjectName getJaasSecurityManagerService() {
return this.jaasSecurityManagerService;
} Deprecated!
|
public String getJndiName() {
return jndiName;
}
|
public ConnectionListener getManagedConnection(Subject subject,
ConnectionRequestInfo cri) throws ResourceException {
return getManagedConnection(null, subject, cri);
}
Public for use in testing pooling functionality by itself.
called by both allocateConnection and reconnect. |
protected ConnectionListener getManagedConnection(Transaction transaction,
Subject subject,
ConnectionRequestInfo cri) throws ResourceException {
return poolingStrategy.getConnection(transaction, subject, cri);
}
Get the managed connection from the pool |
public ManagedConnectionFactory getManagedConnectionFactory() {
return poolingStrategy.getManagedConnectionFactory();
}
|
public ObjectName getManagedConnectionPool() {
return managedConnectionPoolName;
}
|
public MBeanNotificationInfo[] getNotificationInfo() {
// TODO: implement this javax.management.NotificationBroadcaster method
return super.getNotificationInfo();
}
|
public ManagedConnectionPool getPoolingStrategy() {
return poolingStrategy;
}
|
public String getSecurityDomainJndiName() {
return securityDomainJndiName;
}
|
public SubjectFactory getSubjectFactory() {
return subjectFactory;
}
|
public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback) throws RollbackException {
return -1;
}
|
public TransactionManager getTransactionManagerInstance() {
return null;
}
|
public int getTransactionTimeout() throws SystemException {
throw new NotImplementedException("NYI: getTransactionTimeout()");
}
|
public boolean isTransactional() {
return false;
}
|
protected void managedConnectionDisconnected(ConnectionListener cl) throws ResourceException {
}
|
protected void managedConnectionReconnected(ConnectionListener cl) throws ResourceException {
}
|
public void reconnect(Collection conns,
Set unsharableResources) throws ResourceException {
// 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) throws ResourceException {
try
{
//WRONG METHOD NAME!!
managedConnectionReconnected(cl);
}
catch (Throwable t)
{
disconnectManagedConnection(cl);
JBossResourceException.rethrowAsResourceException("Unchecked throwable in managedConnectionReconnected() cl="
+ cl, t);
}
}
Invoked to reassociate a managed connection |
protected static void rethrowAsResourceException(String message,
Throwable t) throws ResourceException {
JBossResourceException.rethrowAsResourceException(message, t);
} Deprecated! use - JBossResourceException.rethrowAsResourceException
Rethrow a throwable as resource exception |
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(ObjectName ccmName) {
this.ccmName = ccmName;
}
|
public void setJaasSecurityManagerService(ObjectName jaasSecurityManagerService) {
this.jaasSecurityManagerService = jaasSecurityManagerService;
} Deprecated! Maintained - for legacy
|
public void setJndiName(String jndiName) {
this.jndiName = jndiName;
}
|
public void setManagedConnectionPool(ObjectName newManagedConnectionPool) {
this.managedConnectionPoolName = newManagedConnectionPool;
}
|
public void setSecurityDomainJndiName(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;
}
|
public void setSubjectFactory(SubjectFactory subjectFactory) {
this.subjectFactory = subjectFactory;
}
|
protected void startService() throws Exception {
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 (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() throws Exception {
//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;
subjectFactory = null;
ccm = null;
}
|
public void transactionStarted(Collection conns) throws SystemException {
//reimplement in subclasses
}
|
protected void unregisterAssociation(ConnectionListener cl,
Object c) throws ResourceException {
cl.unregisterConnection(c);
}
|