/** * Creates a new consumer connection context, reusing any existing connection that might have already been created. * The destination of the connection's session will be that of the given endpoint. * * @param endpoint where the consumer will listen for messages * @return the new consumer connection context fully populated * @throws JMSException any error */ public ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint) throws JMSException { return createConsumerConnectionContext(endpoint, null); }
/** * Creates a new consumer connection context, reusing any existing connection that might have * already been created. The destination of the connection's session will be that of the given endpoint. * The consumer will filter messages based on the given message selector expression (which may be * null in which case the consumer will consume all messages). * * @param endpoint where the consumer will listen for messages * @param messageSelector message consumer's message selector expression. * @return the new consumer connection context fully populated * @throws JMSException any error */ public ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint, String messageSelector) throws JMSException { ConsumerConnectionContext context = new ConsumerConnectionContext(); createOrReuseConnection(context, true); createSession(context); createDestination(context, endpoint); createConsumer(context, messageSelector); return context; }
/** * Creates a new producer connection context, reusing any existing connection that might have already been created. * The destination of the connection's session will be that of the given endpoint. * * @param endpoint where the producer will send messages * @return the new producer connection context fully populated * @throws JMSException any error */ public ProducerConnectionContext createProducerConnectionContext(Endpoint endpoint) throws JMSException { ProducerConnectionContext context = new ProducerConnectionContext(); createOrReuseConnection(context, true); createSession(context); createDestination(context, endpoint); createProducer(context); return context; }
Connection conn; if (isReuseConnection()) { conn = getConnection(); if (conn != null) { } else { createConnection(context); conn = context.getConnection(); cacheConnection(conn, false); createConnection(context); conn = context.getConnection(); cacheConnection(conn, false); } catch (JMSException e) { msglog.errorFailedToStartConnection(e); cacheConnection(null, true); throw e;
@Override public ConsumerConnectionContext getConsumerConnectionContext() { ConsumerConnectionContext ctx = null; try { // here we build a faux consumer connection context whose data will be duplicated in // a producer connection context so the response message can be sent. The endpoint we // use here is just a dummy one - it will be replaced with the JMS ReplyTo by the superclass. ConnectionContextFactory ccf = new ConnectionContextFactory(getConnectionFactory()); ctx = ccf.createConsumerConnectionContext(Endpoint.TEMPORARY_QUEUE); } catch (Exception e) { log.error("Failed to build context - will not be able to respond to message", e); } return ctx; } }
/** * This will close its open connection that it has cached, thus freeing up resources. * This method should be called when this context factory is no longer needed. But realize * that any contexts that were created with the cached connection will be invalidated * since this method will close that connection. * * @throws JMSException any error */ @Override public void close() throws JMSException { cacheConnection(null, true); log.debugf("%s has been closed", this); }
/** * 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); }
Connection conn; if (isReuseConnection()) { conn = getConnection(); if (conn != null) { } else { createConnection(context); conn = context.getConnection(); cacheConnection(conn, false); createConnection(context); conn = context.getConnection(); cacheConnection(conn, false); } catch (JMSException e) { msglog.errorFailedToStartConnection(e); cacheConnection(null, true); throw e;
/** * This will close its open connection that it has cached, thus freeing up resources. * This method should be called when this context factory is no longer needed. But realize * that any contexts that were created with the cached connection will be invalidated * since this method will close that connection. * * @throws JMSException any error */ @Override public void close() throws JMSException { cacheConnection(null, true); log.debugf("%s has been closed", this); }
/** * 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 new producer connection context, reusing any existing connection that might have already been created. * The destination of the connection's session will be that of the given endpoint. * * @param endpoint where the producer will send messages * @return the new producer connection context fully populated * @throws JMSException any error */ public ProducerConnectionContext createProducerConnectionContext(Endpoint endpoint) throws JMSException { ProducerConnectionContext context = new ProducerConnectionContext(); createOrReuseConnection(context, true); createSession(context); createDestination(context, endpoint); createProducer(context); return context; }
/** * Creates a new consumer connection context, reusing any existing connection that might have * already been created. The destination of the connection's session will be that of the given endpoint. * The consumer will filter messages based on the given message selector expression (which may be * null in which case the consumer will consume all messages). * * @param endpoint where the consumer will listen for messages * @param messageSelector message consumer's message selector expression. * @return the new consumer connection context fully populated * @throws JMSException any error */ public ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint, String messageSelector) throws JMSException { ConsumerConnectionContext context = new ConsumerConnectionContext(); createOrReuseConnection(context, true); createSession(context); createDestination(context, endpoint); createConsumer(context, messageSelector); return context; }
/** * Creates a new consumer connection context, reusing any existing connection that might have already been created. * The destination of the connection's session will be that of the given endpoint. * * @param endpoint where the consumer will listen for messages * @return the new consumer connection context fully populated * @throws JMSException any error */ public ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint) throws JMSException { return createConsumerConnectionContext(endpoint, null); }