dev@grizzly.java.net

Re: Asynchronous Request Processing with TCPIP

From: John ROM <snake-john_at_gmx.de>
Date: Mon, 14 Jul 2008 16:54:55 +0200

Laugh,
I am actually trying to write a Grizzly Tutorial explaining the framework-sample package and I will mention it there.

I hope I can send you the Tutorial in 3/4 days.

Many Greetings
John



-------- Original-Nachricht --------
> Datum: Mon, 14 Jul 2008 10:39:14 -0400
> Von: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
> An: dev_at_grizzly.dev.java.net
> Betreff: Re: Asynchronous Request Processing with TCPIP

> Salut,
>
> Oleksiy Stashok wrote:
> > Hello John,
> >
> > I like the patch you propose, let's wait for Jeanfrancois to check it
> also.
>
> This looks good....and should deserve a blog just for the usefulness of
> the feature :-)
>
> A+
>
> -- Jeanfrancois (the blog pusher :-))
>
> >
> > Thanks.
> >
> > WBR,
> > Alexey.
> >
> > On Jul 14, 2008, at 10:12 , John ROM wrote:
> >
> >> Hi Alexey,Jeanfrancois,
> >> here is my current patch for making Context sharable.
> >>
> >> Jeanfrancois you have to look at resume,cancel to check if
> >> that is what you want...
> >>
> >> Many Greetings
> >> John
> >>
> >>
> >>
> >>
> >>
> >> This patch file was generated by NetBeans IDE
> >> # 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;
> >>
> >> /**
> >> @@ -186,7 +188,13 @@
> >> */
> >> private boolean isSuspended = false;
> >>
> >> + /**
> >> + * Reference Counter indicating How many Threads share this
> >> Context.
> >> + * Starts at one allready counting {_at_link WorkerThread}.
> >> + */
> >> + private AtomicInteger refCounter=new AtomicInteger(1);
> >>
> >> +
> >> /**
> >> * Constructor
> >> */
> >> @@ -365,6 +373,7 @@
> >> attributes.clear();
> >> }
> >> isSuspended = false;
> >> + refCounter.set(1);
> >> }
> >>
> >>
> >> @@ -799,6 +808,7 @@
> >> public void suspend(){
> >> if (isSuspended) return;
> >> isSuspended = true;
> >> + incrementRefCount();
> >> setKeyRegistrationState(keyRegistrationState.NONE);
> >> }
> >>
> >> @@ -815,15 +825,16 @@
> >>
> >>
> >> /**
> >> - * Resume a {_at_link #suspend}ed {_at_link Context}. Invoking this
> >> method will
> >> - * automatically clean the state of this Context and mark it as a
> >> candidate
> >> - * for being re-used by another Thread and connection.
> >> + * Resume a {_at_link #suspend}ed {_at_link Context}.
> >> + * <strong>Resume will not call {_at_link
> >> Context#recycle}</strong>. So
> >> + * after the caller is finished using Context caller must
> >> + * call {_at_link Controller#returnContext(com.sun.grizzly.Context)}
> >> + * to mark it as a candidate for being re-used by another
> >> Thread and connection.
> >> *
> >> * <strong>Important. When resumed, all operations done on this
> >> * object are not thread-safe and there is probability that another
> >> * thread is already using this object. Never use this object once
> >> resumed.</strong>
> >> *
> >> - *
> >> * When invoked this method will automatically set the
> >> * {_at_link Context#setKeyRegistrationState} to {_at_link
> >> KeyRegistrationState}
> >> * to KeyRegistrationState.REGISTER and automatically re-enable
> >> read and
> >> @@ -835,8 +846,6 @@
> >> if (!isSuspended) return;
> >> isSuspended = false;
> >> selectorHandler.register(key, SelectionKey.OP_READ);
> >> - recycle();
> >> - getController().returnContext(this);
> >> }
> >>
> >>
> >> @@ -859,8 +868,30 @@
> >> if (!isSuspended) return;
> >> isSuspended = false;
> >> selectorHandler.getSelectionKeyHandler().cancel(key);
> >> - recycle();
> >> getController().returnContext(this);
> >> }
> >> + /**
> >> + * Called by outer Threads that are not instances of {_at_link
> >> WorkerThread} to
> >> + * indicate that this {_at_link Context} should not be
> >> + * {_at_link #recycle()} or offered back to its Pool.
> >> + *
> >> + * When a outer Thread is done with {_at_link Context} it must call
> >> + * {_at_link Controller#returnContext(com.sun.grizzly.Context) to
> >> + * ensure that {_at_link Context} will be propably recycled.
> >> + *
> >> + * @return Current Thread reference count
> >> + */
> >> + public void incrementRefCount(){
> >> + refCounter.incrementAndGet();
> >> + }
> >>
> >> + /**
> >> + * Decrements the reference count of this Context.
> >> + * See {_at_link Controller#returnContext(com.sun.grizzly.Context)}
> >> + * @return return decremented reference count
> >> + */
> >> + public int decrementRefCount(){
> >> + return refCounter.decrementAndGet();
> >> }
> >> +
> >> +}
> >>
> >> # This patch file was generated by NetBeans IDE
> >> # 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: Controller.java
> >> --- Controller.java Base (BASE)
> >> +++ Controller.java Locally Modified (Based On LOCAL)
> >> @@ -588,6 +588,10 @@
> >> ctx.configureOpType(key);
> >> }
> >>
> >> + if (logger.isLoggable(Level.FINE)) {
> >> + logger.log(Level.FINE, "pollContext(..) Context : "+ctx);
> >> + }
> >> +
> >> return ctx;
> >> }
> >>
> >> @@ -599,10 +603,17 @@
> >> }
> >>
> >> /**
> >> - * Return a Context to the pool
> >> + * Return a {_at_link Context} to its pool if it is not shared.
> >> + *
> >> * @param ctx - the {_at_link Context}
> >> */
> >> public void returnContext(Context ctx){
> >> + if(ctx.decrementRefCount()>0) {
> >> + return;
> >> + }
> >> + if (logger.isLoggable(Level.FINE)) {
> >> + logger.log(Level.FINE, "returnContext() Context : "+ctx);
> >> + }
> >> ctx.recycle();
> >> contexts.offer(ctx);
> >> }
> >> # This patch file was generated by NetBeans IDE
> >> # 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: ContextTask.java
> >> --- ContextTask.java Base (BASE)
> >> +++ ContextTask.java Locally Modified (Based On LOCAL)
> >> @@ -59,10 +59,6 @@
> >> }
> >>
> >> public void recycle() {
> >> - // Do not recycle when suspended.
> >> - if (context.isSuspended()){
> >> - return;
> >> - }
> >>
> >> if (context != null) {
> >> context.getController().returnContext(context);
> >>
> >>
> >>
> >> --
> >> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> >> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> >>
> <Context.diff><ContextTask.diff><Controller.diff>---------------------------------------------------------------------
> >>
> >> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> >> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> > For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net

-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx