1 23 24 package com.sun.enterprise.web.connector.grizzly.async; 25 26 import com.sun.enterprise.web.connector.grizzly.AsyncExecutor; 27 import com.sun.enterprise.web.connector.grizzly.AsyncHandler; 28 import com.sun.enterprise.web.connector.grizzly.Pipeline; 29 import com.sun.enterprise.web.connector.grizzly.ProcessorTask; 30 import com.sun.enterprise.web.connector.grizzly.TaskBase; 31 import com.sun.enterprise.web.connector.grizzly.TaskEvent; 32 33 41 public class AsyncProcessorTask extends TaskBase { 42 43 public final static int PRE_EXECUTE = 0; 44 public final static int INTERRUPTED = 1; 45 public final static int POST_EXECUTE = 2; 46 public final static int COMPLETED = 3; 47 51 private AsyncExecutor asyncExecutor; 52 53 54 57 private ProcessorTask processorTask; 58 59 60 63 private int stage = PRE_EXECUTE; 64 65 66 70 public void doTask() throws java.io.IOException { 71 boolean contineExecution = true; 72 while ( contineExecution ) { 73 try{ 74 switch(stage){ 75 case PRE_EXECUTE: 76 stage = INTERRUPTED; 77 contineExecution = asyncExecutor.preExecute(); 78 break; 79 case INTERRUPTED: 80 stage = POST_EXECUTE; 81 contineExecution = asyncExecutor.interrupt(); 82 break; 83 case POST_EXECUTE: 84 contineExecution = asyncExecutor.postExecute(); 85 stage = COMPLETED; 86 break; 87 } 88 } catch (Throwable t){ 89 if ( stage <= INTERRUPTED) { 90 stage = POST_EXECUTE; 92 } else { 93 stage = COMPLETED; 94 throw new RuntimeException (t); 95 } 96 } finally { 97 if ( stage == COMPLETED){ 99 stage = PRE_EXECUTE; 100 ((DefaultAsyncHandler)processorTask.getAsyncHandler()) 101 .returnTask(this); 102 } 103 } 104 } 105 } 106 107 110 public void taskEvent(TaskEvent event) { 111 } 112 113 116 public int getStage(){ 117 return stage; 118 } 119 120 121 124 public void recycle(){ 125 stage = PRE_EXECUTE; 126 processorTask = null; 127 } 128 129 130 134 public void setAsyncExecutor(AsyncExecutor asyncExecutor){ 135 this.asyncExecutor = asyncExecutor; 136 } 137 138 139 142 public AsyncExecutor getAsyncExecutor(){ 143 return asyncExecutor; 144 } 145 146 147 151 public void setProcessorTask(ProcessorTask processorTask){ 152 this.processorTask = processorTask; 153 if ( pipeline == null && processorTask != null) { 154 setPipeline(processorTask.getPipeline()); 155 } 156 } 157 158 159 162 public ProcessorTask getProcessorTask(){ 163 return processorTask; 164 } 165 166 } 167 | Popular Tags |