Mailbox client superclass
Mailbox clients for communicating with our own mailbox and contacts' mailboxes are managed by a singleton mailbox client manager (#2228 (closed)).
We'll need different client implementations for our own mailbox (#2290 (closed)) and contacts' mailboxes (#2289 (closed)), but there will be a shared interface and some shared code. This ticket covers the code shared between the client for our own mailbox and the client for a contact's mailbox.
Interface:
- The manager can create and destroy clients
- The manager can assign/deassign contacts for upload or download
- The client's upload and download workers can request connectivity checks
Implementation:
- At any given time the client may have multiple upload workers and/or a single download worker
- The client has a connectivity check method, which takes an observer as an argument
- The client stores the time of the latest successful connectivity check, a reference to the current connectivity check task, if any, and a list of observers waiting for the result of a connectivity check
When the client is destroyed:
- If a connectivity check task is running:
- Cancel the connectivity check task
- Destroy the upload workers, if any
- Destroy the download worker, if any
When the connectivity check method is called:
- Compare the current time to the time of the latest successful connectivity check
- If a connectivity check has recently succeeded:
- Notify the observer
- Else if a connectivity check task is running:
- Add the observer to the list of waiting observers
- Else:
- Add the observer to the list of waiting observers
- Start a connectivity check task
When a connectivity check task succeeds:
- Update the time of the latest successful connectivity check
- Notify any waiting observers
- Clear the list of waiting observers
Edited by akwizgran