Search in sources :

Example 1 with CodecRegistry

use of com.robo4j.socket.http.units.CodecRegistry in project robo4j by Robo4J.

the class InboundHttpSocketChannelHandler method initSocketChannel.

private void initSocketChannel(ServerContext serverContext) {
    socketChannel = ChannelUtils.initServerSocketChannel(serverContext);
    final SelectionKey key = ChannelUtils.registerSelectionKey(socketChannel);
    final CodecRegistry codecRegistry = serverContext.getPropertySafe(CodecRegistry.class, PROPERTY_CODEC_REGISTRY);
    final int bufferCapacity = serverContext.getPropertySafe(Integer.class, PROPERTY_BUFFER_CAPACITY);
    while (active) {
        int channelReady = ChannelUtils.getReadyChannelBySelectionKey(key);
        if (channelReady == 0) {
            continue;
        }
        Set<SelectionKey> selectedKeys = key.selector().selectedKeys();
        Iterator<SelectionKey> selectedIterator = selectedKeys.iterator();
        while (selectedIterator.hasNext()) {
            final SelectionKey selectedKey = selectedIterator.next();
            selectedIterator.remove();
            if (selectedKey.isAcceptable()) {
                handleSelectorHandler(new AcceptSelectionKeyHandler(selectedKey, bufferCapacity));
            } else if (selectedKey.isConnectable()) {
                handleSelectorHandler(new ConnectSelectionKeyHandler(selectedKey));
            } else if (selectedKey.isReadable()) {
                handleSelectorHandler(new ReadSelectionKeyHandler(context, serverContext, codecRegistry, outBuffers, selectedKey));
            } else if (selectedKey.isWritable()) {
                handleSelectorHandler(new WriteSelectionKeyHandler(context, serverContext, outBuffers, selectedKey));
            }
        }
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) CodecRegistry(com.robo4j.socket.http.units.CodecRegistry)

Aggregations

CodecRegistry (com.robo4j.socket.http.units.CodecRegistry)1 SelectionKey (java.nio.channels.SelectionKey)1