# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Projects\griz-last\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: Context.java --- Context.java Base (BASE) +++ Context.java Locally Modified (Based On LOCAL) @@ -49,12 +49,14 @@ import com.sun.grizzly.util.AttributeHolder; import com.sun.grizzly.util.Copyable; import com.sun.grizzly.util.SelectionKeyAttachment; +import com.sun.grizzly.util.WorkerThread; import java.io.IOException; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; /** @@ -188,6 +190,12 @@ /** + * Reference Counter indicating How many Threads share this Context + * Starts at one. + */ + private AtomicInteger refCounter=new AtomicInteger(1); + + /** * Constructor */ public Context() { @@ -209,8 +217,8 @@ copyContext.ioEvent = ioEvent; copyContext.asyncQueueReader = asyncQueueReader; copyContext.asyncQueueWriter = asyncQueueWriter; - copyContext.asyncQueueReadable = asyncQueueReadable; - copyContext.asyncQueueWritable = asyncQueueWritable; + // copyContext.asyncQueueReadable = asyncQueueReadable; + // copyContext.asyncQueueWritable = asyncQueueWritable; } /** @@ -366,6 +374,7 @@ if (attributes != null) { attributes.clear(); } + refCounter.set(1); isSuspended = false; } @@ -864,5 +873,26 @@ recycle(); getController().returnContext(this); } + /** + * Called by Threads that are not instances of {@link WorkerThread} to + * ensure that other Threads will not {@link #recycle()} this + * {@link Context} + * When done they must return this {@link Context} to + * {@link Controller#returnContext(com.sun.grizzly.Context) + * + * @return Current Thread reference count + */ + public void incrementRefCount(){ + refCounter.incrementAndGet(); + } + /** + * Decrements the reference count of this Context. + * See {@link Controller#returnContext(com.sun.grizzly.Context)} + * @return return decremented reference count + */ + public int decrementRefCount(){ + return refCounter.decrementAndGet(); } + +}