Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   * 
   * 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 https://glassfish.dev.java.net/public/CDDL+GPL.html
  * 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.connector.grizzly.blocking;
 
 
Process a blocking socket. By default, SSL is using blocking mode.

Author(s):
Jean-Francois Arcand
 
 public class ReadBlockingTask extends DefaultReadTask{
    
    
The PipelineStatistic objects used when gathering statistics.
 
     protected PipelineStatistic pipelineStat;
            
    
    
If the Task handling an SSL based request.
 
     protected boolean isSecure = false;
    
    
    
The Handler used to pre-process the request.
 
     private Handler handler;
     
             
     public ReadBlockingTask(){
          = ;
          = new TaskContext();
          = new TaskEvent();
         .setStatus(.);
     }
    
    
    
Force this task to always use the same ProcessorTask instance.
 
     public void attachProcessor(DefaultProcessorTask processorTask){
         try {
              = (Handler) Thread.currentThread().getContextClassLoader().loadClass(
                 .).newInstance();
         } catch (Exception e) {
              = new NoParsingHandler();
         }
         this. = processorTask;
         processorTask.setHandler();  
     }
    
    
    
Dispatch an Http request to a ProcessorTask
    @Override
    public void doTask() throws IOException {
        Socket socket = .getSocket();
        SelectorBlockingThread blockingSelector = 
                (SelectorBlockingThread);
        blockingSelector.setSocketOptions(socket);
        if () {
            try {
                blockingSelector.getServerSocketFactory().handshake(socket);
            } catch (Throwable ex) {
                SelectorThread.getLogger().log(."selectorThread.sslHandshakeException"ex);
                try {
                    socket.close();
                } catch (IOException ioe){
                    // Do nothing
                }
                .setStatus(.);
                taskEvent();
                return;
            }
        }
        .addTaskListener(this);
        addTaskListener((ProcessorBlockingTask));       
        .attachChannel(socket.getChannel());
        // Notify the ProcessorTask that we are ready to process the request.
        fireTaskEvent();
    }
    
    
    
Clear the current state and make this object ready for another request.
    @Override
    public void recycle(){
        clearTaskListeners();
        .setStatus(.);                    
    }  
    
    
    
Gracefully close the blocking socket.
    @Override
    protected void finishConnection(){
        Socket socket = .getSocket();
        if ( ! ) {
            try{
                if (!socket.isInputShutdown()){
                    socket.shutdownInput();
                }
            } catch (IOException ioe){
                ;
            }
            try{
                if (!socket.isOutputShutdown()){
                    socket.shutdownOutput();
                }
            } catch (IOException ex){
                ;
            }
        }
        try{
            socket.close();   
        } catch (IOException ex){
            ;
        } finally {
            if (isMonitoringEnabled()) {
                getRequestGroupInfo().decreaseCountOpenConnections();
            }
        }
    } 

    
    
Receive notification from other Task and recycle this task.
    public void taskEvent(TaskEvent event){
        if ( event.getStatus() == .){
            finishConnection();
            // We must recycle only if we are sure ProcessorTask has completed its
            // processing. If not, 
            if () {
                .recycle();
                recycle();
                .returnTask(this);
            }
        }
    }


    
Return the current Socket used by this instance

Returns:
socket the current Socket used by this instance
    public Socket getSocket(){
        return .getSocket();
    }
    
    
    
Set the PipelineStatistic object used to gather statistic;
    public void setPipelineStatistic(PipelineStatistic pipelineStatistic){
         = pipelineStatistic;
    }
    
    
    
Return the PipelineStatistic object used to gather statistic;
        return ;
    }
    
    
    
Set the isSecure attribute.
    public void setSecure(boolean isSecure){
        this. = isSecure;
    }
    
    
    
Return the isSecure.
    public boolean getSecure(){
        return ;
    }
New to GrepCode? Check out our FAQ X