Spring JMS (1)

1. DestinationResolver
将给定的目的地地址解析为目的地实例。
Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
			throws JMSException;

pubSubDomain--true表示发布/订阅模式,解析后的地址为Topic,false表示为点对点模式,解析后的地址为Queue。
看一下DestinationResolver的层次结构图
Spring JMS (1)

1.1 DynamicDestinationResolver
  DynamicDestinationResolver实现了DestinationResolver接口,并根据pubSubDomain的值,动态的创建目的地实例。
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
			throws JMSException {

		Assert.notNull(session, "Session must not be null");
		Assert.notNull(destinationName, "Destination name must not be null");
		if (pubSubDomain) { //
			return resolveTopic(session, destinationName);
		}
		else {
			return resolveQueue(session, destinationName);
		}
	}

它是通过resolveTopic和resolveQueue创建目的地实例的:
protected Topic resolveTopic(Session session, String topicName) throws JMSException {
		if (session instanceof TopicSession) {
			// Cast to TopicSession: will work on both JMS 1.1 and 1.0.2
			return ((TopicSession) session).createTopic(topicName);
		}
		else {
			// Fall back to generic JMS Session: will only work on JMS 1.1
			return session.createTopic(topicName);
		}
	}

protected Queue resolveQueue(Session session, String queueName) throws JMSException {
		if (session instanceof QueueSession) {
			// Cast to QueueSession: will work on both JMS 1.1 and 1.0.2
			return ((QueueSession) session).createQueue(queueName);
		}
		else {
			// Fall back to generic JMS Session: will only work on JMS 1.1
			return session.createQueue(queueName);
		}
	}



1.2 CachingDestinationResolver
CachingDestinationResolver继承了DestinationResolver接口,并添加了缓存的功能。
void removeFromCache(String destinationName);
void clearCache(); //清空所有目的地缓存

当JMS地址失效时,removeFromCache方法被调用。当JMS provider失效时,clearCache方法被调用。

1.3 JndiDestinationResolver
  JndiDestinationResolver实现了CachingDestinationResolver接口,并继承了JndiLocatorSupport抽象类。如果在JMS provider中配置了静态目的地,那么JndiDestinationResolver通过JNDI查找的方式获得目的地实例。JndiDestinationResolver的cache属性用于指定是否对目的地实例进行缓存,默认值是true。JndiDestinationResolver的fallbackToDynamicDestination表示,如果目的地通过JNDI查找失败后,是否使用动态目的地,默认值为false。
private boolean cache = true;
private boolean fallbackToDynamicDestination = false;

JndiLocatorSupport类继承了JndiAccessor,JndiAccessor封装了JndiTemplate(提供了查找和绑定的一些方法)和JndiEnvironment(环境变量属性)

1.4 BeanFactoryDestinationResolver
  BeanFactoryDestinationResolver实现了DestinationResolver和BeanFactoryAware接口。有了BeanFactoryAware接口,我们就可以知道,它是通过给定的目的地名从BeanFactory中查找目的地实例。
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
			throws JMSException {

		Assert.state(this.beanFactory != null, "BeanFactory is required");
		try {
			return (Destination) this.beanFactory.getBean(destinationName, Destination.class);
		}
		catch (BeansException ex) {
			throw new DestinationResolutionException(
					"Failed to look up Destinaton bean with name '" + destinationName + "'", ex);
		}
	}



你可能感兴趣的:(spring,bean,cache,jms,ITeye)