*/
public void send(final Collection col)
{
if (!m_channel.isSendable())
{
throw new RPCException("err.rpc.notSender", new Object[]{m_channel.getName()});
}
if (s_logger.isDebugEnabled())
{
s_logger.debug("Sending " + col.size() + " message(s) on channel \"" +
m_channel.getName() + "\" to destination \"" + m_sDestination + "\"");
if (s_logger.isDumpEnabled())
{
int nCount = 0;
for (Iterator itr = col.iterator(); itr.hasNext();)
{
s_logger.dump("Message [" + nCount++ + "]: " + ((TransferObject)itr.next()));
}
}
}
if (m_bEnabled)
{
boolean bRetry = true;
ConnectionFactory factory;
Destination destination;
synchronized (this)
{
if (m_destination == null)
{
try
{
bind();
}
catch (Exception t)
{
s_logger.error("Failed to bind to " + m_sTypeName + " \"" +
m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")", t);
throw new RPCException("err.rpc.jms", t);
}
}
factory = m_connectionFactory;
destination = m_destination;
}
retry:
do
{
try
{
Connection connection = null;
Session session = null;
MessageProducer producer = null;
try
{
if (m_sUser == null)
{
connection = factory.createConnection();
}
else
{
connection = factory.createConnection(m_sUser, m_sPassword);
}
session = m_jmsStrategy.createSession(connection);
producer = session.createProducer(destination);
bRetry = false;
for (Iterator itr = col.iterator(); itr.hasNext();)
{
TransferObject tobj = (TransferObject)itr.next();
Boolean persistent = (Boolean)tobj.findValue(PERSISTENT);
int nPersistenceMode =
((persistent == null) ? m_channel.isPersistent() : persistent.booleanValue()) ?
DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
Number priority = (Number)tobj.findValue(PRIORITY);
int nPriority = (priority == null) ? m_channel.getPriority() : priority.intValue();
Number ttl = (Number)tobj.findValue(TTL);
long lTTL = (ttl == null) ? m_channel.getTimeToLive() : ttl.longValue();
m_sentCounter.add(1);
producer.send(createMessage(session, tobj), nPersistenceMode, nPriority, lTTL);
}
}
finally
{
if (producer != null)
{
try
{
producer.close();
}
catch (Exception e)
{
s_logger.error("Error closing the producer for destination \"" + m_sDestination + "\"", e);
}
}
if (session != null)
{
try
{
m_jmsStrategy.closeSession(session);
}
catch (Exception e)
{
s_logger.error("Error closing the session for connection factory \"" +
m_sConnectionFactory + "\"", e);
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (Exception e)
{
s_logger.error("Error closing the connection for connection factory \"" +
m_sConnectionFactory + "\"", e);
}
}
}
}
catch (Exception e)
{
if (bRetry)
{
bRetry = false;
for (Throwable x = e.getCause(); x != null; x = x.getCause())
{
if (x instanceof ResourceException || x instanceof IOException)
{
// The connection factory is stale, get a new one
if (s_logger.isInfoEnabled())
{
s_logger.info("Rebinding the stale " + m_sTypeName + " \"" +
m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")");
}
try
{
synchronized (this)
{
if (m_connectionFactory == factory &&
m_destination == destination)
{
bind();
}
factory = m_connectionFactory;
destination = m_destination;
}
}
catch (Exception mx)
{
s_logger.error("Failed to bind to " + m_sTypeName + " \"" +
m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")", mx);
throw new RPCException("err.rpc.jms", e);
}
continue retry;
}
}
}
throw new RPCException("err.rpc.jms", e);
}
}
while (bRetry);
}
else