public class ConnectionContextFactory extends Object implements AutoCloseable
producer or
consumer contexts. You can then pass these created contexts to
MessageProcessor to send and receive messages.
This class can cache a connection that can then be used to share across multiple contexts. See
createOrReuseConnection(ConnectionContext, boolean).
When you are done with sending and receiving messages through the created contexts, you should call close()
to free up resources and close all connections to the broker.
Subclasses are free to extend this class to add or override functionality or to provide stricter type-checking.| Modifier and Type | Field and Description |
|---|---|
protected javax.jms.ConnectionFactory |
connectionFactory |
| Constructor and Description |
|---|
ConnectionContextFactory(javax.jms.ConnectionFactory connectionFactory)
Initializes with the given factory.
|
ConnectionContextFactory(String brokerURL)
Initializes the factory with the given broker URL.
|
ConnectionContextFactory(String brokerURL,
String username,
String password)
Initializes the factory with the given broker URL and the given security credentials.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method should be called when this context factory is no longer needed.
|
protected void |
createConnection(ConnectionContext context)
Creates a connection using this object's connection factory and stores
that connection in the given context object.
|
protected void |
createConsumer(ConsumerConnectionContext context,
String messageSelector)
Creates a message consumer using the context's session and destination.
|
ConsumerConnectionContext |
createConsumerConnectionContext(Endpoint endpoint)
Creates a new consumer connection context, reusing any existing connection that might have already been created.
|
ConsumerConnectionContext |
createConsumerConnectionContext(Endpoint endpoint,
String messageSelector)
Creates a new consumer connection context, reusing any existing connection that might have
already been created.
|
protected void |
createDestination(ConnectionContext context,
Endpoint endpoint)
Creates a destination using the context's session.
|
protected void |
createOrReuseConnection(ConnectionContext context,
boolean start)
This method provides a way to cache and share a connection across
multiple contexts.
|
protected void |
createProducer(ProducerConnectionContext context)
Creates a message producer using the context's session and destination.
|
ProducerConnectionContext |
createProducerConnectionContext(Endpoint endpoint)
Creates a new producer connection context, reusing any existing connection that might have already been created.
|
protected void |
createSession(ConnectionContext context)
Creates a default session using the context's connection.
|
protected javax.jms.Connection |
getConnection()
The stored connection.
|
protected javax.jms.ConnectionFactory |
getConnectionFactory() |
protected void |
setConnection(javax.jms.Connection connection)
To store a connection in this processor object, call this setter.
|
public ConnectionContextFactory(String brokerURL) throws javax.jms.JMSException
brokerURL - the broker that is used for the contexts created by this factory;
all messages sent and received through the contexts will go through this broker.javax.jms.JMSException - any errorpublic ConnectionContextFactory(String brokerURL, String username, String password) throws javax.jms.JMSException
brokerURL - the broker that is used for the contexts created by this factory;
all messages sent and received through the contexts will go through this broker.username - user to connect topassword - credentials of userjavax.jms.JMSException - any errorpublic ConnectionContextFactory(javax.jms.ConnectionFactory connectionFactory)
throws javax.jms.JMSException
connectionFactory - the factory that will be used to create contexts.javax.jms.JMSException - any errorpublic ProducerConnectionContext createProducerConnectionContext(Endpoint endpoint) throws javax.jms.JMSException
endpoint - where the producer will send messagesjavax.jms.JMSException - any errorpublic ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint) throws javax.jms.JMSException
endpoint - where the consumer will listen for messagesjavax.jms.JMSException - any errorpublic ConsumerConnectionContext createConsumerConnectionContext(Endpoint endpoint, String messageSelector) throws javax.jms.JMSException
endpoint - where the consumer will listen for messagesmessageSelector - message consumer's message selector expression.javax.jms.JMSException - any errorpublic void close()
throws javax.jms.JMSException
close in interface AutoCloseablejavax.jms.JMSException - any errorprotected javax.jms.ConnectionFactory getConnectionFactory()
protected javax.jms.Connection getConnection()
createConnection(ConnectionContext).createConnection(ConnectionContext)protected void setConnection(javax.jms.Connection connection)
createConnection(ConnectionContext) does
not set this processor's connection - that method only creates the
connection and puts that connection in the context. It does not save that
connection in this processor object. You must explicitly set the
connection via this method if you want that connection cached here. See
also createOrReuseConnection(ConnectionContext, boolean).connection - the connectioncreateOrReuseConnection(ConnectionContext, boolean)protected void createOrReuseConnection(ConnectionContext context, boolean start) throws javax.jms.JMSException
getConnection() is non-null). If
there is no connection yet, one will be created. Whether the connection
is created or reused, that connection will be stored in the given
context.context - the connection will be stored in this contextstart - if true, the created connection will be started.javax.jms.JMSException - any errorprotected void createConnection(ConnectionContext context) throws javax.jms.JMSException
setConnection(Connection) must be passed the connection
found in the context after this method returns. See also
createOrReuseConnection(ConnectionContext, boolean).context - the context where the new connection is storedjavax.jms.JMSException - any errorIllegalStateException - if the context is nullcreateOrReuseConnection(ConnectionContext, boolean),
setConnection(Connection)protected void createSession(ConnectionContext context) throws javax.jms.JMSException
context - the context where the new session is storedjavax.jms.JMSException - any errorIllegalStateException - if the context is null or the context's connection is nullprotected void createDestination(ConnectionContext context, Endpoint endpoint) throws javax.jms.JMSException
context - the context where the new destination is storedendpoint - identifies the queue or topicjavax.jms.JMSException - any errorIllegalStateException - if the context is null or the context's session is null or endpoint is nullprotected void createProducer(ProducerConnectionContext context) throws javax.jms.JMSException
context - the context where the new producer is storedjavax.jms.JMSException - any errorIllegalStateException - if the context is null or the context's session is null
or the context's destination is nullprotected void createConsumer(ConsumerConnectionContext context, String messageSelector) throws javax.jms.JMSException
context - the context where the new consumer is storedmessageSelector - the message selector expression that the consumer will use to filter messagesjavax.jms.JMSException - any errorIllegalStateException - if the context is null or the context's session is null
or the context's destination is nullCopyright © 2015 Red Hat, Inc.. All rights reserved.