@Override public void close() throws IOException { if (producer != null) { try { producer.close(); } catch (JMSException e) { throw new IOException(e); } } super.close(); } }
/** * Creates a default session using the context's connection. This implementation creates a non-transacted, * auto-acknowledged session. Subclasses are free to override this behavior. * * @param context the context where the new session is stored * @throws JMSException any error * @throws IllegalStateException if the context is null or the context's connection is null */ protected void createSession(ConnectionContext context) throws JMSException { if (context == null) { throw new IllegalStateException("The context is null"); } Connection conn = context.getConnection(); if (conn == null) { throw new IllegalStateException("The context had a null connection"); } Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); context.setSession(session); }
throw new IllegalStateException("The context is null"); Session session = context.getSession(); if (session == null) { throw new IllegalStateException("The context had a null session"); context.setDestination(dest);
if (conn != null) { context.setConnection(conn); } else { conn = context.getConnection(); cacheConnection(conn, false); conn = context.getConnection(); cacheConnection(conn, false);
/** * Creates a text message that can be send via a producer that contains the given BasicMessage's JSON encoded data. * * @param context the context whose session is used to create the message * @param basicMessage contains the data that will be JSON-encoded and encapsulated in the created message, with * optional headers included * @param headers headers for the Message that will override same-named headers in the basic message * @return the message that can be produced * @throws JMSException any error * @throws NullPointerException if the context is null or the context's session is null */ protected Message createMessage(ConnectionContext context, BasicMessage basicMessage, Map<String, String> headers) throws JMSException { if (context == null) { throw new IllegalArgumentException("The context is null"); } if (basicMessage == null) { throw new IllegalArgumentException("The message is null"); } Session session = context.getSession(); if (session == null) { throw new IllegalArgumentException("The context had a null session"); } TextMessage msg = session.createTextMessage(basicMessage.toJSON()); setHeaders(basicMessage, headers, msg); log.debugf("Created text message [%s] with text [%s]", msg, msg.getText()); return msg; }
/** * Creates a connection using this object's connection factory and stores * that connection in the given context object. * * NOTE: this does <b>not</b> set the connection in this processor object. * If the caller wants the created connection cached in this processor * object, {@link #cacheConnection} must be passed the connection * found in the context after this method returns. See also * {@link #createOrReuseConnection(ConnectionContext, boolean)}. * * @param context the context where the new connection is stored * @throws JMSException any error * @throws IllegalStateException if the context is null * * @see #createOrReuseConnection(ConnectionContext, boolean) * @see #cacheConnection */ protected void createConnection(ConnectionContext context) throws JMSException { if (context == null) { throw new IllegalStateException("The context is null"); } ConnectionFactory factory = getConnectionFactory(); Connection conn = factory.createConnection(); context.setConnection(conn); }
throw new IllegalStateException("The context is null"); Session session = context.getSession(); if (session == null) { throw new IllegalStateException("The context had a null session"); context.setDestination(dest);
if (conn != null) { context.setConnection(conn); } else { conn = context.getConnection(); cacheConnection(conn, false); conn = context.getConnection(); cacheConnection(conn, false);
/** * Creates a text message that can be send via a producer that contains the given BasicMessage's JSON encoded data. * * @param context the context whose session is used to create the message * @param basicMessage contains the data that will be JSON-encoded and encapsulated in the created message, with * optional headers included * @param headers headers for the Message that will override same-named headers in the basic message * @return the message that can be produced * @throws JMSException any error * @throws NullPointerException if the context is null or the context's session is null */ protected Message createMessage(ConnectionContext context, BasicMessage basicMessage, Map<String, String> headers) throws JMSException { if (context == null) { throw new IllegalArgumentException("The context is null"); } if (basicMessage == null) { throw new IllegalArgumentException("The message is null"); } Session session = context.getSession(); if (session == null) { throw new IllegalArgumentException("The context had a null session"); } TextMessage msg = session.createTextMessage(basicMessage.toJSON()); setHeaders(basicMessage, headers, msg); log.infof("Created text message [%s] with text [%s]", msg, msg.getText()); return msg; }
/** * Creates a connection using this object's connection factory and stores * that connection in the given context object. * * NOTE: this does <b>not</b> set the connection in this processor object. * If the caller wants the created connection cached in this processor * object, {@link #cacheConnection} must be passed the connection * found in the context after this method returns. See also * {@link #createOrReuseConnection(ConnectionContext, boolean)}. * * @param context the context where the new connection is stored * @throws JMSException any error * @throws IllegalStateException if the context is null * * @see #createOrReuseConnection(ConnectionContext, boolean) * @see #cacheConnection */ protected void createConnection(ConnectionContext context) throws JMSException { if (context == null) { throw new IllegalStateException("The context is null"); } ConnectionFactory factory = getConnectionFactory(); Connection conn = factory.createConnection(); context.setConnection(conn); }
/** * Creates a default session using the context's connection. This implementation creates a non-transacted, * auto-acknowledged session. Subclasses are free to override this behavior. * * @param context the context where the new session is stored * @throws JMSException any error * @throws IllegalStateException if the context is null or the context's connection is null */ protected void createSession(ConnectionContext context) throws JMSException { if (context == null) { throw new IllegalStateException("The context is null"); } Connection conn = context.getConnection(); if (conn == null) { throw new IllegalStateException("The context had a null connection"); } Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); context.setSession(session); }
@Override public void close() throws IOException { if (producer != null) { try { producer.close(); } catch (JMSException e) { throw new IOException(e); } } super.close(); } }
Session session = context.getSession(); if (session == null) { throw new IllegalArgumentException("The context had a null session");
@Override public void close() throws IOException { if (consumer != null) { try { consumer.close(); } catch (JMSException e) { throw new IOException(e); } } super.close(); } }
Session session = context.getSession(); if (session == null) { throw new IllegalArgumentException("The context had a null session");
@Override public void close() throws IOException { if (consumer != null) { try { consumer.close(); } catch (JMSException e) { throw new IOException(e); } } super.close(); } }