2.4.1 View
-
GlobalView
chatroom.view.xml:
<bean name="ViewChatRoomInfo"> <variable name="name" type="string" /> <variable name="roomid" type="long" /> </bean> <bean name="RoomChatHallInfo"> <variable name="name" type="string" /> <variable name="hallid" type="long" /> <variable name="rooms" type="vector" value="ViewChatRoomInfo" /> </bean> <view name="CommonInfo" lifecycle="global"> <variable name="halls" type="vector" value="RoomChatHallInfo" /> </view>
This GlobalView has only one field halls, which is the RoomChatHallInfo array and provides the complete chat hall and the information of the room.
SessionManager.java:
static void setViewHallsFromCache() { final ArrayList<RoomChatHallInfo> halls = new ArrayList<>(); .................... CommonInfo.getInstance().setHalls(halls); lastSetHallsTimeStamp = System.currentTimeMillis(); }
The setViewHallsFromCache constructs the halls array according to the database configuration information and sets to the CommonInfo. This method is called after adjusting the configuration of the hall during the running. This method is called after the system initiates of the configuration of the hall or room is changed.
UserInfo.java:
void checkUpdateHallInfos() { if (updateroominfotime < SessionManager.lastSetHallsTimeStamp) { updateroominfotime = System.currentTimeMillis(); CommonInfo.getInstance().syncToClient(getSessionId()); } }
This method detected whether the hall information obtained by the client is the latest one for the current user. If not, the latest version is updated to the client.
Searching the reference of the checkUpdateHallInfos, you could find there are 3 calling.
UserInfo.java:
private UserInfo(SessionView.CreateParameter param) { .............. checkUpdateHallInfos(); }
This method is called when creating SessionView after the user successful login to initiate the hall information for the client, which is necessary.
UserInfo.java:
protected void onMessage(String message, long sessionid) { final int index = message.indexOf('='); if (-1 == index) return; checkUpdateHallInfos(); ................... }
When receiving the user Message, the frequency of user command is low. So it is insignificant to do a detection.
ChatRoom.java:
protected void onDetached(long sessionid, byte reason) { RoomInfo.increment_memberCount_mapkey(roomid, -1L); UserInfo info = UserInfo.getInstance(sessionid); if (info != null) info.checkUpdateHallInfos(); }
The user leaves the chatroom and re-enters the hall. If the hall information changes at this time, it is necessary to refresh.
The GlobalView provides the support for the global configuration information, and these information does not need to be refreshed immediately when they are changed and could be manually refreshed in the specific time according to the requirement.