public void broadcastTextMessage ( String topicName , String textMessage , int delaySeconds ) throws NamingException , JMSException , ServiceLocatorException { if ( mdwMessageProducer != null ) { mdwMessageProducer . broadcastMessageToTopic ( topicName , textMessage ) ; } else { TopicConnectionFactory tFactory = null ; TopicConnection tConnection = null ; TopicSession tSession = null ; TopicPublisher tPublisher = null ; try { // if (logger.isDebugEnabled()) logger.debug("broadcast JMS // message: " + // textMessage); // cannot log above - causing recursive broadcasting tFactory = getTopicConnectionFactory ( null ) ; tConnection = tFactory . createTopicConnection ( ) ; tSession = tConnection . createTopicSession ( false , Session . AUTO_ACKNOWLEDGE ) ; Topic topic = getTopic ( topicName ) ; tPublisher = tSession . createPublisher ( topic ) ; // TODO: platform-independent delay // WLMessageProducer wlMessageProducer = // (WLMessageProducer)tPublisher; // long delayInMilliSec = 0; // if(pMinDelay > 0){ // delayInMilliSec = delaySeconds*1000; // } // wlMessageProducer.setTimeToDeliver(delayInMilliSec); TextMessage message = tSession . createTextMessage ( ) ; tConnection . start ( ) ; message . setText ( textMessage ) ; tPublisher . publish ( message , DeliveryMode . PERSISTENT , TextMessage . DEFAULT_DELIVERY_MODE , TextMessage . DEFAULT_TIME_TO_LIVE ) ; // }catch(ServiceLocatorException ex){ // ex.printStackTrace(); // never log exception here!!! infinite loop when publishing log // messages // throw new JMSException(ex.getMessage()); } finally { closeResources ( tConnection , tSession , tPublisher ) ; } } }
Sends the passed in text message to a local topic