1 23 package com.sun.enterprise.web.connector.grizzly; 24 25 import com.sun.enterprise.web.connector.grizzly.handlers.NoParsingHandler; 26 import java.io.IOException ; 27 import java.net.Socket ; 28 29 34 public class ReadBlockingTask extends ReadTask{ 35 36 39 protected PipelineStatistic pipelineStat; 40 41 42 45 private NoParsingHandler handler; 46 47 48 public ReadBlockingTask(){ 49 type = READ_TASK; 50 taskContext = new TaskContext(); 51 taskEvent = new TaskEvent(taskContext); 52 taskEvent.setStatus(TaskEvent.START); 53 } 54 55 56 60 public void attachProcessor(ProcessorTask processorTask){ 61 handler = new NoParsingHandler(selectorThread.getPort()); 62 63 this.processorTask = processorTask; 64 processorTask.addTaskListener(this); 65 addTaskListener(processorTask); 66 67 processorTask.useAlternateKeepAlive(false); 68 processorTask.setHandler(handler); 69 } 70 71 72 75 public void doTask() throws IOException { 76 handler.attachChannel(processorTask.getSocket().getChannel()); 77 78 fireTaskEvent(taskEvent); 80 } 81 82 83 86 protected void finishConnection(){ 87 Socket socket = processorTask.getSocket(); 88 89 if (selectorThread.getSSLImplementation() == null){ 91 try{ 92 if (!socket.isInputShutdown()){ 93 socket.shutdownInput(); 94 } 95 } catch (IOException ioe){ 96 ; 97 } 98 try{ 99 if (!socket.isOutputShutdown()){ 100 socket.shutdownOutput(); 101 } 102 } catch (IOException ex){ 103 ; 104 } 105 } 106 107 try{ 108 socket.close(); 109 } catch (IOException ex){ 110 ; 111 } finally { 112 if (isMonitoringEnabled()) { 113 getRequestGroupInfo().decreaseCountOpenConnections(); 114 } 115 } 116 } 117 118 119 122 public void taskEvent(TaskEvent event){ 123 if ( event.getStatus() == TaskEvent.COMPLETED){ 124 finishConnection(); 125 126 if (recycle) { 129 processorTask.recycle(); 130 selectorThread.returnTask(this); 131 } 132 } 133 } 134 135 136 140 protected Socket getSocket(){ 141 return processorTask.getSocket(); 142 } 143 144 145 148 public void setPipelineStatistic(PipelineStatistic pipelineStatistic){ 149 this.pipelineStat = pipelineStatistic; 150 } 151 152 153 157 public PipelineStatistic getPipelineStatistic(){ 158 return pipelineStat; 159 } 160 } 161 | Popular Tags |