Grizzly is an open source NIO framework that provides high performance APIs for TCP, UDP, and SSL communications. It aims to simplify programming with Java NIO by hiding complexity. Grizzly 2.0 is a complete redesign with a clearer core API and improved performance. It introduces unified buffer/memory management and thread pool APIs. Grizzly includes modules for HTTP, Comet, and servlets that can be used to build web servers and applications. The Grizzly community is active with around 25,000 downloads per month and discussions on mailing lists.
3. 1. What is Project Grizzly
â˘âOpen Source Project https://grizzly.dev.java.net
â˘âOpen Sourced under CDDL/LGPL license.
â˘âVery open community policy.
>â All project communications are done on Grizzly mailing
list. No internal, off mailing list conversations a-la-Sailfin.
>â Project meetings open to anyone
â˘âProject decisions are made by project member
votes. Code contributions frequents.
â˘âApprox ~25 000 download for the last 3 months
â˘âMailing list quite busy some day!
3
4. 1. What is project Grizzly
â˘âCommiters
>â Oleksiy Stashok (Sun) â Lead (all modules)
>â Jean-Francois Arcand (Sun)âŤ( ââŹall modules)
>â Shing Wai Chan (Sun)âŤ( ââŹhttp, comet, bayeux)
>â Ken Cavanaugh (Sun)âŤ( ââŹframework)
>â Charlie Hunt (Sun)âŤ( ââŹframework)
>â John Vieten (Conclude GmbH)âŤ( ââŹtutorial, framework)
>â Sebastien Dionne (Consultant)âŤ( ââŹtutorial, framework)
>â Takai Naoto (ITOCHU Techno-Solution)âŤ( ââŹjruby, bayeux)
â˘â Active users listâŚthe community answer for us!
4
5. What is Project Grizzly
â ses Java NIO primitives and hides the complexity
U
programming with Java NIO.
â tarted in 2004 (Grizzly 1.0). Own project February 2007
S
(Grizzly 1.5)
â .0 represented extracted network layer of Glassfish
1
â asy-to-use high performance APIs for TCP, UDP and SSL
E
communications.
â tilizes high performance buffers and buffer management.
U
â hoice of several different high performance thread pools.
C
â hip with an HTTP module which is really easy to embed.
S
5
8. 2.1 Framework
â˘â The root of Grizzly. Everything build on top of this module
â˘â The Grizzly Framework bundles default implementation
for TCP, UDP and TLS/SSL transports.
â˘â Used to implement protocol based applications like http,
sip, custom protocol, etc.
â˘â In this module, EVERYTHING is customizable. If the
default isn't doing what you need , customize it!
8
14. HTTP modules (http, http-utils)
â˘â The Grizzly Framework also have an HTTP framework that can be
used to build Web Server
â˘â Extremely small, perfect for small devices
>â Like iPhone, Android, Smart Box, etc.
â˘â Simple interface to allow customization of the HTTP Protocol
>â GrizzlyRequest: A utility class to manipulate the HTTP protocol
request.
>â GrizzlyResponse: A utility class to manipulate the HTTP protocol
response.
>â GrizzlyAdapter: A utility class to manipulate the HTTP request/
response object.
14
15. 2.2 Http module
public class FileAdapter extends GrizzlyAdapter{
public void service(GrizzlyRequest req,
GrizzlyResponse res){
ByteChun bc = req.decodedURI();
// Prevent XSS attack
HttpRequestDecoded.decode(bc);
// OK, we are safe
res.write((loadFile(bc));
res.flush();
res.close();
15
19. 2.4 Grizzly Comet Framework
â˘âGrizzly Comet is a framework that ship with
GlassFish v1|2|3, and can also be embedded into
any application.
>â One day ď, the code will be moved to a new project
called Atmosphere (Atmosphere.dev.java.net)
>â Grizzly Comet, for all web server!!
â˘âThe Grizzly Comet Framework includes a set of
components that can be used for building Comet
based application:
>â Grizzly Comet, Continuation, Grizzlet, Messages Bus,
Bayeux support
19
20. AtmosphereâŚ.
Reuse experience and code...from Grizzly Comet to Jersey!
Grizzlet Atmosphere re-usable
(Atmosphere POJO)âŤâ⏠Components library
Jersey's Injection Provider, Jerseyâs IoC Support
Atmosphere Servlet Runtime Engine
Tomcat Comet Grizzly Comet Jetty Comet Blocking WS
User defined Atmosphere Component
20
23. 2.5 Grizzly Servlet Container
â˘âThe community started developing a Servlet
Container
>â Incomplete, not (*yet*) Servlet compliant
>â Very small and fast
>â No extraâŚjust the basicâŚ.with power
>â Easy to embed in any application.
â˘âReally useful for writing unit test.
23
26. 4.1 Introduction
â˘âStarted in June 2008.
â˘âCompletely new Grizzly core API.
â˘âNo backwards compatibility requirement.
>â 1.0 suffered design limitation like supporting SJSAS,
Tomcat API AND Sun Web Server API. This was a major
restriction and some API are quite ugly.
>â 1.5 was a tentative to keep our 1.0 Community on board,
and grow.
>â 1.8.x is successful, but is now time to do a revolution,
e.g. bye bye GlassFish API ď
26
27. 4.2 Goals
â˘âMake framework core API more clear and useful,
based on earlier experience. Especially client side.
â˘âPerformance. Make sure API changes will not affect
the performance, which is still the main goal for
Grizzly.
â˘âIntroduce unified Buffer/Memory management API.
â˘âUnify ThreadPool implementation. Make it compatible
with ExecutorService, provided by JDK.
â˘âReborn a Grizzly based on Community Feedback
and lessons learned since 2004.!
27
29. 4.3 New features
â˘âFilter chain standalone read/write.
â˘âMessage parsing using streams.
â˘âSmart message parser
29
30. 4.3.1 FilterChain standalone read/
write
â˘âLeverage filters logic for a client side.
â˘âMinimize the effort to build nice client code.
â˘âSupports blocking and asynchronous modes
30
31. 4.3.1 FilterChain standalone read/
write
TCPNIOTransport transport =
TransportManager.instance().createTCPTransport();
transport.getFilterChain().add(new TransportFilter());
transport.getFilterChain().add(new SSLFilter());
transport.getFilterChain().add(new StringFilter());
transport.getFilterChain().add(new EchoFilter());
--- (1) start the âtransportâ in the server mode
--- (2) connect client the âconnectionâ to the âtransportâ
Future writeFuture = transport.getFilterChain().write(connection, âHello
worldâ);
Future readFuture = transport.getFilterChain().read(connection);
String result = (String) readFuture.get();
// The result should contain âHello worldâ, sent by server
31
32. 4.3.2 Message parsing using streams
â˘âSimplify message parsing.
â˘âNo ByteBuffer positions, limits, capacities!
â˘âSimple stream API, which supports Java primitive
types and arrays.
32
33. 4.3.2 Message parsing using streams
// initialize the filter chain
transport.getFilterChain().add(new TransportFilter());
transport.getFilterChain().add(new StreamFilter());
transport.getFilterChain().add(new CustomProtocolParser());
-------------------------------- cut --------------------------------------
public class CustomProtocolParser extends FilterAdapter {
public NextAction handleRead(FilterChainContext context) {
StreamMessage message =
(StreamMessage) context.getMessage();
Reader reader = message.getReader();
if (reader.availabe(4)) {
int a = reader.getInt();
int b = reader.getInt();
message.getWriter().putInt(a+b);
33
34. 4.3.3 Smart message parser
â˘âKnows how to parse the custom message, based on
message class structure.
â˘âPOJO in enough, however could be driven by
annotations.
â˘âIt's possible to provide custom encoder/decoder for
complex types.
34
35. 4.3.3 Smart message parser
transport.getFilterChain().add(new TransportFilter());
transport.getFilterChain().add(new SSLFilter());
// Parse the data according to MyMessage class
transport.getFilterChain().add(new SmartParserFilter(MyMessage.class));
// Echo MyMessage
transport.getFilterChain().add(new EchoFilter());
-------------------------------- cut --------------------------------------
public class MyMessage {
public MyMessage(int a, int b) { this.a = a; this.b = b;}
public int a;
public int b;
}
35
36. 4.4 Example #1: Start the echo server
TCPNIOTransport transport =
TransportManager.instance().createTCPTransport();
transport.getFilterChain().add(new TransportFilter());
transport.getFilterChain().add(new EchoFilter());
try {
transport.bind(PORT);
transport.start();
-------------- wait until server is running ---------
} finally {
transport.stop();
TransportManager.instance().close();
}
36
38. 4.4 Example #3: EchoFilter
public class EchoFilter extends FilterAdapter {
@Override
public NextAction handleRead(FilterChainContext ctx,
NextAction nextAction) throws IOException {
Object message = ctx.getMessage();
ctx.getFilterChain().write(ctx.getConnection(), message);
return nextAction;
}
}
38
39. 5 Roadmap
â˘â1.8.6 was released 09/24
>â Biggest tested community release.
â˘â1.9.0 still discussed
>â Will include NIO.2 support
>â May include an http-client new module
ââDepends on the community
>â Last release for the 1.x branch.
â˘âRelease Grizzly 2 framework core: December 2008
â˘âRelease Grizzly 2 http module: February 2009
39
40. 6. Summary
â˘âProject Grizzly is a simple NIO Framework.
>â With less than 50 lines, you can create power client or
server side components.
>â Support Java NIO and NIO.2
>â Simple, but customizable.
â˘âGrizzly 2.0 will be better than the original! Better
API, same performance!
â˘âHealthy community: get a response in less than 2
hours :-)!
40
41. For More Information
â˘â Grizzly Activeâs Bloggers:
>â Alexey: http://blogs.sun.com/oleksiys/
>â Shing Wai: http://blogs.sun.com/swchan/
>â John: http://weblogs.java.net/blog/johnmann/
>â Sebastien: http://www2.sebastiendionne.ca
>â Jeanfrancois: http://weblogs.java.net/jfarcand
â˘â News:
>â Every week or so, a list of interesting blogs talking about us
http://www.nabble.com/forum/Search.jtp?forum=23249&local=y&query=News
â˘â Project Grizzly mailing lists,
>â dev@grizzly.dev.java.net & users@dev.grizzly.java.net
41