1 23 package com.sun.enterprise.web.connector.grizzly; 24 25 import java.io.IOException ; 26 import java.util.logging.Level ; 27 28 35 public class AsyncReadTask extends ReadTask { 36 37 public AsyncReadTask(){ 38 super(); 39 } 40 41 42 public AsyncReadTask(StreamAlgorithm algorithm, 43 boolean useDirectByteBuffer, boolean useByteBufferView){ 44 super(algorithm,useDirectByteBuffer,useByteBufferView); 45 } 46 47 49 52 protected void manageKeepAlive(boolean keepAlive,int count, 53 Exception exception){ 54 55 if ( count <= 0 || exception != null){ 57 if ( exception != null){ 58 detachProcessor(); 60 SelectorThread.logger().log(Level.FINEST, 61 "SocketChannel Read Exception: " 62 ,exception); 63 } 64 terminate(false); 65 } 66 } 67 68 69 74 public boolean executeProcessorTask() throws IOException { 75 boolean registerKey = false; 76 77 if (SelectorThread.logger().isLoggable(Level.FINEST)) 78 SelectorThread.logger().log(Level.FINEST,"executeProcessorTask"); 79 80 if ( algorithm.getHandler() 81 .handle(null, Handler.REQUEST_BUFFERED) == Handler.BREAK ){ 82 return true; 83 } 84 85 if (processorTask == null){ 88 attachProcessor(selectorThread.getProcessorTask()); 89 } else { 90 configureProcessorTask(); 93 } 94 95 if (taskEvent == null){ 96 taskContext = new TaskContext(); 97 taskEvent = new TaskEvent<TaskContext>(taskContext); 98 } 99 100 taskEvent.setStatus(TaskEvent.START); 102 taskContext.setInputStream(inputStream); 103 taskEvent.attach(taskContext); 104 fireTaskEvent(taskEvent); 105 return false; 106 } 107 108 109 112 public void terminate(boolean keepAlive){ 113 if ( isReturned ){ 115 return; 116 } 117 118 if (processorTask != null && processorTask.connectionHeaderValue){ 119 detachProcessor(); 120 registerKey(); 121 recycle(); 122 returnTask(); 123 } else { 124 super.terminate(keepAlive); 125 } 126 } 127 128 129 132 public void configureProcessorTask(){ 133 super.configureProcessorTask(); 134 if ( !getTaskListeners().contains(processorTask) ){ 135 processorTask.addTaskListener(this); 136 addTaskListener(processorTask); 137 } 138 } 139 } 140 | Popular Tags |