2021SC@SDUSC
CachingSecurityManager实现了SecurityManager,Destroyable,CacheManagerAware,EventBusAware四个接口
私有变量
CacheManager
private CacheManager cacheManager;
cacheManager主要用于各种缓存操作,可以为null
EventBus
private EventBus eventBus;
EventBus用于发布和接收Shiro生命周期中的事件。
含有方法
CachingSecurityManager
public CachingSecurityManager() {
//use a default event bus:
setEventBus(new DefaultEventBus());
}
构造方法,设置一个EventBus‘
getCacheManager
获得cancheMangager
setCacheManager
public void setCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
afterCacheManagerSet();
}
手动设置cacheManager
afterCacheManagerSet
protected void afterCacheManagerSet() {
applyEventBusToCacheManager();
}
告诉子类cacheManager已经被设置,可以被使用
getEventBus
获得eventBus对象
setEventBus
public void setEventBus(EventBus eventBus) {
this.eventBus = eventBus;
afterEventBusSet();
}
手动设置eventBus对象
applyEventBusToCacheManager
protected void applyEventBusToCacheManager() {
if (this.eventBus != null && this.cacheManager != null && this.cacheManager instanceof EventBusAware) {
((EventBusAware)this.cacheManager).setEventBus(this.eventBus);
}
}
对cacheManager设置eventBus对象
afterEventBusSet
protected void afterEventBusSet() {
applyEventBusToCacheManager();
}
一个模板,告诉子类eventBus已经设置可以被使用
destroy
public void destroy() {
LifecycleUtils.destroy(getCacheManager());
this.cacheManager = null;
LifecycleUtils.destroy(getEventBus());
this.eventBus = new DefaultEventBus();
}
销毁 cacheManager对象并且重新设置eventBus对象