2016-03-01 25 views
0

我有一個在線遊戲,其中包含一個表示用戶狀態的actor。通過遞歸調用become狀態更新:如何從postStop訪問狀態範圍到當前行爲

private PartialFunction<Object, BoxedUnit> updatedUser(final User user) { 
    return ReceiveBuilder. 
     ... 
     matchEquals("update", s -> { 
      context().become(updatedUser(new User(...))); 
     }).build(); 
} 

現在,當用戶離開遊戲(演員停止),我需要將其狀態保存到數據庫中。我認爲這個理想的地方是從postStop發送消息。但是用戶的狀態超出了範圍。

public void postStop() throws Exception { 
    //user state out of scope 
    Database.tell(user, self()); 

} 

我不想有作爲演員領域的國家。解決這個問題最好的辦法是什麼?

回答

1

沒有辦法訪問updatedUser函數以外的值user

只要讓你的用戶說明actor的實例變量。