2016-07-14 13 views
0

有沒有辦法找到與給定userId關聯的ServerSession的列表?Cometd Seti-有沒有辦法找到與給定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上發佈以通知其他彗星。

詳細Explanation-

我已經實現的cometd奧爾特集羣數據庫更改通知推送到瀏覽器。

兩個節點被認爲是主/從。主節點只接收來自數據庫的通知。

用戶通過從節點連接。 當用戶首先與從節點握手時,seti發佈添加的事件用戶存在。

集羣中的兩個節點都知道雲中的用戶。 當用戶刷新瀏覽器時,發起新的(第二次)握手。 userId(loginUserId)保持不變。 Seti不會將其發佈到設計正確的羣集。

經過一段時間後,通過第一次握手的會話由於不活動而被刪除。存在移除事件由seti發起,這也是設計所期望的。

從節點只知道用戶通過第二次握手連接,但主節點不知道用戶在雲中。

當新事件從數據庫到達時,主節點不會在雲中看到用戶,因此沒有事件傳輸到瀏覽器。而且,主節點和從節點在此時連接。連接到羣集的用戶在兩個節點之間不同步。

我想seti/disassociate,然後seti /關聯會話爲同一個用戶。

我們可以得到會話列表connected-

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


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

通過客戶端1d,服務器會話可以檢索並解離可爲用戶來完成。

seti.disassociate(loginUserId, serverSession); 

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

目前尚不清楚問題是什麼。如果用戶已經關聯,則Seti不會發布以通知其他節點,這是有目的的。其他節點已經知道,所以不需要再告訴他們。 – sbordet

+0

我同意它的設計。如果給你一個userId,你如何計算出與之相關的本地會話列表(客戶端ID)。我想知道客戶端ID。 – user2263197

+0

爲什麼你需要知道'clientId'?你不解釋,如果你解釋*的問題*會更容易幫助你。詢問如何獲取'clientId'是解決您的問題的方法之一,但它可能是錯誤的。首先解釋*問題*。 – sbordet

回答

0

如果您連接到從屬節點兩會,其中之一消失,然後塞提將廣播存在刪除的事件,因爲這是隻發射時所有關聯的上一個userId節點消失了。

這完全是爲了避免一個節點仍然存在關聯,但是其他節點認爲用戶已經離開了雲。

如果您有證據表明發生了這種情況,那麼這是一個錯誤,但是這個特定的行爲已經在CometD測試套件中進行了測試。

相關問題