Online list Class 1

Source: Internet
Author: User
We know how to restrict repeated login by users in the background management system. Some people started to say that they set a flag in the database. When the same user logs on, the system prompts that he has already logged on again. However, there is a problem here: if the user suddenly shuts down illegally, other users will never be able to log on. Therefore, we need to consider two situations: when a user has logged on, when other users log on with the same account and password, other users can force the previous user to go offline, this is logical. Since we all know the user name and password, the system cannot determine which login is correct. Therefore, the system has the right to allow users with passwords to log on to the system. The second one should also prevent users from shutting down illegally. Once the user shuts down, we should set a timer. Of course, we will define a reasonable time by ourselves, then let the server trigger this event at the specified time. Constantly judge whether the user in the online user list has reached the specified time and no operation is performed. If yes, clear the user from the online list and ask the user to log on again. I think this design is reasonable. If it is better, I can leave a message.

According to this requirement, we define a system class for user management. It has the user ID, user name, start time, last operation time, last operation URL, user type, online time, and IP address. After the definition, we need to define a set to store the information. The system defines a cache dictionary to store the information. Two dictionaries and a two-way linked list are defined. The first is dictionary <string, inclulistnode <tvalue> _ memberuserlist; used to store all member information. Dictionary <tkey, inclulistnode <tvalue> _ alluserlist; defines all information, including Members and tourists. Sort by defining a two-way linked list <tvalue> _ tvaluelink. Because we need to add, delete, and modify the linked list to continuously maintain the online linked list, a lock must be defined, to limit the read or write operations on the online list at the same time. Therefore, the system defines a protected readerwriterlock _ cachedatarwl = new readerwriterlock (); lock. The next step is to define a time. The system. Time. Timer class I mentioned earlier will be used to trigger events continuously based on the specified time. The event here is to constantly clear expired users. Of course, the functions of this class are not limited. Since expired users can be deleted, of course, they must have the functions of adding new users and updating new users. Therefore, this class contains multiple deletion methods. It can be deleted based on the given key value, that is, the key, or the name attribute. Therefore, names and keys must be unique. However, you must lock the deletion and addition. It is easy to determine whether a user has not been operating for a long time. You only need to judge the last operation time and current time of the user. If the operating system specifies the time, the operation times out. Of course, this also requires users to update the last operation time every time they access a page.

Of course, you can also store user information in tables. In fact, the methods are similar. One is to store user information in the memory, the other is to store user information in the database, and the other is to access the table quickly but occupy the memory, another slow speed means connecting to the database every time, but storing a large amount of data can meet the online needs of a large number of users.

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.