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() {
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?
Environment
Operating System: All
Platform: All
Affected Versions
[memcached-1.0]