Package com.sun.enterprise.web.connector.grizzly

Examples of com.sun.enterprise.web.connector.grizzly.ReadTask


     * an instance of <code>ReadTask</code> byte buffer. Once the
     * <code>Rule</code> has been successfully applied, execute it.
     */
    public void doTask() throws IOException {  
        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);
View Full Code Here


                    "HeapMemoryRuleThread"){
               
                public void run(){
                    while (true) {
                        try{
                            ReadTask t =
                                (ReadTask)HeapMemoryRulePipeline.this.getTask();
                            if ( t != null){
                                long current = usedMemory();
                                t.run();   
                                long usage = usedMemory() - current;
                                if ( usage > 0){
                                    String token =
                                       contextRootyCache.get(t);
                                    appMemoryUsage.put(token,usage);
View Full Code Here

     * Execute the <code>Rule</code>s on the <code>IsolatedTask</code>
     * @param isolatedTask the task used.
     * @return true if the request processing can continue.
     */
    public boolean execute(IsolatedTask isolatedTask) {
        ReadTask task = (ReadTask)isolatedTask.getWrappedTask();
                      
        Integer status = 0;
        int i = 0;
        isCachingAllowed = true;
        while(true) {
            rules.get(i).attach(task);
           
            try{
                status = (Integer)rules.get(i).call()
            } catch(Exception ex) {
                SelectorThread.logger().log(Level.SEVERE,"Rule exception",ex);
                return true;
            }
           
            isCachingAllowed = (status == RULE_OK_NOCACHE ? false:true);
           
            if (status == RULE_DELAY){  
               
                // Wait until the delay expire. The current thread will
                // wait and then re-execute the rules.
                try{
                    Thread.sleep(delayValue);
                } catch (InterruptedException ex) {
                    SelectorThread.logger().
                            log(Level.SEVERE,"Rule delay exception",ex);
                }
                i = 0;
                continue;
            else if ( status == RULE_BLOCKED ){
                task.cancelTask("No resources available.", HtmlHelper.OK);
                return true;
            }
           
            i++;
            if (i == rules.size()){
View Full Code Here

        for (int i = 0; i < readThreads.length; i++) {
            readThreads[i] = new SSLSelectorReadThread(){
                public ReadTask getReadTask(SelectionKey key)
                    throws IOException{

                    ReadTask readTask = SSLSelectorThread.this.getReadTask(key);
                    readTask.setSelectorThread(this);
                    return readTask;
                }
            };
            ((SSLSelectorReadThread)readThreads[i]).countName = i;
            configureReadThread((SSLSelectorReadThread)readThreads[i]);
View Full Code Here

     * create a new instance. Make sure the SSLEngine is reused when the
     * SelectionKey is part of a keep-alive transaction.
     */
    @Override
    public ReadTask getReadTask(SelectionKey key) throws IOException{
        ReadTask task = super.getReadTask(key);
       
        SSLEngine sslEngine = null;
        Object attachment = key.attachment();
        if (attachment != null && attachment instanceof SSLEngine){
            sslEngine = (SSLEngine)attachment;
View Full Code Here

     * Execute the <code>Rule</code>s on the <code>IsolatedTask</code>
     * @param isolatedTask the task used.
     * @return true if the request processing can continue.
     */
    public boolean execute(IsolatedTask isolatedTask) {
        ReadTask task = (ReadTask)isolatedTask.getWrappedTask();
                      
        Integer status = 0;
        int i = 0;
        isCachingAllowed = true;
        while(true) {
            rules.get(i).attach(task);
           
            try{
                status = (Integer)rules.get(i).call()
            } catch(Exception ex) {
                SelectorThread.logger().log(Level.SEVERE,"Rule exception",ex);
                return true;
            }
           
            isCachingAllowed = (status == RULE_OK_NOCACHE ? false:true);
           
            if (status == RULE_DELAY){  
               
                // Wait until the delay expire. The current thread will
                // wait and then re-execute the rules.
                try{
                    Thread.sleep(delayValue);
                } catch (InterruptedException ex) {
                    SelectorThread.logger().
                            log(Level.SEVERE,"Rule delay exception",ex);
                }
                i = 0;
                continue;
            else if ( status == RULE_BLOCKED ){
                task.cancelTask("No resources available.", HtmlHelper.OK);
                return true;
            }
           
            i++;
            if (i == rules.size()){
View Full Code Here

     * an instance of <code>ReadTask</code> byte buffer. Once the
     * <code>Rule</code> has been successfully applied, execute it.
     */
    public void doTask() throws IOException {  
        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);
View Full Code Here

               
                @Override
                public void run(){
                    while (true) {
                        try{
                            ReadTask t =
                                (ReadTask)HeapMemoryRulePipeline.this.getTask();
                            if ( t != null){
                                long current = usedMemory();
                                t.run();   
                                long usage = usedMemory() - current;
                                if ( usage > 0){
                                    String token =
                                       contextRootyCache.get(t);
                                    appMemoryUsage.put(token,usage);
View Full Code Here

TOP

Related Classes of com.sun.enterprise.web.connector.grizzly.ReadTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.