|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Handlet
An inversion-of-control mechanism for implementing a non-blocking network server or client. The methods defined here are designed to be invoked by a server or client container that is aware of the I/O readiness of the underlying channel.
read(ScatteringByteChannel)
, or
write(GatheringByteChannel)
.
init(HandletContext)
. This is the familiar pattern found both in
the servlet and applet architecture. No other method on the handlet
instance will be invoked prior to initialization. I.e. the behavior of
all the other methods is undefined prior to the invocation of
init()
(unless, of course, if defined by the implementation).
On return, the state of the instance will not be IoState.DONE.
read
. The state
of the instance may change on invocation of read.
write
. The state
of the instance may change on invocation of write.
init(HandletContext)
. The context object also provides
an Executor
on which the asynchronous task may be run, however, the
handlet is free to use some other asynchronous mechanism.
IoState
returned on invoking either of the
read
/write
methods will not necessarily be the same as that returned by a
subsequent invocation of the state
method. In particular,
after a
read
/write
method returns IoState.PROCESSING, an immediate
invocation might of state()
might return a different value. The
reason why is that the asynchronous task may have completed even before
the read/write method returns. The return value in the
signature of these two I/O methods provides a way for the container to
reliably detect that a handlet instance went into the PROCESSING
state.
Method Summary | |
---|---|
void |
discard()
Discards the instance. |
IoState |
init(HandletContext context)
Initializes the handlet. |
IoState |
read(ScatteringByteChannel in)
Reads from the specified channel and returns the possibly new state of the instance. |
IoState |
state()
Returns the state of the handlet. |
IoState |
write(GatheringByteChannel out)
Writes to the specified channel and returns the possibly new state of the instance. |
Method Detail |
---|
IoState init(HandletContext context)
context
- the context supplied by the instance's container (e.g.
serverIoState state()
IoState read(ScatteringByteChannel in) throws IOException
state()
may
return a value other than PROCESSING
, if the asynchronous
task completes before the call to state()
.
The implementation must read from the channel in non-blocking manner.
The behavior of this method is undefined if the state of the instance is not IoState.READING.
IOException
IoState write(GatheringByteChannel out) throws IOException
state()
may
return a value other than PROCESSING
, if the asynchronous
task completes before the call to state()
.
The implementation must write to the channel in non-blocking manner.
The behavior of this method is undefined if the state of the instance is not IoState.WRITING.
IOException
void discard()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |