Hi Brian,
OK I know what is the problem. During the refactoring, I've moved the
ARP support from modules/http to modules/comet. If you look at:
https://grizzly.dev.java.net/source/browse/grizzly/trunk/modules/comet/src/main/java/com/sun/grizzly/standalone/ARP.java?rev=44&view=markup
I'm overriding the SelectorThread.initController() to inject the proper
ProtocolFilter. Mainly I'm doing:
> protocolChain.addFilter(new ReadFilter());
> protocolChain.addFilter(
> new AsyncProtocolFilter(algorithmClass,port));
AsyncProtocolFilter is required for supporting ARP.
Now this should be hidden for 1.0 user, thus I will port the logic from
the comet module to the http module so your code will need no changes to
execute.
Thanks!
-- Jeanfrancois
Brian McCallister wrote:
> I grabbed the HTTP part of grizzly today and pulled out what I had done
> previously against the 1.0 version to port to 1.5-SNAPSHOT. Where before
> I had:
>
> public static void main(String[] args) throws IOException,
> InstantiationException
> {
> SelectorThread sel = new SelectorThread();
> sel.setPort(8002);
>
> sel.setAdapter(new MyAdapter());
>
> final AsyncHandler handler = new DefaultAsyncHandler();
> handler.addAsyncFilter(new AsyncFilter()
> {
> public boolean doFilter(final AsyncExecutor executor)
> {
> final AsyncTask asyncTask = executor.getAsyncTask();
> final AsyncHandler asyncHandler =
> executor.getAsyncHandler();
>
> final DefaultProcessorTask processorTask =
> (DefaultProcessorTask)
> executor.getAsyncTask().getProcessorTask();
> processorTask.getRequest().setAttribute(CALLBACK_KEY,
> new Runnable() {
> public void run()
> {
> asyncHandler.handle(asyncTask);
> }
> });
> processorTask.invokeAdapter();
> return false;
> }
> });
> sel.setAsyncHandler(handler);
> sel.setEnableAsyncExecution(true);
> sel.setDisplayConfiguration(true);
> sel.initEndpoint();
> sel.startEndpoint();
> }
>
> and an adaptor:
>
> class MyAdapter implements Adapter
> {
> static byte[] CONTENT;
> {
> CONTENT = ByteChunk.convertToBytes("hello world!\n");
> }
>
> private static final ScheduledExecutorService exec =
> Executors.newScheduledThreadPool(2);
>
> public void service(final Request req, final Response res)
> throws Exception
> {
> System.out.println("got request");
> exec.schedule(new Callable<Void>() {
> public Void call() throws Exception
> {
> res.setStatus(200);
>
> byte[] bytes = CONTENT;
> ByteChunk chunk = new ByteChunk();
> res.setContentLength(bytes.length);
> res.setContentType("text/plain");
> chunk.append(bytes, 0, bytes.length);
> res.doWrite(chunk);
> System.out.println("sending resposne!");
> Async.commit(req);
> return null;
> }
> }, 10, TimeUnit.SECONDS);
> }
>
> public void afterService(Request req, Response res) throws
> Exception
> {
> req.action( ActionCode.ACTION_POST_REQUEST , null);
> }
>
> public void fireAdapterEvent(String type, Object data)
> {
> }
> }
>
> Which would correctly respond in 10 seconds, now it responds with
> nothing immediately, and 10 seconds later attempts to respond but
> doesn't actually do anything (also logging no error).
>
> Any guidelines on how to do ARP with the new code?
>
> -Brian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>