List of usage examples for javax.jms JMSException printStackTrace
public void printStackTrace()
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * @param tickSize// www. ja v a2s. c o m * @param ttl * @param persistent */ public void publishTickSize(TickSize tickSize, MessageProducer mp) { BytesMessage tickMessage; try { Session session = this.createSession(); // Create a new ByteMessage tickMessage = session.createBytesMessage(); // Serialize the tick content into the message tickMessage.writeBytes(tickSize.serialize()); tickMessage.setStringProperty("Symbol", tickSize.getSymbol()); mp.send(tickMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.james.queue.activemq.ActiveMQMailQueue.java
/** * Try to use ActiveMQ StatisticsPlugin to get size and if that fails * fallback to {@link JMSMailQueue#getSize()} *//* w w w. ja v a2 s . c o m*/ @Override public long getSize() throws MailQueueException { Connection connection = null; Session session = null; MessageConsumer consumer = null; MessageProducer producer = null; TemporaryQueue replyTo = null; long size = -1; try { connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); replyTo = session.createTemporaryQueue(); consumer = session.createConsumer(replyTo); Queue myQueue = session.createQueue(queuename); producer = session.createProducer(null); String queueName = "ActiveMQ.Statistics.Destination." + myQueue.getQueueName(); Queue query = session.createQueue(queueName); Message msg = session.createMessage(); msg.setJMSReplyTo(replyTo); producer.send(query, msg); MapMessage reply = (MapMessage) consumer.receive(2000); if (reply != null && reply.itemExists("size")) { try { size = reply.getLong("size"); return size; } catch (NumberFormatException e) { // if we hit this we can't calculate the size so just catch // it } } } catch (Exception e) { throw new MailQueueException("Unable to remove mails", e); } finally { if (consumer != null) { try { consumer.close(); } catch (JMSException e1) { e1.printStackTrace(); // ignore on rollback } } if (producer != null) { try { producer.close(); } catch (JMSException e1) { // ignore on rollback } } if (replyTo != null) { try { // we need to delete the temporary queue to be sure we will // free up memory if thats not done and a pool is used // its possible that we will register a new mbean in jmx for // every TemporaryQueue which will never get unregistered replyTo.delete(); } catch (JMSException e) { } } try { if (session != null) session.close(); } catch (JMSException e1) { // ignore here } try { if (connection != null) connection.close(); } catch (JMSException e1) { // ignore here } } // if we came to this point we should just fallback to super method return super.getSize(); }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * @param tick//from ww w.ja v a 2 s. c om * @param ttl * @param persistent */ public void publishTick(Tick tick, MessageProducer mp) { BytesMessage tickMessage; try { Session session = this.createSession(); // Create a new ByteMessage tickMessage = session.createBytesMessage(); // Serialize the tick content into the message tickMessage.writeBytes(tick.serialize()); tickMessage.setStringProperty("Symbol", tick.getSymbol()); tickMessage.setStringProperty("Currency", tick.getCurrency()); mp.send(tickMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * // ww w . j a va2 s .c o m * @param tick * @param ttl * @param persistent */ public void publishTicks(Tick[] tick, MessageProducer mp) { BytesMessage tickMessage; try { Session session = this.createSession(); for (int i = 0; i < tick.length; i++) { // Create a new ByteMessage tickMessage = session.createBytesMessage(); // Serialize the tick content into the message tickMessage.writeBytes(tick[i].serialize()); tickMessage.setStringProperty("Symbol", tick[i].getSymbol()); tickMessage.setStringProperty("Currency", tick[i].getCurrency()); mp.send(tickMessage); } this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * Publish a simulation request/*from w ww.j ava2 s . c o m*/ * * @param sr * @param ttl * @param persistent */ public void publishSimulationRequest(SimulationRequest sr, MessageProducer mp) { BytesMessage simulationMessage; try { Session session = this.createSession(); // Create a new ByteMessage simulationMessage = session.createBytesMessage(); // Serialize the simulation request content into the message simulationMessage.writeBytes(sr.serialize()); simulationMessage.setStringProperty("Symbol", sr.getSymbol()); simulationMessage.setStringProperty("LoadValues", String.valueOf(sr.getLoadValues())); simulationMessage.setStringProperty("StartDate", String.valueOf(sr.getStartDate())); simulationMessage.setStringProperty("EndDate", String.valueOf(sr.getEndDate())); mp.send(simulationMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.openmrs.event.EventEngine.java
/** * @see Event#subscribe(Destination, EventListener) *///from w ww . j a va 2 s . c o m public void subscribe(Destination destination, final EventListener listenerToRegister) { initializeIfNeeded(); TopicConnection conn; Topic topic = (Topic) destination; try { conn = (TopicConnection) jmsTemplate.getConnectionFactory().createConnection(); TopicSession session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = session.createSubscriber(topic); subscriber.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { listenerToRegister.onMessage(message); } }); //Check if this is a duplicate and remove it String key = topic.getTopicName() + DELIMITER + listenerToRegister.getClass().getName(); if (subscribers.containsKey(key)) { unsubscribe(destination, listenerToRegister); } subscribers.put(key, subscriber); conn.start(); } catch (JMSException e) { // TODO Auto-generated catch block. Do something smarter here. e.printStackTrace(); } // List<EventListener> currentListeners = listeners.get(key); // // if (currentListeners == null) { // currentListeners = new ArrayList<EventListener>(); // currentListeners.add(listenerToRegister); // listeners.put(key, currentListeners); // if (log.isInfoEnabled()) // log.info("subscribed: " + listenerToRegister + " to key: " // + key); // // } else { // // prevent duplicates because of weird spring loading // String listernToRegisterName = listenerToRegister.getClass() // .getName(); // Iterator<EventListener> iterator = currentListeners.iterator(); // while (iterator.hasNext()) { // EventListener lstnr = iterator.next(); // if (lstnr.getClass().getName().equals(listernToRegisterName)) // iterator.remove(); // } // // if (log.isInfoEnabled()) // log.info("subscribing: " + listenerToRegister + " to key: " // + key); // // currentListeners.add(listenerToRegister); // } }
From source file:com.alliander.osgp.acceptancetests.adhocmanagement.ResumeScheduleSteps.java
@DomainStep("a resume schedule response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)") public void givenAResumeScheduleResponseMessageIsFoundInTheQueue(final String correlationId, final String deviceId, final String qresult, final String qdescription, final Boolean isFound) { LOGGER.info(/* ww w. j av a 2 s. c om*/ "GIVEN: \"a resume schedule response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}\".", correlationId, deviceId, qresult, qdescription, isFound); if (isFound) { final ObjectMessage messageMock = mock(ObjectMessage.class); try { when(messageMock.getJMSCorrelationID()).thenReturn(correlationId); when(messageMock.getStringProperty("OrganisationIdentification")) .thenReturn(this.organisation.getOrganisationIdentification()); when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId); final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult); Serializable dataObject = null; OsgpException exception = null; if (result.equals(ResponseMessageResultType.NOT_OK)) { dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.UNKNOWN, new ValidationException()); exception = (OsgpException) dataObject; } final ResponseMessage message = new ResponseMessage(correlationId, this.organisation.getOrganisationIdentification(), deviceId, result, exception, dataObject); when(messageMock.getObject()).thenReturn(message); } catch (final JMSException e) { e.printStackTrace(); } when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class))) .thenReturn(messageMock); } else { when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null); } }
From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StartDeviceTestSteps.java
@DomainStep("a start device test response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)") public void givenAStartDeviceTestResponseMessageIsFoundInTheQueue(final String correlationId, final String deviceId, final String qresult, final String qdescription, final Boolean isFound) { LOGGER.info(//ww w . j av a2 s.c o m "a start device test response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}", correlationId, deviceId, qresult, qdescription, isFound); if (isFound) { final ObjectMessage messageMock = mock(ObjectMessage.class); try { when(messageMock.getJMSCorrelationID()).thenReturn(correlationId); when(messageMock.getStringProperty("OrganisationIdentification")) .thenReturn(this.organisation.getOrganisationIdentification()); when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId); final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult); Serializable dataObject = null; OsgpException exception = null; if (result.equals(ResponseMessageResultType.NOT_OK)) { dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.UNKNOWN, new ValidationException()); exception = (OsgpException) dataObject; } final ResponseMessage message = new ResponseMessage(correlationId, this.organisation.getOrganisationIdentification(), deviceId, result, exception, dataObject); when(messageMock.getObject()).thenReturn(message); } catch (final JMSException e) { e.printStackTrace(); } when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock); } else { when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null); } }
From source file:org.frameworkset.mq.ReceiveDispatcher.java
public void stop(boolean remove) // throws JMSException { if (stopped)/*from w w w. j av a 2 s. com*/ return; if (this.session != null) { if (this.transacted // && !this.rollbacked // && !this.commited ) { try { this.rollback(); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { session.close(); } catch (Exception e) { } } // this.mqclient.removeReceivor(this); this.stopped = true; }
From source file:de.fraunhofer.iosb.ivct.IVCTcommander.java
/** * sendToJms// www . j av a 2 s. c om */ public void sendToJms(final String userCommand) { Message message = jmshelper.createTextMessage(userCommand); try { producer.send(message); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }