Top Description Fields Constructors Methods
org.springframework.jms.support.destination

public Class JndiDestinationResolver

extends JndiLocatorSupport
implements CachingDestinationResolver
Class Inheritance
All Implemented Interfaces
org.springframework.jms.support.destination.CachingDestinationResolver, org.springframework.jms.support.destination.DestinationResolver
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, javax.naming.NamingException, jakarta.jms.Destination, .JMSException, .Queue, .Session, .Topic, org.springframework.jndi.JndiLocatorSupport, org.springframework.lang.Nullable, org.springframework.util.Assert

DestinationResolver implementation which interprets destination names as JNDI locations (with a configurable fallback strategy).

Allows for customizing the JNDI environment if necessary, for example specifying appropriate JNDI environment properties.

Dynamic queues and topics get cached by destination name. As a consequence, you need to use unique destination names across both queues and topics. Caching can be turned off through the "cache" flag.

Note that the fallback to resolution of dynamic destinations is turned off by default. Switch the "fallbackToDynamicDestination" flag on to enable this functionality.

Authors
Mark Pollack, Juergen Hoeller
Since
1.1
See Also
setJndiTemplate, setJndiEnvironment, setCache, setFallbackToDynamicDestination

Field Summary

Modifier and TypeField and Description
private boolean
private final Map<String, Destination>
private DestinationResolver
private boolean
Inherited from org.springframework.jndi.JndiLocatorSupport:
CONTAINER_PREFIX

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
removeFromCache(String
the name of the destination
destinationName
)

Implements org.springframework.jms.support.destination.CachingDestinationResolver.removeFromCache.

Remove the destination with the given name from the cache (if cached by this resolver in the first place).

public Destination
resolveDestinationName(Session
the current JMS Session (may be null if the resolver implementation is able to work without it)
session
,
String
the name of the destination
destinationName
,
boolean
true if the domain is pub-sub, false if P2P
pubSubDomain
)

Implements org.springframework.jms.support.destination.DestinationResolver.resolveDestinationName.

Resolve the given destination name, either as located resource or as dynamic destination.

public void
setCache(boolean cache)

Set whether to cache resolved destinations.

public void
setDynamicDestinationResolver(DestinationResolver dynamicDestinationResolver)

Set the DestinationResolver to use when falling back to dynamic destinations.

public void
setFallbackToDynamicDestination(boolean fallbackToDynamicDestination)

Set whether this resolver is supposed to create dynamic destinations if the destination name is not found in JNDI.

protected void
validateDestination(Destination
the Destination object to validate
destination
,
String
the name of the destination
destinationName
,
boolean
true if a Topic is expected, false in case of a Queue
pubSubDomain
)

Validate the given Destination object, checking whether it matches the expected type.

Inherited from org.springframework.jndi.JndiLocatorSupport:
convertJndiNameisResourceReflookuplookupsetResourceRef

Field Detail

cacheback to summary
private boolean cache
destinationCacheback to summary
private final Map<String, Destination> destinationCache
dynamicDestinationResolverback to summary
private DestinationResolver dynamicDestinationResolver
fallbackToDynamicDestinationback to summary
private boolean fallbackToDynamicDestination

Constructor Detail

JndiDestinationResolverback to summary
public JndiDestinationResolver()

Method Detail

clearCacheback to summary
public void clearCache()

Implements org.springframework.jms.support.destination.CachingDestinationResolver.clearCache.

Doc from org.springframework.jms.support.destination.CachingDestinationResolver.clearCache.

Clear the entire destination cache.

To be called in case of general JMS provider failure.

Annotations
@Override
removeFromCacheback to summary
public void removeFromCache(String destinationName)

Implements org.springframework.jms.support.destination.CachingDestinationResolver.removeFromCache.

Doc from org.springframework.jms.support.destination.CachingDestinationResolver.removeFromCache.

Remove the destination with the given name from the cache (if cached by this resolver in the first place).

To be called if access to the specified destination failed, assuming that the JMS Destination object might have become invalid.

Parameters
destinationName:String

the name of the destination

Annotations
@Override
resolveDestinationNameback to summary
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException

Implements org.springframework.jms.support.destination.DestinationResolver.resolveDestinationName.

Doc from org.springframework.jms.support.destination.DestinationResolver.resolveDestinationName.

Resolve the given destination name, either as located resource or as dynamic destination.

Parameters
session:Session

the current JMS Session (may be null if the resolver implementation is able to work without it)

destinationName:String

the name of the destination

pubSubDomain:boolean

true if the domain is pub-sub, false if P2P

Returns:Destination

the JMS destination (either a topic or a queue)

Annotations
@Override
Exceptions
JMSException:
if the JMS Session failed to resolve the destination
setCacheback to summary
public void setCache(boolean cache)

Set whether to cache resolved destinations. Default is "true".

This flag can be turned off to re-lookup a destination for each operation, which allows for hot restarting of destinations. This is mainly useful during development.

Note that dynamic queues and topics get cached by destination name. As a consequence, you need to use unique destination names across both queues and topics.

setDynamicDestinationResolverback to summary
public void setDynamicDestinationResolver(DestinationResolver dynamicDestinationResolver)

Set the DestinationResolver to use when falling back to dynamic destinations.

The default is Spring's standard DynamicDestinationResolver.

See Also
setFallbackToDynamicDestination, DynamicDestinationResolver
setFallbackToDynamicDestinationback to summary
public void setFallbackToDynamicDestination(boolean fallbackToDynamicDestination)

Set whether this resolver is supposed to create dynamic destinations if the destination name is not found in JNDI. Default is "false".

Turn this flag on to enable transparent fallback to dynamic destinations.

See Also
setDynamicDestinationResolver
validateDestinationback to summary
protected void validateDestination(Destination destination, String destinationName, boolean pubSubDomain)

Validate the given Destination object, checking whether it matches the expected type.

Parameters
destination:Destination

the Destination object to validate

destinationName:String

the name of the destination

pubSubDomain:boolean

true if a Topic is expected, false in case of a Queue