* an instance of <code>ReadTask</code> byte buffer. Once the
* <code>Rule</code> has been successfully applied, execute it.
*/
public void doTask() throws IOException {
try {
ReadTask readTask = (ReadTask)wrappedTask;
ByteBuffer byteBuffer = readTask.getByteBuffer();
SocketChannel socketChannel =
(SocketChannel)readTask.getSelectionKey().channel();
Socket socket = socketChannel.socket();
socketChannel.read(byteBuffer);
int position = byteBuffer.position();
int limit = byteBuffer.limit();
// If we weren't able to parse the token, return to the
// SelectorThread
boolean execute = false;
if (algorithm.parse(byteBuffer)) {
execute = rulesExecutor.execute(this);
if ( execute ){
// Tell the ReadTask to not load bytes and re-use the one
// already loaded.
readTask.setBytesAvailable(true);
byteBuffer.limit(limit);
byteBuffer.position(position);
// Get notification once the task has completed.
readTask.addTaskListener(this);
readTask.execute();
} else {
fireTaskEvent(taskEvent);
}
} else {
// Failed to read the URI. Close the connections.
readTask.terminate(false);
fireTaskEvent(taskEvent);
}
} catch (Exception ex){
SelectorThread.logger()
.log(Level.SEVERE,"IsolatedTask logic exception.",ex);