/** * cleanup connection resources. */ protected void cleanup() { try { session.close(); connection.close(); session = null; connection = null; } catch (JMSException ex) { logger.debug(ex.getLocalizedMessage()); } }
/** * Implementation of {@link ExceptionListener} * * @param ex */ @Override public void onException(JMSException ex) { cleanup(); LOG.error(ex.getLocalizedMessage()); throwable.set(ex); throw new RuntimeException(ex); }
public void closeConnection() { try { consumer.close(); session.close(); connection.close(); } catch (JMSException ex) { logger.debug(ex.getLocalizedMessage()); } } }
@Override public void accept(final String key, final Object value) { try { jmsMapMessage.setObject(key, value); } catch (final JMSException e) { throw new IllegalArgumentException(String.format("%s mapping key '%s' to value '%s': %s", e.getClass(), key, value, e.getLocalizedMessage()), e); } } });
@Override public void onMessage(Message message) { // Stop listener if captured maximum messages. if (countMessages++ >= maximumReceiveMessages && maximumReceiveMessages != 0) { try { logger.warn("Reached maximum receive messages of {}", maximumReceiveMessages); consumer.setMessageListener(null); } catch (JMSException ex) { logger.debug(ex.getLocalizedMessage()); } return; } }
private boolean closeConnection() { if (connection == null) { return true; } final Connection temp = connection; connection = null; try { temp.close(); return true; } catch (final JMSException e) { StatusLogger.getLogger().debug( "Caught exception closing JMS Connection: {} ({}); continuing JMS manager shutdown", e.getLocalizedMessage(), temp, e); return false; } }
private boolean closeMessageProducer() { if (messageProducer == null) { return true; } final MessageProducer temp = messageProducer; messageProducer = null; try { temp.close(); return true; } catch (final JMSException e) { StatusLogger.getLogger().debug( "Caught exception closing JMS MessageProducer: {} ({}); continuing JMS manager shutdown", e.getLocalizedMessage(), temp, e); return false; } }
private boolean closeSession() { if (session == null) { return true; } final Session temp = session; session = null; try { temp.close(); return true; } catch (final JMSException e) { StatusLogger.getLogger().debug( "Caught exception closing JMS Session: {} ({}); continuing JMS manager shutdown", e.getLocalizedMessage(), temp, e); return false; } }
/** * If getJMSReplyTo is set then send message back to reply producer. * * @param message */ protected void sendReply(Message message) { try { if (message.getJMSReplyTo() != null) { // Send reply only if the replyTo destination is set replyProducer.send(message.getJMSReplyTo(), getSession().createTextMessage("Reply: " + message.getJMSMessageID())); } } catch (JMSException ex) { LOG.error(ex.getLocalizedMessage()); throwable.set(ex); throw new RuntimeException(ex); } }
@Override public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("Incoming message event of type " + event.getClass().getSimpleName() + " from Catalog"); } // skip incoming events until context is loaded if (!isEnabled()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("skipping incoming event: context is not initted"); } return; } // update properties Properties options = getProperties(); try { jmsPublisher.publish(getTopic(), getJmsTemplate(), options, event); } catch (JMSException e) { if (LOGGER.isLoggable(java.util.logging.Level.SEVERE)) { LOGGER.severe(e.getLocalizedMessage()); } throw new CatalogException(e); } }
@Override public void commit() { try { if (session.getAcknowledgeMode() == Session.SESSION_TRANSACTED) { session.commit(); } } catch (JMSException e) { throw new BallerinaException("transaction commit failed: " + e.getLocalizedMessage(), e); } }
@Override public void rollback() { try { if (session.getAcknowledgeMode() == Session.SESSION_TRANSACTED) { session.rollback(); } } catch (JMSException e) { throw new BallerinaException("transaction rollback failed: " + e.getLocalizedMessage(), e); } }
@Override public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("Incoming message event of type " + event.getClass().getSimpleName() + " from Catalog"); } // skip incoming events until context is loaded if (!isEnabled()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("skipping incoming event: context is not initted"); } return; } // update properties Properties options = getProperties(); try { jmsPublisher.publish(getTopic(), getJmsTemplate(), options, event); } catch (JMSException e) { if (LOGGER.isLoggable(java.util.logging.Level.SEVERE)) { LOGGER.severe(e.getLocalizedMessage()); } throw new CatalogException(e); } }
@Override public void handleGlobalChange(GeoServerInfo global, List<String> propertyNames, List<Object> oldValues, List<Object> newValues) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("Incoming event"); } // skip incoming events if producer is not Enabled if (!isEnabled()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("skipping incoming event: context is not initted"); } return; } try { // update properties final Properties options = getProperties(); // propagate the event jmsPublisher.publish(getTopic(), getJmsTemplate(), options, new JMSGlobalModifyEvent(ModificationProxy.unwrap(global), propertyNames, oldValues, newValues)); } catch (JMSException e) { if (LOGGER.isLoggable(java.util.logging.Level.SEVERE)) { LOGGER.severe(e.getLocalizedMessage()); } } }
@Override public void handleGlobalChange(GeoServerInfo global, List<String> propertyNames, List<Object> oldValues, List<Object> newValues) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("Incoming event"); } // skip incoming events if producer is not Enabled if (!isEnabled()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine("skipping incoming event: context is not initted"); } return; } try { // update properties final Properties options = getProperties(); // propagate the event jmsPublisher.publish(getTopic(), getJmsTemplate(), options, new JMSGlobalModifyEvent(ModificationProxy.unwrap(global), propertyNames, oldValues, newValues)); } catch (JMSException e) { if (LOGGER.isLoggable(java.util.logging.Level.SEVERE)) { LOGGER.severe(e.getLocalizedMessage()); } } }
/** * Acknowledge the message * * @return true if ack is processed successfully. If there was some issue, * we call recover on session will return false */ public boolean ack() { try { if (message != null) { message.acknowledge(); } } catch (javax.jms.IllegalStateException e) { logger.warn("JMS Session is in an illegal state. Recovering session."); try { getSession().recover(); logger.warn("JMS Session recovered."); } catch (JMSException e1) { logger.error("Error occurred while recovering session: " + e.getLocalizedMessage(), e); return false; } return false; } catch (JMSException e) { logger.error(getId() + " cannot ack last read message. Error:" + e.getLocalizedMessage(), e); return false; } return true; }
/** * Create a JMS Message for the given tuple. * @return Message */ @Override protected Message createMessage(Object tuple) { try { if (tuple instanceof Message) { return (Message)tuple; } else if (tuple instanceof String) { return getSession().createTextMessage((String)tuple); } else if (tuple instanceof byte[]) { BytesMessage message = getSession().createBytesMessage(); message.writeBytes((byte[])tuple); return message; } else if (tuple instanceof Map) { return createMessageForMap((Map)tuple); } else if (tuple instanceof Serializable) { return getSession().createObjectMessage((Serializable)tuple); } else { throw new RuntimeException("Cannot convert object of type " + tuple.getClass() + "] to JMS message. Supported message " + "payloads are: String, byte array, Map<String,?>, Serializable object."); } } catch (JMSException ex) { logger.error(ex.getLocalizedMessage()); throw new RuntimeException(ex); } }
createConnection(); } catch (JMSException ex) { logger.debug(ex.getLocalizedMessage()); throw new RuntimeException(ex);
private void setTransportHeaders(Message message, MessageContext synCtx){ //Set transport headers to the message Map<?,?> headerMap = (Map<?,?>) ((Axis2MessageContext)synCtx).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if(headerMap != null) { for (Object headerName : headerMap.keySet()) { String name = (String) headerName; Object value = headerMap.get(name); try { if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } catch (JMSException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not save Message property: " + ex.getLocalizedMessage()); } } } } }
logger.debug("Could not save Message property: " + e.getLocalizedMessage());