Fields Summary |
---|
public static final int | ISOLATED_TASK |
protected com.sun.enterprise.web.connector.grizzly.StreamAlgorithm | algorithmThe algorithm used to determine the context-root, the HTTP method,
the protocol etc. |
protected RulesExecutor | rulesExecutorThe RuleExecutor used to apply Rule |
protected ArrayList | listenersList of listeners |
protected int | initialBytePositionThe ByteBuffer initial position before applying the
Algorithm |
protected int | initialByteLimitThe ByteBuffer initial limit before applying the
Algorithm |
protected com.sun.enterprise.web.connector.grizzly.TaskEvent | taskEventThe TaskEvent used between this task and it's attached
ReadTask |
protected com.sun.enterprise.web.connector.grizzly.Pipeline | pipelineThe Thread Pool wrapper. |
private static ConcurrentHashMap | cacheKeyCache the SelectionKey to avoid parsing the
requests bytes more than once. |
Methods Summary |
---|
public void | addTaskListener(com.sun.enterprise.web.connector.grizzly.TaskListener task)Add the given TaskListener to this Task .
listeners.add(task);
|
public void | clearTaskListeners()Clean all the listeners of this Task
listeners.clear();
|
public void | doTask()Apply a set of Rule s to the current bytes requests using
an instance of ReadTask byte buffer. Once the
Rule has been successfully applied, execute it.
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);
}
|
public void | execute()Execute that task using the current Thread.
run();
|
protected void | fireTaskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)Notify listeners of that class that the processing has completed.
for (int i=0; i < listeners.size(); i++){
listeners.get(i).taskEvent(event);
}
|
public com.sun.enterprise.web.connector.grizzly.Pipeline | getPipeline()Get the Thread pool wrapper.
return pipeline;
|
public int | getType()This task type.
return ISOLATED_TASK;
|
public void | removeTaskListener(com.sun.enterprise.web.connector.grizzly.TaskListener task)Remove the given TaskListener/code> from this
Task .
listeners.remove(task);
|
public void | run()Execute the logic required to isolate the task.
try{
doTask();
} catch (IOException ex){
throw new RuntimeException(ex);
};
|
public void | setAlgorithm(com.sun.enterprise.web.connector.grizzly.StreamAlgorithm algorithm)Set the Algorithm used by this task.
this.algorithm = algorithm;
|
public void | setPipeline(com.sun.enterprise.web.connector.grizzly.Pipeline pipeline)Set the Thread pool wrapper.
this.pipeline = pipeline;
|
public void | setRulesExecutor(RulesExecutor rulesExecutor)Set the RuleExecutor instance used by this task.
this.rulesExecutor = rulesExecutor;
|
public void | taskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)Remove the SelectionKey from the cache.
wrappedTask = null;
fireTaskEvent(taskEvent);
((ReadTask)event.attachement()).setPipeline(pipeline);
|
public com.sun.enterprise.web.ara.IsolatedTask | wrap(com.sun.enterprise.web.connector.grizzly.Task task)Wrao the Task with this task.
wrappedTask = task;
return this;
|