Package kilim.nio

Class EndPoint

java.lang.Object
kilim.nio.EndPoint

public class EndPoint extends Object
The EndPoint represents an open socket connection. It is a wrapper over a non-blocking socket (channel) and belongs to a SessionTask. It serves as the bridge between the SessionTask and the NioSelectorScheduler, using a pair of mailboxes for exchanging socket registration and socket ready events.

The other purpose of this class is to provide convenience methods that read from a socket into a bytebuffer, or write from a bytebuffer to the socket. If the socket is not ready for business, the endpoint (and hence the task) simply yields, without registering with the NioSelectorScheduler. The idea is to give the other runnable tasks a chance to run before retrying the operation (on resumption); this avoids waking up the selector -- an expensive operation -- as much as possible, and introduces a delay between retries. If, after a fixed number of times (YIELD_COUNT), the operation still hasn't succeeded, the endpoint registers itself with the NioSelectorScheduler, and waits for a socket-ready event from the selector. This scheme is adaptive to load, in that the delay between retries is proportional to the number of runnable tasks. Busy sockets tend to get serviced more often as the socket is always ready.