Presentation is loading. Please wait.

Presentation is loading. Please wait.

Grizzly 2.0 Initial propose overview

Similar presentations


Presentation on theme: "Grizzly 2.0 Initial propose overview"— Presentation transcript:

1 Grizzly 2.0 Initial propose overview
Oleksiy Stashok 1

2 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

3 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

4 1. Grizzly 2.0 goals Make framework core API more clear and useful, based on earlier experience 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 Thread pool abstractions, provided by JDK.

5 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

6 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

7 2.1 Grizzly 1.x architecture solutions to be changed
Split different transports logic, as it makes mess No Controller NIO Transport <-1 : 1-> SelectorHandler <-1 : 1-> SelectionKeyHandler. No copies, no clones. Unify SelectionKey events processing: client and server side connections will be processed the same way Unify SelectionKey attachments

8 2.1 Grizzly 1.x architecture solutions to be changed (cont.)
ConnectorHandler will be responsible just for client ”connect” phase.

9 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

10 2.2.1 Transport Represents one specific transport implementation
Configuration Thread pool Memory/ByteBuffer manager Connection IO events processing logic Life-cycle control: start, pause, resume, stop

11 2.2.2 Connection Represents connection unit in Grizzly, both server and client side Implements basic IO operations: read, write, close Hides protocol specifics, NIO complexity Could be used to store connection state/attributes

12 2.2.3 IOEventProcessor Common interface for processing IO events, occurred on the connection CallbackHandler and ProtocolChain implement IOEventProcessor It's easy to write custom IOEventProcessor: public void process(IOEventContext context) throws IOException;

13 2.2.4 IOEventProcessorSelector
Incapsulates logic for selecting appropriate IOEventProcessor(s) to process specific IO event Is associated with Transport, although each specific connection unit, can have its own selector, which has higher priority public boolean injectEventProcessors(int connectionOp, Connection connection, IOEventProcessorChain eventProcessorChain);

14 2.2.5 MemoryManager Manages memory allocation, release operations
Associated with a Transport Default implementations: ByteBufferManager, ByteBufferViewManager public interface MemoryManager<E> { public E allocate(int size); public E reallocate(E oldBuffer, int newSize); public void release(E buffer); }

15 2.2.6 ThreadPool Currently its API was taken from Grizzly 1.x
Associated with a Transport Needs to be compatible with JDK ThreadPool?

16 2.2.7 Attribute Typed Attribute implementation (proposed by Ken)
Compile time attribute types check Example: Attribute<Integer> lengthAttr; AttributeHolder session; public void setLength(int length) { lengthAttr.set(session, length); } public int getLength() { return lengthAttr.get(session);

17 Agenda Grizzly 2.0 goals Architecture
Grizzly 1.x architecture solutions to be changed Abstractions overview Examples

18 3.1 Start and stop the Transport
TCPNIOTransport transport = new TCPNIOTransport(); try { transport.bind(7777); transport.start(); } finally { transport.stop(); }

19 3.2 Blocking client write TCPNIOConnectorHandler connectorHandler =
new TCPNIOConnectorHandler(transport); try { IOFuture<NIOConnection> future = connectorHandler.connectAsync("localhost", 7777); NIOConnection connection = future.get(10, TimeUnit.SECONDS); connection.write(someBuffer); } finally { connectorHandler.close(); }

20 3.3 Async client write TCPNIOConnectorHandler connectorHandler =
new TCPNIOConnectorHandler(transport); IOFuture writeFuture = connection.writeAsync(someBuffer); WriteResult writeResult = writeFuture.get(10, TimeUnit.SECONDS);

21 3.4 Filter chain write public class CustomFilter extends AbstractFilter { public boolean execute(IOEventContext ctx) throws IOException { ByteBuffer response = getResponse(); // Filter's filterWrite performs some Filter specific // response transformation and call filterWrite // on previous Filter in chain until it comes to // TransportFilter, which will send response on a wire IOFuture future = filterWriteAsync(ctx, response); }

22 3.5 Filter chain write (cont.)
public class CustomFilter extends AbstractFilter { public boolean execute(IOEventContext ctx) throws IOException { ByteBuffer response = getResponse(); // It's possible to send response directly on a wire IOFuture future = ctx.getConnection().writeAsync(response); }

23 Grizzly 2.0 Initial propose overview
23


Download ppt "Grizzly 2.0 Initial propose overview"

Similar presentations


Ads by Google