PATH  Documentation > Mac OS X > Foundation Reference: Java



Table of Contents

NSPort


Inherits from:
NSObject
Package:
com.apple.yellow.foundation


Class Description


An NSPort represents a communication channel to or from another NSPort, which typically resides in a different thread or task.


Note: An NSPort is essentially the object form of a Mach port. To use NSPorts effectively you should be familiar with Mach ports, port access rights, and Mach messages. See the Mach OS documentation for more information.NSPort is intended to receive incoming messages that need to be added to an NSRunLoop. See the NSRunLoop class specification for more information.




Method Types


Constructors
NSPort
Validation
invalidate
isValid
Setting the delegate
setDelegate
delegate


Constructors



NSPort

public NSPort()

Creates a new NSPort object capable of both sending and receiving messages.

public NSPort(int machPort)

Creates a newly allocated NSPort object to use the Mach port machPort. Depending on the access rights for machPort, the new NSPort may only be able to send messages.


Instance Methods



delegate

public Object delegate()

Returns the NSPort's delegate.

See Also: setDelegate



invalidate

public void invalidate()

Marks the NSPort as invalid and posts a PortDidBecomeInvalidNotification to the default notification center.

See Also: isValid



isValid

public boolean isValid()

Returns false if the NSPort is known to be invalid, true otherwise (an NSPort only notes that it has become invalid when it tries to send or receive a message). An NSPort becomes invalid when its underlying communication resource, which is operating-system dependent, is closed or damaged.

See Also: invalidate



setDelegate

public void setDelegate(Object anObject)

Sets the NSPort's delegate to anObject.

See Also: delegate




Notifications


PortDidBecomeInvalidNotification

Posted from the invalidate method, which is invoked when the NSPort is deallocated or when it notices that its communication channel has been damaged. This notification contains a notification object but no userInfo dictionary. The notification object is the NSPort object that has become invalid.

The NSPort object posting this notification is no longer useful, so all receivers should unregister themselves for any notifications involving the NSPort. A method receiving this notification should check to see which port became invalid before attempting to do anything. In particular, observers that receive all PortDidBecomeInvalidNotification's should be aware that communication with the window server is handled through an NSPort. If this port becomes invalid, drawing operations will cause a fatal error.



Table of Contents