producer.initialize(settings);
producer.start();
}
catch (Exception e)
{
throw new MessageException(e);
}
}
else
{
producer = topicProducers.removeFirst();
}
topicProducers.addLast(producer);
}
}
else if (settings.getDestinationType().equals(QUEUE))
{
synchronized (queueProducers)
{
if (queueProducers.size() < settings.getMaxProducers())
{
producer = new JMSQueueProducer();
try
{
producer.initialize(settings);
producer.start();
}
catch (Exception e)
{
throw new MessageException(e);
}
}
else
{
producer = queueProducers.removeFirst();
}
queueProducers.addLast(producer);
}
}
try
{
if (producer != null)
producer.sendMessage(message);
}
catch (JMSException jmsEx)
{
// At this point we give up on this producer, so we just
// stop and remove it from the pool.
if (settings.getDestinationType().equals(TOPIC))
{
synchronized (topicProducers)
{
if (producer != null)
{
producer.stop();
topicProducers.remove(producer);
}
}
}
else if (settings.getDestinationType().equals(QUEUE))
{
synchronized (queueProducers)
{
if (producer != null)
{
producer.stop();
queueProducers.remove(producer);
}
}
}
throw new MessageException(jmsEx);
}
return null;
}