List of usage examples for javax.jms TemporaryTopic delete
void delete() throws JMSException;
From source file:org.grouter.common.jms.TopicListenerDestination.java
/** * <br>// w ww. j a v a 2 s . co m */ public void sendReplyToTemporaryDestination(Message request) { TemporaryTopic replyTopic = null; TopicPublisher tempsender = null; String temporaryDestinationName = null; try { if (request.getJMSReplyTo() == null) { throw new IllegalStateException("The sender of this message has not entered a JMSReplyTo field - " + "impossible to send reply on temporary destination!!"); } temporaryDestinationName = request.getJMSReplyTo().toString(); request.setJMSCorrelationID(request.getJMSMessageID()); logger.debug("JMSCorrelationID was set!!!" + request.getJMSCorrelationID()); replyTopic = (TemporaryTopic) request.getJMSReplyTo(); tempsender = topicSession.createPublisher(replyTopic); logger.debug("Created a tempsender and sending reply to " + replyTopic); tempsender.send(request); } catch (JMSException ex) { //ignore logger.warn("Failed sending reply on temporary destination : " + temporaryDestinationName); } finally { try { if (tempsender != null) { tempsender.close(); } if (replyTopic != null) { replyTopic.delete(); } } catch (JMSException ex1) { //ignore } } }
From source file:org.openanzo.combus.bayeux.BridgeConnectionManager.java
/** * Sets up state for connecting a single Bayeux client to the BayeuxJMSBridge. * // w w w .j a v a2 s . c om * @param clientId * the Bayeux client id. * @return true if client was connected. false if there was already a connection for the client. */ protected boolean connectClient(String clientId, MessageListener listener, AnzoPrincipal principal) throws JMSException { // checks if connection already exists, create topic and client state, add to maps. boolean ret = false; boolean clientAlreadyConnected = false; mapLock.lock(); try { clientAlreadyConnected = clientIdToClientState.containsKey(clientId); } finally { mapLock.unlock(); } if (!clientAlreadyConnected) { // We don't have a temporary topic for this client yet so we'll create one. // We make sure to do this while NOT holding the mapLock to avoid deadlocks // (like http://www.openanzo.org/projects/openanzo/ticket/286). This // means that it's possible, in rare cases, that we could create a temp topic which we'll // have to just throw out immediately but there's not much harm in that. TemporaryTopic topic = session.createTemporaryTopic(); String tempDestinationId = topic.getTopicName(); MessageConsumer consumer = session.createConsumer(topic); consumer.setMessageListener(listener); boolean destroyNewJMSState = false; mapLock.lock(); try { if (clientIdToClientState.containsKey(clientId)) { // Some other thread seems to have connected this client while we were busy creating // JMS topics, etc. That's okay, we'll just close the topics we created since they aren't needed anymore. // But we don't want to destroy them while holding the mapLock, so we'll just mark a boolean so that they // are deleted after releasing the lock. destroyNewJMSState = true; } else { ClientState state = new ClientState(principal, topic, clientId, consumer); tempDestinationToClientState.put(tempDestinationId, state); clientIdToClientState.put(clientId, state); ret = true; } } finally { mapLock.unlock(); if (destroyNewJMSState) { consumer.close(); topic.delete(); } } } return ret; }
From source file:org.openanzo.combus.bayeux.BridgeConnectionManager.java
/** * Destroy all state including the JMS connection and Bayeux client state. * //from w w w.j a v a 2s.co m * @param bundleStopping * bundle stopping * @throws AnzoException */ protected void destroy(boolean bundleStopping) throws AnzoException { closed = true; topicDeletionTimeoutTimer.cancel(); topicDeletionTimeoutTimer = null; if (conn != null) { try { Collection<MessageConsumer> consumersToClose = null; Collection<TemporaryTopic> topicsToDelete = null; mapLock.lock(); try { if (bundleStopping) { Collection<MessageConsumer> graphTopicConsumersToClose = removeAllTopicSubscriptions(); consumersToClose = new ArrayList<MessageConsumer>( graphTopicConsumersToClose.size() + clientIdToClientState.size()); consumersToClose.addAll(graphTopicConsumersToClose); topicsToDelete = new ArrayList<TemporaryTopic>(clientIdToClientState.size()); for (Map.Entry<String, ClientState> entry : clientIdToClientState.entrySet()) { ClientState state = entry.getValue(); if (state != null) { consumersToClose.add(state.consumer); topicsToDelete.add(state.topic); } } } clientIdToClientState.clear(); } finally { mapLock.unlock(); } if (bundleStopping) { if (consumersToClose != null) { for (MessageConsumer consumer : consumersToClose) { if (consumer != null) { closeMessageConsumer(consumer); } } } if (topicsToDelete != null) { for (TemporaryTopic topic : topicsToDelete) { if (topic != null) { try { topic.delete(); } catch (JMSException jmsex) { log.warn(LogUtils.COMBUS_MARKER, "Error deleting bayuex connection manager temporary topic:" + topic.toString(), jmsex); } } } } if (session != null) { try { session.close(); } catch (JMSException jmsex) { log.warn(LogUtils.COMBUS_MARKER, "Error closing bayuex connection manager session", jmsex); } finally { session = null; } } } } finally { try { conn.close(); } catch (JMSException jmsex) { log.warn(LogUtils.COMBUS_MARKER, "Error closing bayuex connection manager connection", jmsex); } finally { conn = null; } } } }