Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
 package com.sun.enterprise.web.ara;
This task is used to configure an instance of .ReadTask based on the Rule implementation.

Jeanfrancois Arcand
 public class IsolatedTask extends TaskWrapper implements TaskListener{
     public final static int ISOLATED_TASK = 4;
The algorithm used to determine the context-root, the HTTP method, the protocol etc.
     protected StreamAlgorithm algorithm;
The RuleExecutor used to apply Rule
     protected RulesExecutor rulesExecutor;
List of listeners
     protected ArrayList<TaskListenerlisteners = new ArrayList<TaskListener>();

The ByteBuffer initial position before applying the Algorithm
     protected int initialBytePosition;
The ByteBuffer initial limit before applying the Algorithm
     protected int initialByteLimit;
The TaskEvent used between this task and it's attached ReadTask
    protected TaskEvent<IsolatedTasktaskEvent;

The Thread Pool wrapper.
    protected Pipeline pipeline;    
Cache the SelectionKey to avoid parsing the requests bytes more than once.
    private static ConcurrentHashMap<SelectionKey,PipelinecacheKey = 
            new ConcurrentHashMap<SelectionKey,Pipeline>();
    public IsolatedTask(){
         = new TaskEvent<IsolatedTask>();
Apply a set of Rules to the current bytes requests using an instance of ReadTask byte buffer. Once the Rule has been successfully applied, execute it.
    public void doTask() throws IOException {   
        try {
            ReadTask readTask = (ReadTask);
            ByteBuffer byteBuffer = readTask.getByteBuffer();     
            SocketChannel socketChannel = 
            Socket socket = socketChannel.socket();
            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 (.parse(byteBuffer)) {
                execute = .execute(this);
                if ( execute ){                       
                    // Tell the ReadTask to not load bytes and re-use the one
                    // already loaded.
                    // Get notification once the task has completed.
                } else {
            } else {
                // Failed to read the URI. Close the connections.
        } catch (Exception ex){
                .log(.,"IsolatedTask logic exception.",ex);
Set the RuleExecutor instance used by this task.
    public void setRulesExecutor(RulesExecutor rulesExecutor){
        this. = rulesExecutor;
Set the Algorithm used by this task.
    public void setAlgorithm(StreamAlgorithm algorithm){
        this. = algorithm;
Wrao the Task with this task.
    public IsolatedTask wrap(Task task){
         = task;
        return this;
    // ------------------------------------------------------ Execution -----//
Execute that task using the current Thread.
    public void execute(){
Execute the logic required to isolate the task.
    public void run(){
        } catch (IOException ex){
            throw new RuntimeException(ex);
    // ----------------------------------------------------- Task Listener ----/
Add the given TaskListener to this Task.
    public void addTaskListener(TaskListener task){

Remove the given TaskListener/code> from this Task.
    public void removeTaskListener(TaskListener task){
Clean all the listeners of this Task
    public void clearTaskListeners(){

Notify listeners of that class that the processing has completed.
    protected void fireTaskEvent(TaskEvent<?> event){
        for (int i=0; i < .size(); i++){

Remove the SelectionKey from the cache.
    public void taskEvent(TaskEvent event) {
         = null;

This task type.
    public int getType(){
        return ;

Set the Thread pool wrapper.
    public void setPipeline(Pipeline pipeline) {
        this. = pipeline;

Get the Thread pool wrapper.
    public Pipeline getPipeline() {
        return ;
New to GrepCode? Check out our FAQ X