FileDocCategorySizeDatePackage
PresencePollingManager.javaAPI DocAndroid 1.5 API3596Wed May 06 22:42:46 BST 2009com.android.im.imps

PresencePollingManager

public class PresencePollingManager extends Object implements Runnable
Manage presence polling from the server. If the server does not support subscribing presence change or prefer the client polling presence, the client should send GetPresence-Request periodically.

Fields Summary
private boolean
mStopped
private boolean
mFinished
private long
mPollingInterval
private Object
mLock
private ImpsAddress[]
mPollingAddress
private ImpsAddress[]
mContactLists
private ImpsContactListManager
mManager
private Thread
mPollingThread
Constructors Summary
public PresencePollingManager(ImpsContactListManager manager, long pollingIntervalMillis)


      
              
        mManager = manager;
        mPollingInterval = pollingIntervalMillis;
        mStopped = true;
        mFinished = false;
    
Methods Summary
private voiddoStartPolling()

        mStopped = false;
        if (mPollingThread == null) {
            mPollingThread = new Thread(this, "PollingThread");
            mPollingThread.setDaemon(true);
            mPollingThread.start();
        } else {
            synchronized (mLock) {
                mLock.notify();
            }
        }
    
private ImpsAddress[]getContactLists()

        if (mContactLists == null) {
            mContactLists = mManager.getAllListAddress();
        }
        return mContactLists;
    
public voidresetPollingContacts()

        synchronized (mLock) {
            mContactLists = null;
        }
    
public voidrun()

        while (!mFinished) {
            synchronized (mLock) {
                if (!mStopped) {
                    ImpsAddress[] pollingAddress = mPollingAddress;
                    if (pollingAddress == null) {
                        // Didn't specify of which contacts the presence will
                        // poll. Fetch the presence of all contacts in list.
                        pollingAddress = getContactLists();
                    }
                    mManager.fetchPresence(pollingAddress);
                }

                try {
                    mLock.wait(mPollingInterval);
                } catch (InterruptedException e) {
                    // ignore
                }
            }
        }
    
public voidshutdownPolling()

        mFinished = true;
        synchronized (mLock) {
            mLock.notify();
        }
    
public voidstartPolling()

        synchronized (mLock) {
            // Clear the polling address; the polling thread will fetch the
            // presence of all the contacts in lists.
            mPollingAddress = null;
        }
        doStartPolling();
    
public voidstartPolling(ImpsUserAddress user)

        synchronized (mLock) {
            mPollingAddress = new ImpsAddress[] { user };
        }
        doStartPolling();
    
public voidstopPolling()

        mStopped = true;