BlackBerry Spark Communications Services for iOS  1.11.0
BBMConnection Class Reference
Inheritance diagram for BBMConnection:

Class Methods

(NSLock *) + readWriteLock


id< BBMModelProtocolmodel

Detailed Description

BBMConnection is the abstract interface for the connection the BBMDSModel uses to communicate with the underlying API.

Requests with a JSON payload are queued and dispatched with a NSOperationQueue Received JSON is dispatched to all added consumers.

Incoming JSON messages are queued in a serial dispatch queue. readWriteLock is acquired prior to all write operations which are dispatched synchronously to the main thread. Any read operations on the data model occurring off the main thread should acquire this lock to ensure the model is not updated during the read.


Method Documentation

◆ readWriteLock()

+ (NSLock *) readWriteLock

You must acquire this lock before reading any observable properties off the main thread inside an ObservableMonitor block. All BBM model object properties are observable.

Do not hold this lock for long periods of time as it will block updates to the data model.

All write operations from incoming JSON acquire this lock prior to dispatch to the main thread. Write operations are blocked in a dispatch queue until this lock becomes available to ensure all background read operations can complete before the data model is updated.

Read operations on BBMDS model properties are not thread safe unless this lock is acquired.
self.identifierMonitor = [ObservableMonitor monitorActivatedWithName:@"identifierMonitor" block:^{
//Do some things on the main thread
dispatch_async(dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//acquire lock
[[myConsumer readWriteLock] lock];
//It is now safe to read observable properties. We are guaranteed that the data model
//will not change while we hold this lock
id theVar =
//Release the lock as soon as we are done reading
[[myConsumer readWriteLock] unlock];
//Do some things with theVar
NSLock Locked when a write operation is taking place to the data model.

Property Documentation

◆ model

- (id<BBMModelProtocol>) model

Returns the data model associated with this connection.

To get the root node of the default data model, use [[BBMEnterpriseService shared] model]
The data model associated with this connection