# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Projects\Grizzly\trunk\modules\grizzly\src\main\java\com\sun\grizzly # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: CallbackHandlerDescriptor.java --- CallbackHandlerDescriptor.java Locally New +++ CallbackHandlerDescriptor.java Locally New @@ -0,0 +1,37 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (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/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ + +package com.sun.grizzly; + +import com.sun.grizzly.Context.OpType; + +/** + * Class represents CallbackHandler descriptor. + * (Probably it should become part of CallbackHandler interface, but we don't want + * to touch existing API) + * + * @author Alexey Stashok + */ +public interface CallbackHandlerDescriptor { + public boolean isRunInSeparateThread(OpType operation); +} \ No newline at end of file Index: Context.java --- Context.java Base (BASE) +++ Context.java Locally Modified (Based On LOCAL) @@ -38,6 +38,7 @@ import java.nio.channels.SelectionKey; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; /** * This Object is used to share information between the Grizzly Framework @@ -389,11 +390,34 @@ * @throws com.sun.grizzly.PipelineFullException */ public void execute(ContextTask contextTask) throws PipelineFullException { + execute(contextTask, true); + } + + + /** + * Execute this Context using either Controller's Pipeline or current thread + * @param contextTask ContextTask, which will be + * executed by Pipeline + * @param runInSeparateThread if true - ContextTask will + * be executed in separate thread, false - in current thread. + * @throws com.sun.grizzly.PipelineFullException + */ + public void execute(ContextTask contextTask, boolean runInSeparateThread) throws PipelineFullException { if (contextTask != null) { contextTask.setContext(this); + if (runInSeparateThread) { getPipeline().execute(contextTask); + } else { + try { + contextTask.call(); + } catch(Exception e) { + Controller.logger().log(Level.SEVERE, + "Unexpected exception occured, when executing task: " + + contextTask, e); } } + } + } /** Index: TCPSelectorHandler.java --- TCPSelectorHandler.java Base (BASE) +++ TCPSelectorHandler.java Locally Modified (Based On LOCAL) @@ -218,7 +218,7 @@ /** * Flag, which shows whether shutdown was called for this SelectorHandler */ - protected AtomicBoolean isShutedDown = new AtomicBoolean(false); + protected AtomicBoolean isShutDown = new AtomicBoolean(false); public TCPSelectorHandler(){ this(false); @@ -295,7 +295,7 @@ if (selector == null){ try { - isShutedDown.set(false); + isShutDown.set(false); connectorInstanceHandler = new ConnectorInstanceHandler. ConcurrentQueueDelegateCIH( @@ -514,7 +514,7 @@ */ public void shutdown() { // If shutdown was called for this SelectorHandler - if (isShutedDown.getAndSet(true)) return; + if (isShutDown.getAndSet(true)) return; stateHolder.setState(State.STOPPED); @@ -687,7 +687,7 @@ * @throws java.io.IOException */ protected void invokeCallbackHandler(CallbackHandler callbackHandler, - Context context) throws IOException{ + Context context) throws IOException { IOEventioEvent = new IOEvent.DefaultIOEvent(context); context.setIOEvent(ioEvent); @@ -697,7 +697,14 @@ try { CallbackHandlerContextTask task = CallbackHandlerContextTask.poll(); task.setCallBackHandler(callbackHandler); - context.execute(task); + boolean isRunInSeparateThread = false; + + if (callbackHandler instanceof CallbackHandlerDescriptor) { + isExecuteInSeparateThread = + ((CallbackHandlerDescriptor) callbackHandler). + isRunInSeparateThread(context.getCurrentOpType()); + } + context.execute(task, isRunInSeparateThread); } catch (PipelineFullException ex){ throw new IOException(ex.getMessage()); }