Top Description Fields Constructors Methods
org.springframework.jca.endpoint

public Class GenericMessageEndpointManager

extends Object
implements SmartLifecycle, InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.context.Phased, org.springframework.context.Lifecycle
Imports
jakarta.resource.ResourceException, jakarta.resource.spi.ActivationSpec, .ResourceAdapter, jakarta.resource.spi.endpoint.MessageEndpointFactory, org.springframework.beans.factory.DisposableBean, .InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.lang.Nullable, org.springframework.util.Assert

Generic bean that manages JCA 1.7 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="jakarta.jms.Queue"/>
   </bean>
 </property>
</bean>

In this example, Spring's own GenericMessageEndpointFactory is used to point to a standard message listener object that happens to be supported by the specified target ResourceAdapter: in this case, a JMS jakarta.jms.MessageListener 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. 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="..."/>
 </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 CCI jakarta.resource.cci.MessageListener 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, where <bean class="..."/> should be replaced with configuration for any JCA-compliant WorkManager.

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 Spring org.springframework.transaction.jta.JtaTransactionManager or a plain jakarta.transaction.TransactionManager 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="jakarta.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="jakarta.jms.Queue"/>
     <property name="useRAManagedTransaction" value="true"/>
   </bean>
 </property>
</bean>
Author
Juergen Hoeller
Since
2.5
See Also
jakarta.resource.spi.ResourceAdapter#endpointActivation, jakarta.resource.spi.ResourceAdapter#endpointDeactivation, jakarta.resource.spi.endpoint.MessageEndpointFactory, jakarta.resource.spi.ActivationSpec

Field Summary

Modifier and TypeField and Description
private ActivationSpec
private boolean
private final Object
private MessageEndpointFactory
private int
private ResourceAdapter
private volatile boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Prepares the message endpoint, and automatically activates it if the "autoStartup" flag is set to "true".

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Deactivates the message endpoint, preparing it for shutdown.

public ActivationSpec
getActivationSpec()

Return the JCA ActivationSpec to use for activating the endpoint.

public MessageEndpointFactory
getMessageEndpointFactory()

Return the JCA MessageEndpointFactory to activate.

public int
getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase in which this endpoint manager will be started and stopped.

public ResourceAdapter
getResourceAdapter()

Return the JCA ResourceAdapter to manage endpoints for.

public boolean
isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Return whether the configured message endpoint is currently active.

public void
setActivationSpec(ActivationSpec activationSpec)

Set the JCA ActivationSpec to use for activating the endpoint.

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.

public void
setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)

Set the JCA MessageEndpointFactory to activate, pointing to a MessageListener object that the endpoints will delegate to.

public void
setPhase(int phase)

Specify the phase in which this endpoint manager should be started and stopped.

public void
setResourceAdapter(ResourceAdapter resourceAdapter)

Set the JCA ResourceAdapter to manage endpoints for.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Activates the configured message endpoint.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Deactivates the configured message endpoint.

public void
stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Indicates that a Lifecycle component must stop if it is currently running.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activationSpecback to summary
private ActivationSpec activationSpec
Annotations
@Nullable
autoStartupback to summary
private boolean autoStartup
lifecycleMonitorback to summary
private final Object lifecycleMonitor
messageEndpointFactoryback to summary
private MessageEndpointFactory messageEndpointFactory
Annotations
@Nullable
phaseback to summary
private int phase
resourceAdapterback to summary
private ResourceAdapter resourceAdapter
Annotations
@Nullable
runningback to summary
private volatile boolean running

Constructor Detail

GenericMessageEndpointManagerback to summary
public GenericMessageEndpointManager()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws ResourceException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Prepares the message endpoint, and automatically activates it if the "autoStartup" flag is set to "true".

Annotations
@Override
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Deactivates the message endpoint, preparing it for shutdown.

Annotations
@Override
getActivationSpecback to summary
public ActivationSpec getActivationSpec()

Return the JCA ActivationSpec to use for activating the endpoint.

Annotations
@Nullable
getMessageEndpointFactoryback to summary
public MessageEndpointFactory getMessageEndpointFactory()

Return the JCA MessageEndpointFactory to activate.

Annotations
@Nullable
getPhaseback to summary
public int getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase in which this endpoint manager will be started and stopped.

Annotations
@Override
getResourceAdapterback to summary
public ResourceAdapter getResourceAdapter()

Return the JCA ResourceAdapter to manage endpoints for.

Annotations
@Nullable
isAutoStartupback to summary
public boolean isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property. If "true", this endpoint manager will start upon a ContextRefreshedEvent.

Annotations
@Override
isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Return whether the configured message endpoint is currently active.

Returns:boolean

Doc from org.springframework.context.Lifecycle.isRunning.

whether the component is currently running

Annotations
@Override
setActivationSpecback to summary
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.

setAutoStartupback to summary
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.

setMessageEndpointFactoryback to summary
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.

See Also
GenericMessageEndpointFactory#setMessageListener
setPhaseback to summary
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.

setResourceAdapterback to summary
public void setResourceAdapter(ResourceAdapter resourceAdapter)

Set the JCA ResourceAdapter to manage endpoints for.

startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Activates the configured message endpoint.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Deactivates the configured message endpoint.

Annotations
@Override
stopback to summary
public void stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Doc from org.springframework.context.SmartLifecycle.stop.

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 the SmartLifecycle component does indeed stop.

The LifecycleProcessor will call only this variant of the stop method; i.e. Lifecycle#stop() will not be called for SmartLifecycle implementations unless explicitly delegated to within the implementation of this method.

The default implementation delegates to stop() and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).

Annotations
@Override