dev@grizzly.java.net

Grizzly WebServer now uses 1.5 framework.

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 21 Feb 2007 12:52:16 -0500

Hi,

this is a small steps but still a good one. I've ported the GlassFish
WebServer code (which is build on to on Grizzly 1.0) and make it use
Grizzly Framework 1.5. Fortunately the steps required was simple. Just
FYI, I've removed all NIO related code in Grizzly SelectorThread and added:

> 611 protected void initController(){
> 612 controller = new Controller();
> 613 TCPSelectorHandler selectorHandler = new TCPSelectorHandler();
> 614 selectorHandler.setPort(port);
> 615 selectorHandler.setInet(inet);
> 616 selectorHandler.setLinger(linger);
> 617 selectorHandler.setLogger(logger);
> 618 selectorHandler.setReuseAddress(true);
> 619 selectorHandler.setSelectTimeout(selectorTimeout);
> 620 selectorHandler.setServerTimeout(serverTimeout);
> 621 selectorHandler.setSocketTimeout(keepAliveTimeoutInSeconds * 1000);
> 622 selectorHandler.setSsBackLog(ssBackLog);
> 623 selectorHandler.setTcpNoDelay(tcpNoDelay);
> 624 controller.setSelectHandler(selectorHandler);
> 625
> 626 DefaultSelectionKeyHandler keyHandler =
> 627 new DefaultSelectionKeyHandler(){
> 628 public void expire(SelectionKey key){
> 629 super.expire(key);
> 630 if (isMonitoringEnabled()) {
> 631 getRequestGroupInfo().decreaseCountOpenConnections();
> 632 }
> 633 }
> 634 };
> 635 keyHandler.setLogger(logger);
> 636 keyHandler.setTimeout(keepAliveTimeoutInSeconds * 1000);
> 637 controller.setSelectionKeyHandler(keyHandler);
> 638
> 639 final DefaultProtocolChain protocolChain
> 640 = new DefaultProtocolChain();
> 641
> 642 protocolChain.addFilter(new ReadFilter());
> 643 ProtocolFilter httpParserFilter = new ProtocolFilter(){
> 644
> 645 public boolean execute(Context ctx) throws IOException {
> 646 ByteBuffer byteBuffer =
> 647 ((WorkerThread)Thread.currentThread()).getByteBuffer();
> 648 byteBuffer.flip();
> 649 ByteBufferInputStream inputStream =
> 650 new ByteBufferInputStream();
> 651 SelectionKey key = ctx.getSelectionKey();
> 652 inputStream.setSelectionKey(key);
> 653 inputStream.setByteBuffer(byteBuffer);
> 654
> 655 ProcessorTask processorTask = getProcessorTask();
> 656 processorTask.setSelectionKey(key);
> 657 processorTask.setSocket(((SocketChannel)key.channel()).socket());
> 658 //processorTask.setHandler(algorithm.getHandler());
> 659
> 660 boolean keepAlive = false;
> 661
> 662 try{
> 663 keepAlive = processorTask.process(inputStream,null);
> 664 } catch (Throwable ex){
> 665 logger.log(Level.INFO,"ProcessorTask exception",ex);
> 666 keepAlive = false;
> 667 }
> 668 ctx.setCancelKey(!keepAlive);
> 669
> 670 // Last filter.
> 671 return false;
> 672 }
> 673
> 674 public boolean postExecute(Context ctx) throws IOException {
> 675 return true;
> 676 }
> 677
> 678 };
> 679 protocolChain.addFilter(httpParserFilter);
> 680
> 681 InstanceHandler<ProtocolChain> instanceHandler
> 682 = new InstanceHandler<ProtocolChain>(){
> 683 /**
> 684 * Always return instance of ProtocolChain.
> 685 */
> 686 public ProtocolChain poll(){
> 687 return protocolChain;
> 688 }
> 689
> 690 /**
> 691 * Pool an instance of ProtocolChain.
> 692 */
> 693 public boolean offer(ProtocolChain instance){
> 694 return true;
> 695 }
> 696 };
> 697 controller.setInstanceHandler(instanceHandler);
> 698 controller.setPipeline(processorPipeline);
> 699
> 700
> 701 }

OK this is not perfect yet, but demonstrate how easy it will be to
implement other protocol than http. Once I've all the missing features
implemented, I will call for a vote about our first release, which
should be 1.5.0.

A+

-- Jeanfrancois