zoukankan      html  css  js  c++  java
  • Shiro SessionDAO的设计概念

    SessionDao

    其行为有

    AbstractSessionDAO 

    具备了生成Session的ID的工具SessionIdGenerator,该工具有多种功能(默认是UUID形式的),可以生成UUID形式的,可以是随机数形式的

    公共的方法抽取出来交给AbstractSessionDao来做,如生成Session的ID,如新增、查询、更新、删除Session过程中涉及的行为(四种基础行为抽象)

    public Serializable create(Session session) {
        Serializable sessionId = doCreate(session);
        verifySessionId(sessionId);
        return sessionId;
    }
    
    private void verifySessionId(Serializable sessionId) {
        if (sessionId == null) {
            String msg = "sessionId returned from doCreate implementation is null.  Please verify the implementation.";
            throw new IllegalStateException(msg);
        }
    }
    
    protected abstract Serializable doCreate(Session session);

    MemorySessionDAO具体实现新增行为

    protected Serializable doCreate(Session session) {
        Serializable sessionId = generateSessionId(session);
        assignSessionId(session, sessionId);
        storeSession(sessionId, session);
        return sessionId;
    }

    将Session存储到了内存中

    private ConcurrentMap<Serializable, Session> sessions;
    
    public MemorySessionDAO() {
        this.sessions = new ConcurrentHashMap<Serializable, Session>();
    }
    
    protected Session storeSession(Serializable id, Session session) {
        if (id == null) {
            throw new NullPointerException("id argument cannot be null.");
        }
        return sessions.putIfAbsent(id, session);
    }
  • 相关阅读:
    51nod 1051【基础】
    HDU5971【瞎搞】
    Lightoj1018 【状压DP】
    HDU2604【矩阵快速幂】
    HDU1501【简单DP】
    HDU3555【数位DP】
    Lightoj1037【状压DP】
    51nod 1099【贪心】
    HDU5950【矩阵快速幂】
    51nod 1049【经典】
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/9296258.html
Copyright © 2011-2022 走看看