Conversation this class mainly represents the data structure of the dialogue, which holds a thread all the relevant information, such as Recipients,threadid, also used to manage thread, such as query thread, delete thread, update thread , manage ThreadID, manage thread contacts, and so on. Because the thread table has more information associated with other tables, such as contacts and the number of messages, some of the information is written directly in the database. Because there is more information on thread, it is more time-consuming to load, so there is a cache inside the conversation to improve the speed of loading thread.
The way to get conversation objects is through the conversation static Method Conversation.get (), this method first from the internal cache to fetch conversation objects, if the cache does not build objects, and load the information from the database into the object.
Because a conversation represents a thread, the implementation data structure of the conversation's internal cache is a hashset, in which each element is a conversation object. It provides several ways to manipulate the cache: Get, put, remove, replace, etc. Each conversation object can be added only once, or there will be exception thrown. But this cache implementation is very not efficient, directly with a hashset<conversation>, so in get and replace, very inconvenient. Better implementation should be a hash table, the key is ThreadID, the value is conversation object, so you can take advantage of the high efficiency of the hash to query and replace operations. This cache implementation is very simple, the Converation.init () method calls Cacheallthreads () to do the work of the cache. When MMS is started and thread changes, Conversation.init () is also invoked to update the cache, such as when thread is deleted. Convresation.init () starts a new thread and calls Cacheallthreads () in the thread to build the cache of conversation, and the method to get conversation is like Conversation.get ( Will first try to get the conversation object from its cache, if not in the cache, create a new conversation, and add to the cache. Cacheallthreads () queries all thread from the database, constructs a new conversation object, adds the total information of the database to the conversation object, and puts it into the cache.