代码拉取完成,页面将自动刷新
同步操作将从 huifer/Code-Analysis 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
org.springframework.messaging.simp.SimpSessionScope
SimpSessionScope
没有成员变量
其操作对象是通过 SimpAttributesContextHolder
获取的得到的SimpAttributes
这里简单描述一下 SimpAttributesContextHolder
和 SimpAttributes
SimpAttributesContextHolder
中存放了一个 ThreadLocal
存储SimpAttributes
SimpAttributes
使用到的字段如下
在了解上述内容后进行方法分析
SimpAttributesContextHolder
虎丘属性表
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
// 获取当前的属性
SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
// 从属性表中获取对象
Object scopedObject = simpAttributes.getAttribute(name);
if (scopedObject != null) {
return scopedObject;
}
// 处理线程问题
synchronized (simpAttributes.getSessionMutex()) {
// 从属性表中获取对象
scopedObject = simpAttributes.getAttribute(name);
if (scopedObject == null) {
// 通过 object factory 创建
scopedObject = objectFactory.getObject();
// 设置属性
simpAttributes.setAttribute(name, scopedObject);
}
return scopedObject;
}
}
对点给钱的 SimpAttributes
删除name对应的实体 和 摧毁时调用的回调方法
@Override
@Nullable
public Object remove(String name) {
SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
synchronized (simpAttributes.getSessionMutex()) {
Object value = simpAttributes.getAttribute(name);
if (value != null) {
simpAttributes.removeAttribute(name);
return value;
}
else {
return null;
}
}
}
调用SimpAttributes
进行注册
key: SimpAttributes.class.getName() + ".DESTRUCTION_CALLBACK."
+ name
value : Runnable
@Override
public void registerDestructionCallback(String name, Runnable callback) {
SimpAttributesContextHolder.currentAttributes().registerDestructionCallback(name, callback);
}
// org.springframework.messaging.simp.SimpAttributes#registerDestructionCallback
public void registerDestructionCallback(String name, Runnable callback) {
synchronized (getSessionMutex()) {
if (isSessionCompleted()) {
throw new IllegalStateException("Session id=" + getSessionId() + " already completed");
}
this.attributes.put(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback);
}
}
SimpAttributes
的SessionId
@Override
public String getConversationId() {
return SimpAttributesContextHolder.currentAttributes().getSessionId();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。