ESFramework 4.0 (11)-friends and Groups

Source: Internet
Author: User

In most distributed communication systems, client-to-client communication and client grouping are involved, or similar requirements. ESFramework provides powerful support for this common task, including the cluster from the client to the server, to the Platform. During the design, we considered how to provide maximum support for common friend communication and group broadcast communication, so that ESFramework users can easily use these features.

In ESFramework, friends and group members are not only users (persons), but all running client instances. As long as the two client instances need to communicate with each other frequently, they can establish a friend relationship (friend ). If broadcast communication is required between some specific client instances, these instances can be divided into the same group and become groupmate ). If ESFramework is used to develop IM systems, the relationship between these two systems is more obvious. They are similar to QQ's friends and groups.

 

1. Non-mandatory dependency

ESFramework provides interfaces for friend management and group management (IFriendsManager and IGroupManager). If your application requires friends and group functions, you only need to implement these two interfaces, and injected into the ESFramework framework, you can have the powerful functions of ESFramework's built-in friends and groups. However, if your application only communicates with the server on the client and does not require the friend and group functions, you can directly use EmptyFriendsManager and EmptyGroupManager In the null object Mode built in the framework as placeholder objects.

ESFramework does not require your application to implement an interface (such as IFriendsManager and IGroupManager) That is irrelevant to your project requirements ). We have handed over the right of choice to you. You can decide which interfaces to implement based on the specific needs of the project and inject them into the ESFramework framework. You can even implement IFriendsManager and EmptyGroupManager. Alternatively, you can only implement IGroupManager and EmptyFriendsManager. How to do it depends entirely on your project requirements.

 

Ii. Friend Management

ESFramework provides the simplest friend management interface ESPlus. Core. Server. IFriendsManager. Its definition is as follows:

Public interface IFriendsManager
{
/// <Summary>
/// Obtain the friend list. /// </Summary>
List <string> GetFriendList (string ownerID );
}

This method is used to obtain the list of userids of all friends of a user. Like the design rules of many common return sets, this method does not allow null to be returned. If the target user does not have any friends, return a List with 0 elements. Next, we will see that with the IFriendsManager interface, the framework can provide friends-related functions or features.

(1) When a user goes online/offline, the user is notified to his/her friends. When a user goes online or offline, the Framework calls back the OnFriendConnected method or OnFriendOffline method of the ESPlus. Application. Basic. Passive. IBasicBusinessHandler interface to notify all online friends.

(2) The client can obtain the list of all friends and all online friends through the GetFriends method and GetAllOnlineFriends method of the ESPlus. Application. Basic. Passive. IBasicOutter interface.

With the support of these two sets of features, each running client instance can clearly know the online status of each friend throughout its life cycle. In a specific project, we can do this. After a client successfully logs in, it obtains the list of all friends and all online friends. Then, during the running process, when an IBasicBusinessHandler callback notification is received, the status of the corresponding friend is modified. This ensures that our client can know whether every friend is online in real time.

ESFramework has two built-in implementations of the IFriendsManager interface. One is the placeholder EmptyFriendsManager mentioned above, and the other is DefaultFriendsManager.

(1) EmptyFriendsManager assumes that all users are not friends-that is, the GetFriendList method always returns a list with 0 elements.

(2) DefaultFriendsManager assumes that all online users are friends, that is, the GetFriendList method always returns the list of all online users (excluding their ownerID ).

 

Iii. Group Management

Group Management is a little more complex than friend management because a user can join multiple groups and members in different groups can be repeated. ESFramework has a built-in simple group management interface ESPlus. Core. Server. IGroupManager, which is defined as follows:

Public interface IGroupManager
{
/// <Summary>
/// Obtain the list of all members of a group. /// </Summary>
/// <Param name = "groupID"> target group ID </param>
/// <Returns> List of userids of group members </returns>
List <string> GetMemberList (string groupID );

/// <Summary>
/// Obtain the group friends list of the target user (that is, the Union of all group members of the target user ). /// </Summary>
/// <Param name = "userID"> Target User ID </param>
/// <Returns> List of userids of group friends. Note: The list should not contain the target user. </Returns>
List <string> GetGroupmateList (string userID );

/// <Summary>
/// Obtain the ID set of all groups to which the target user joins. /// </Summary>
/// <Param name = "userID"> UserID of the target user </param>
/// <Returns> contains the list of IDs of all groups of userID users </returns>
List <string> GetOwnerGroupIDList (string userID );
}

(1) All three methods return a List, so follow the same method design rule: if there is no result that meets the conditions, return a List with 0 elements.

(2) GetMemberList is used to obtain the list of all members of a group. For example, when implementing this interface, we can load the target group and group members from the DB, and then return to the member list.

(3) groupmate, that is, the relationship between the members of the same group. Since a user can join multiple groups, all group friends are the union of all members of these groups. Note: The list returned by the GetGroupmateList method cannot contain duplicate userids.

(4) a user can belong to multiple groups. The GetOwnerGroupIDList method is used to obtain the GroupID list of all groups a user joins.

Next, we will see what group-related functions or features the framework can provide with the IGroupManager interface.

(1) When a user goes online or offline, all group friends are notified. When a user goes online or offline, the Framework calls back the OnGroupmateConnected method or OnGroupmateOffline method of the ESPlus. Application. Basic. Passive. IBasicBusinessHandler interface to notify all online group friends.

(2) The client can use the GetAllOnlineGroupmates method of the ESPlus. Application. Basic. Passive. IBasicOutter interface to obtain a list of all online group friends.

(3) When we send group broadcast messages (such as ESPlus. application. customizeInfo. passive. ICustomizeInfoOutter interface's BroadcastInGroup method). The framework uses the GetMemberList method of the IGroupManager interface to know which users to broadcast messages.

Like IFriendsManager, each running client instance is supported by the (1) and (2) features, you can clearly know the online status of each group of friends.

ESFramework has a built-in implementation of the IGroupManager interface, that is, the placeholder EmptyGroupManager mentioned above. All three methods of the interface are implemented to return a list of zero elements.

 

Iv. Integration with ESPlatform

The main purpose of ESPlatform is to support massive concurrency through the application server cluster. When an ESFramework-based communication system is migrated to ESPlatform, features related to friends and groups can still be used normally. The server and client programs do not need to be modified. You only need to modify the local IFriendsManager reference and IGroupManager reference originally configured on the server to the global Remoting reference of the platform layer in ESPlatform, for more information, see ESFramework 4.0 advanced (09) -- three cluster models supported by ESPlatform.

 

5.Please note the performance

If you need to frequently use features such as friends and groups in a specific project, pay special attention to performance issues when implementing the IFriendsManager interface and IGroupManager interface. Because the IFriendsManager interface and IGroupManager interface are frequently called by the framework, you must find a way to improve the performance of the IFriendsManager and IGroupManager interfaces.

If the methods of the IFriendsManager and IGroupManager interfaces are called, you must reload the relationship between friends and groups from external media (such as databases and files) each time, then it will undoubtedly seriously reduce the performance of the application. The common solution is to use the cache to avoid repeated reading. When the relationship between friends and groups does not change, the corresponding list is directly returned from the memory.

To determine which policies are used to improve the performance of IFriendsManager and IGroupManager, you need to make proper design based on the specific circumstances of your project. This is especially important in High-Performance Distributed communication systems.

 

ESFramework 4.0 Overview

What are the advantages of ESFramework 4.0?

ESFramework 4.0 upgrade description (continuous update)

All articles in ESFramework 4.0 Quick Start

All articles in ESFramework 4.0 advanced edition Series

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.