Cometd Seti-有没有办法找到与给定userId关联的ServerSession列表?

时间:2016-07-14 21:34:47

标签: cometd

有没有办法找到与给定userId相关联的ServerSession列表?

public boolean associate(final String userId, final ServerSession session)
    {
        if (session == null)
            throw new NullPointerException();

        LocalLocation location = new LocalLocation(userId, session);
        boolean wasAssociated = isAssociated(userId);
        boolean added = associate(userId, location);

        if (added)
        {
            session.addListener(location);
            if (_logger.isDebugEnabled())
                _logger.debug("Associated session {} to user {}", session, userId);
            if (!wasAssociated)
            {
                if (_logger.isDebugEnabled())
                    _logger.debug("Broadcasting association addition for user {}", userId);
                // Let everyone in the cluster know that this session is here
                _session.getChannel(SETI_ALL_CHANNEL).publish(new SetiPresence(true, userId));
            }
        }

        return added;
    }

如果用户已经关联,则seti不会在SETI_ALL_CHANNEL上发布以通知其他彗星。

详细说明 -

我已经实现了cometd oort集群来将数据库更改通知推送到浏览器。

两个节点被视为主/从。主节点仅接收来自数据库的通知。

用户通过从节点连接。 当用户第一次与从属节点握手时,seti发布添加的事件用户状态。

群集中的两个节点都知道云中的用户。 当用户刷新浏览器时,启动新的(第二次)握手。 userId(loginUserId)保持不变。 Seti不会将其发布到集群中,这是设计正确的。

经过一段时间后,由于不活动而导致第一次握手的会话被删除。 seti会触发已删除状态事件,这也是设计所期望的。

从属节点只知道用户通过第二次握手连接,但是主节点不知道用户在云中存在。

当新事件从数据库到达时,主节点不会在云中看到用户,因此没有事件传输到浏览器。此外,主节点和从节点在此时连接。连接到群集的用户不会在两个节点之间同步。

我正在考虑seti / disassociate,然后seti /关联同一用户的会话。

我们可以获得连接的会话列表 -

seti.getOort().getBayeuxServer().getSessions();


//  clientId - previous client session id need to be identified 
    ServerSession serverSession=seti.getOort().getBayeuxServer().getSession(clientId);

通过客户端ID,可以检索服务器会话,并且可以为用户完成解除关联。

 seti.disassociate(loginUserId, serverSession); 

 boolean association=seti.associate(loginUserId, serverSession);//new  handshake- serverSession

1 个答案:

答案 0 :(得分:0)

如果您有两个会话连接到从属节点,其中一个会消失,那么Seti将广播一个已删除状态的事件,因为只有在{{的所有关联时才会触发该事件节点上的1}}消失了。

这正是为了避免一个节点仍然存在关联,但其他节点认为用户已离开云端。

如果您有证据表明这种情况正在发生,那么它就是一个错误,但这一特定行为在CometD测试套件中进行了测试。

相关问题