Up

# NSDistributedNotificationCenter class reference

### Authors

Richard Frith-Macdonald (`richard@brainstorm.co.uk`)

Version: 37003

Date: 2013-08-22 16:44:54 +0100 (Thu, 22 Aug 2013)

Copyright: (C) 1998-2009 Free Software Foundation, Inc.

# Software documentation for the NSDistributedNotificationCenter class

## NSDistributedNotificationCenter : NSNotificationCenter

> Declared in:
>   Foundation/NSDistributedNotificationCenter.h

Availability: MacOS-X 10.0.0

The `NSDistributedNotificationCenter` provides a versatile yet simple mechanism for objects in different processes to communicate effectively while knowing very little about each others' internals.
A distributed notification center acts much like a normal notification center, but it handles notifications on a machine-wide (or local network wide) basis rather than just notifications within a single process. Objects are able to register themselves as observers for particular notification names and objects, and they will then receive notifications (including optional user information consisting of a dictionary of property-list objects) as they are posted.

Since posting of distributed notifications involves inter-process (and sometimes inter-host) communication, it is fundamentally slower than normal notifications, and should be used relatively sparingly. In order to help with this, the `NSDistributedNotificationCenter` provides a notion of 'suspension', whereby a center can be suspended causing notifications for observers in the process where the center was suspended to cease receiving notifications. Observers can specify how notifications are to be handled in this case (queued or discarded) and posters can specify that particular notifications are to be delivered immediately irrespective of suspension.

Distributed notifications are mediated by a server process which handles all notifications for a particular center type. In GNUstep this process is the `gdnc` tool, and when started without special options, a gdnc process acts as the local centre for the host it is running on. When started with the `GSNetwork` user default set to `YES`, the `gdnc` tool acts as a local network wide server (you should only run one copy of `gdnc` like this on your LAN).
The `gdnc` process should be started at machine boot time, but GNUstep will attempt to start it automatically if it can't find it.

MacOS-X currently defines only a notification center for the local host. GNUstep also defines a local network center which can be used from multiple hosts. By default the system sends this to any gdnc process it can find which is configured as a network-wide server, but the `GDNCHost` user default may be used to specify a particular host to be contacted... this may be of use where you wish to have logically separate clusters of machines on a shared LAN.

Instance Variables
Method summary

- +defaultCenter
- +notificationCenterForType:
- -addObserver:selector:name:object:
- -addObserver:selector:name:object:suspensionBehavior:
- -postNotification:
- -postNotificationName:object:
- -postNotificationName:object:userInfo:
- -postNotificationName:object:userInfo:deliverImmediately:
- -removeObserver:name:object:
- -setSuspended:
- -suspended

### defaultCenter

+ (id) defaultCenter;
Availability: MacOS-X 10.0.0
Returns the default notification center... a shared notification center for the local host. This is simply a convenience method equivalent to calling +notificationCenterForType: with `NSLocalNotificationCenterType` as its argument.

### notificationCenterForType:

+ (NSDistributedNotificationCenter*) notificationCenterForType: (NSString*)type;
Availability: MacOS-X 10.0.0
Returns a notification center of the specified type.
The `NSLocalNotificationCenterType` provides a shared access to a notification center used by processes on the local host which belong to the current user.
The `GSPublicNotificationCenterType` provides a shared access to a notification center used by processes on the local host belonging to any user.
The `GSNetworkNotificationCenterType` provides a shared access to a notification center used by processes on the local network.
MacOS-X supports only `NSLocalNotificationCenterType`.

### addObserver: selector: name: object:

- (void) addObserver: (id)anObserver selector: (SEL)aSelector name: (NSString*)notificationName object: (NSString*)anObject;
Availability: MacOS-X 10.0.0
Adds an observer to the receiver. Calls -addObserver:selector:name:object:suspensionBehavior: with `NSNotificationSuspensionBehaviorCoalesce`.

### addObserver: selector: name: object: suspensionBehavior:

- (void) addObserver: (id)anObserver selector: (SEL)aSelector name: (NSString*)notificationName object: (NSString*)anObject suspensionBehavior: (NSNotificationSuspensionBehavior)suspensionBehavior;
Availability: MacOS-X 10.0.0
Adds an observer to the receiver.
When a notification matching notificationName and anObject is sent to the center, the object anObserver is sent the message aSelector with the notification info dictionary as its argument.
The suspensionBehavior governs how the center deals with notifications when the process to which the notification should be delivered is suspended:

`NSNotificationSuspensionBehaviorDrop`
  Discards the notification if the observing process is suspended.
`NSNotificationSuspensionBehaviorCoalesce`
  Discards previously queued notifications when the observing process is suspended, leaving only the last notification posted in the queue. Delivers this single notification when the process becomes unsuspended.
`NSNotificationSuspensionBehaviorHold`
  Queues notifications when the observing process is suspended, delivering all the queued notifications when the process becomes unsuspended again.
`NSNotificationSuspensionBehaviorDeliverImmediately`
  Deliver the notification immediately, even if the destination process is suspended.

### postNotification:

- (void) postNotification: (NSNotification*)notification;
Availability: MacOS-X 10.0.0
Posts the notification to the center using postNotificationName:object:userInfo:deliverImmediately: with the delivery flag set to `NO`.

### postNotificationName: object:

- (void) postNotificationName: (NSString*)notificationName object: (NSString*)anObject;
Availability: MacOS-X 10.0.0
Posts the notificationName and anObject to the center using postNotificationName:object:userInfo:deliverImmediately: with the user info set to `nil` and the delivery flag set to `NO`.

### postNotificationName: object: userInfo:

- (void) postNotificationName: (NSString*)notificationName object: (NSString*)anObject userInfo: (NSDictionary*)userInfo;
Availability: MacOS-X 10.0.0
Posts the notificationName, anObject and userInfo to the center using postNotificationName:object:userInfo:deliverImmediately: with the delivery flag set to `NO`.

### postNotificationName: object: userInfo: deliverImmediately:

- (void) postNotificationName: (NSString*)notificationName object: (NSString*)anObject userInfo: (NSDictionary*)userInfo deliverImmediately: (BOOL)deliverImmediately;
Availability: MacOS-X 10.0.0
The primitive notification posting method...
The userInfo dictionary may contain only property-list objects.
The deliverImmediately flag specifies whether the suspension state of the receiving process is to be ignored.

### removeObserver: name: object:

- (void) removeObserver: (id)anObserver name: (NSString*)notificationName object: (NSString*)anObject;
Availability: MacOS-X 10.0.0
Removes the observer from the center.

### setSuspended:

- (void) setSuspended: (BOOL)flag;
Availability: MacOS-X 10.0.0
Sets the suspension state of the receiver... if the receiver is suspended, it won't handle notification until it is unsuspended again, unless the notifications are posted to be delivered immediately.

### suspended

- (BOOL) suspended;
Availability: MacOS-X 10.0.0
Returns the current suspension state of the receiver.

## Instance Variables for NSDistributedNotificationCenter Class

### _centerLock

@protected NSRecursiveLock* _centerLock;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

### _remote

@protected id _remote;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

### _suspended

@protected BOOL _suspended;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

### _type

@protected NSString* _type;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

Up