users@grizzly.java.net

Re: async filter help

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 01 Dec 2008 20:28:44 -0500

Salut,

rama wrote:
> Actually "serverStupid" will just return false, this was just an example :D
>
> the problem is that EulerStaticAdapter (service) isn't executed neither
> if doFilter return true, neither if doFilter return false.
> what i expected to obtain (after reading the example) is that if i get
> "serverStupid" (return false) the execution of all
> the next filter (Both sync and async) is blocked. with return true, all
> the other filter (synch and async) are executed.

I see. You must explicitly invoke the Adapter yourself:

https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/arp/AsyncFilter.html

> An interface marker used to execute operations before a AsyncProcesssorTask in pre/post or interrupted. Usualy, implementation of this interface is called by an instance of AsyncExecutor. Using an AsyncExecutor, it is possible to suspend or resume the current request processing. Once suspended, the request can always be resumed using the AsyncExecutor, and the normal Grizzly invokation path will be used (like calling Adapter#service or GrizzlyAdapter#service). To invoke the GrizzlyAdapter from an AsyncFilter, just invoke AsyncExecutor.execute(), and then calling AsyncExecutor.postExecute() will commit the response. Implementation of this interface must be thread-safe.

Does it help?

--Jeanfrancois



>
> in this example, sync is never executed :(
> tnx :)
>
>> Salut,
>>
>> answering that one before the others :-)
>>
>> rama wrote:
>>> Hello, after reading a bit, i am ready for some new question :)
>>> this is not the real code, i don't think
>>> that this will work :D
>>> but, the question is, if i get a shtml or ehtml file
>>> i will do something (still to do)
>>> if not, return true, should go to EulerStaticAdapter
>>> but, the print is not executed.
>>> can someone give to me a little hint?
>>> ---server---
>>> st = new SelectorThread();
>>> st.setPort(port);
>>> st.setMaxThreads(maxThreads);
>>> isStarted = true;
>>> st.setAdapter(new
>>> EulerStaticAdapter(root1,root2));
>>> st.setEnableAsyncExecution(true);
>>> AsyncHandler asyncHandler = new DefaultAsyncHandler();
>>> asyncHandler.addAsyncFilter(new EulerAsyncAdapter());
>>> st.setAsyncHandler(asyncHandler); try {
>>> st.listen();
>>> } catch (InstantiationException ex) {
>>> throw new IOException(ex.getMessage());
>>> }
>>
>> So far so good.
>>
>>> ---asyncadapter---
>>> public class EulerAsyncAdapter implements AsyncFilter{
>>> public boolean doFilter(AsyncExecutor ex) {
>>> ProcessorTask pt = ex.getProcessorTask();
>>> String uri = pt.getRequestURI();
>>> if (uri.endsWith(".shtml") || uri.endsWith(".ehtml"))
>>> return serverStupid();
>>> System.out.println(uri);
>>> return true;
>>> }
>>
>> Yes it will works :-) But what serverStupid will do? if you want to
>> see an example of AsyncFilter, take a look at:
>>
>> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/comet/CometAsyncFilter.html
>>
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>> private boolean serverStupid() {
>>> // TODO Auto-generated method stub
>>> return false;
>>> }
>>> }
>>> ---sync---
>>> public class EulerStaticAdapter implements Adapter {
>>> public void service(Request req, final Response res) throws Exception {
>>> System.out.println(hey);
>>> }
>>> }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>