类 GenericMessageEndpointManager
- java.lang.Object
- org.springframework.jca.endpoint.GenericMessageEndpointManager
- 所有已实现的接口:
DisposableBean
,InitializingBean
,Lifecycle
,Phased
,SmartLifecycle
- 直接已知子类:
JmsMessageEndpointManager
public class GenericMessageEndpointManager extends Object implements SmartLifecycle, InitializingBean, DisposableBean
Generic bean that manages JCA 1.5 message endpoints within a Spring application context, activating and deactivating the endpoint as part of the application context's lifecycle.This class is completely generic in that it may work with any ResourceAdapter, any MessageEndpointFactory, and any ActivationSpec. It can be configured in standard bean style, for example through Spring's XML bean definition format, as follows:
<bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager"> <property name="resourceAdapter" ref="resourceAdapter"/> <property name="messageEndpointFactory"> <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory"> <property name="messageListener" ref="messageListener"/> </bean> </property> <property name="activationSpec"> <bean class="org.apache.activemq.ra.ActiveMQActivationSpec"> <property name="destination" value="myQueue"/> <property name="destinationType" value="javax.jms.Queue"/> </bean> </property> </bean>
In this example, Spring's ownGenericMessageEndpointFactory
is used to point to a standard message listener object that happens to be supported by the specified target ResourceAdapter: in this case, a JMSMessageListener
object as supported by the ActiveMQ message broker, defined as a Spring bean:<bean id="messageListener" class="com.myorg.messaging.myMessageListener"> ... </bean>
The target ResourceAdapter may be configured as a local Spring bean as well (the typical case) or obtained from JNDI (e.g. on WebLogic). For the example above, a local ResourceAdapter bean could be defined as follows (matching the "resourceAdapter" bean reference above):<bean id="resourceAdapter" class="org.springframework.jca.support.ResourceAdapterFactoryBean"> <property name="resourceAdapter"> <bean class="org.apache.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl" value="tcp://localhost:61616"/> </bean> </property> <property name="workManager"> <bean class="org.springframework.jca.work.SimpleTaskWorkManager"/> </property> </bean>
For a different target resource, the configuration would simply point to a different ResourceAdapter and a different ActivationSpec object (which are both specific to the resource provider), and possibly a different message listener (e.g. a CCIMessageListener
for a resource adapter which is based on the JCA Common Client Interface).The asynchronous execution strategy can be customized through the "workManager" property on the ResourceAdapterFactoryBean (as shown above). Check out
SimpleTaskWorkManager
's javadoc for its configuration options; alternatively, any other JCA-compliant WorkManager can be used (e.g. Geronimo's).Transactional execution is a responsibility of the concrete message endpoint, as built by the specified MessageEndpointFactory.
GenericMessageEndpointFactory
supports XA transaction participation through its "transactionManager" property, typically with a SpringJtaTransactionManager
or a plainTransactionManager
implementation specified there.<bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager"> <property name="resourceAdapter" ref="resourceAdapter"/> <property name="messageEndpointFactory"> <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory"> <property name="messageListener" ref="messageListener"/> <property name="transactionManager" ref="transactionManager"/> </bean> </property> <property name="activationSpec"> <bean class="org.apache.activemq.ra.ActiveMQActivationSpec"> <property name="destination" value="myQueue"/> <property name="destinationType" value="javax.jms.Queue"/> </bean> </property> </bean> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
Alternatively, check out your resource provider's ActivationSpec object, which should support local transactions through a provider-specific config flag, e.g. ActiveMQActivationSpec's "useRAManagedTransaction" bean property.<bean class="org.springframework.jca.endpoint.GenericMessageEndpointManager"> <property name="resourceAdapter" ref="resourceAdapter"/> <property name="messageEndpointFactory"> <bean class="org.springframework.jca.endpoint.GenericMessageEndpointFactory"> <property name="messageListener" ref="messageListener"/> </bean> </property> <property name="activationSpec"> <bean class="org.apache.activemq.ra.ActiveMQActivationSpec"> <property name="destination" value="myQueue"/> <property name="destinationType" value="javax.jms.Queue"/> <property name="useRAManagedTransaction" value="true"/> </bean> </property> </bean>
- 从以下版本开始:
- 2.5
- 作者:
- Juergen Hoeller
- 另请参阅:
ResourceAdapter.endpointActivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
,ResourceAdapter.endpointDeactivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
,MessageEndpointFactory
,ActivationSpec
构造器概要
构造器 构造器 说明 GenericMessageEndpointManager()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Prepares the message endpoint, and automatically activates it if the "autoStartup" flag is set to "true".void
destroy()
Deactivates the message endpoint, preparing it for shutdown.ActivationSpec
getActivationSpec()
Return the JCA ActivationSpec to use for activating the endpoint.MessageEndpointFactory
getMessageEndpointFactory()
Return the JCA MessageEndpointFactory to activate.int
getPhase()
Return the phase in which this endpoint manager will be started and stopped.ResourceAdapter
getResourceAdapter()
Return the JCA ResourceAdapter to manage endpoints for.boolean
isAutoStartup()
Return the value for the 'autoStartup' property.boolean
isRunning()
Return whether the configured message endpoint is currently active.void
setActivationSpec(ActivationSpec activationSpec)
Set the JCA ActivationSpec to use for activating the endpoint.void
setAutoStartup(boolean autoStartup)
Set whether to auto-start the endpoint activation after this endpoint manager has been initialized and the context has been refreshed.void
setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)
Set the JCA MessageEndpointFactory to activate, pointing to a MessageListener object that the endpoints will delegate to.void
setPhase(int phase)
Specify the phase in which this endpoint manager should be started and stopped.void
setResourceAdapter(ResourceAdapter resourceAdapter)
Set the JCA ResourceAdapter to manage endpoints for.void
start()
Activates the configured message endpoint.void
stop()
Deactivates the configured message endpoint.void
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
构造器详细资料
GenericMessageEndpointManager
public GenericMessageEndpointManager()
方法详细资料
setResourceAdapter
public void setResourceAdapter(ResourceAdapter resourceAdapter)
Set the JCA ResourceAdapter to manage endpoints for.
getResourceAdapter
public ResourceAdapter getResourceAdapter()
Return the JCA ResourceAdapter to manage endpoints for.
setMessageEndpointFactory
public void setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)
Set the JCA MessageEndpointFactory to activate, pointing to a MessageListener object that the endpoints will delegate to.A MessageEndpointFactory instance may be shared across multiple endpoints (i.e. multiple GenericMessageEndpointManager instances), with different
ActivationSpec
objects applied.
getMessageEndpointFactory
public MessageEndpointFactory getMessageEndpointFactory()
Return the JCA MessageEndpointFactory to activate.
setActivationSpec
public void setActivationSpec(ActivationSpec activationSpec)
Set the JCA ActivationSpec to use for activating the endpoint.Note that this ActivationSpec instance should not be shared across multiple ResourceAdapter instances.
getActivationSpec
public ActivationSpec getActivationSpec()
Return the JCA ActivationSpec to use for activating the endpoint.
setAutoStartup
public void setAutoStartup(boolean autoStartup)
Set whether to auto-start the endpoint activation after this endpoint manager has been initialized and the context has been refreshed.Default is "true". Turn this flag off to defer the endpoint activation until an explicit
start()
call.
isAutoStartup
public boolean isAutoStartup()
Return the value for the 'autoStartup' property. If "true", this endpoint manager will start upon a ContextRefreshedEvent.
setPhase
public void setPhase(int phase)
Specify the phase in which this endpoint manager should be started and stopped. The startup order proceeds from lowest to highest, and the shutdown order is the reverse of that. By default this value is Integer.MAX_VALUE meaning that this endpoint manager starts as late as possible and stops as soon as possible.
getPhase
public int getPhase()
Return the phase in which this endpoint manager will be started and stopped.
afterPropertiesSet
public void afterPropertiesSet() throws ResourceException
Prepares the message endpoint, and automatically activates it if the "autoStartup" flag is set to "true".- 指定者:
afterPropertiesSet
在接口中InitializingBean
- 抛出:
ResourceException
start
public void start()
Activates the configured message endpoint.- 指定者:
start
在接口中Lifecycle
- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public void stop()
Deactivates the configured message endpoint.- 指定者:
stop
在接口中Lifecycle
- 另请参阅:
SmartLifecycle.stop(Runnable)
,DisposableBean.destroy()
stop
public void stop(Runnable callback)
从接口复制的说明:SmartLifecycle
Indicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessor
to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecycle
component does indeed stop.The
LifecycleProcessor
will call only this variant of thestop
method; i.e.Lifecycle.stop()
will not be called forSmartLifecycle
implementations unless explicitly delegated to within the implementation of this method.- 指定者:
stop
在接口中SmartLifecycle
- 另请参阅:
Lifecycle.stop()
,Phased.getPhase()
isRunning
public boolean isRunning()
Return whether the configured message endpoint is currently active.
destroy
public void destroy()
Deactivates the message endpoint, preparing it for shutdown.- 指定者:
destroy
在接口中DisposableBean