@Override
        public void register(EventLoop eventLoop, ChannelPromise promise) {
            // Register
            if (!(eventLoop instanceof NioEventLoop)) {
                throw new IllegalArgumentException("Only valid for NioEventLoop!");
            }
            if (!(promise.channel() instanceof SerialChannel)) {
                throw new IllegalArgumentException("Only valid for " + SerialChannel.class + " but is " + promise.channel().getClass());
            }
            // Register channel to event loop
            // We have to use reflection here, I fear
            try {
                Method method = NioEventLoop.class.getDeclaredMethod("unwrappedSelector");
                method.setAccessible(true);
                SerialPollingSelector selector = (SerialPollingSelector) method.invoke(eventLoop);

                // Register the channel
                serialSelectionKey = (SerialSelectionKey) ((SerialChannel) promise.channel()).javaChannel().register(selector, 0, SerialChannel.this);

                // Set selection key
                final Field selectionKeyField = AbstractNioChannel.class.getDeclaredField("selectionKey");
                selectionKeyField.setAccessible(true);
                selectionKeyField.set(SerialChannel.this, serialSelectionKey);

                // Set event loop (again, via reflection)
                final Field loop = AbstractChannel.class.getDeclaredField("eventLoop");
                loop.setAccessible(true);
                loop.set(SerialChannel.this, eventLoop);

                // Register Pipeline, if necessary
                // Ensure we call handlerAdded(...) before we actually notify the promise. This is needed as the
                // user may already fire events through the pipeline in the ChannelFutureListener.
                if (!(pipeline() instanceof DefaultChannelPipeline)) {
                    throw new IllegalStateException("Pipeline should be of Type " + DefaultChannelPipeline.class);
                }
                // Again reflection, but has to be done in an event loop
                eventLoop().execute(() -> {
                    try {
                        final Method invokeHandlerAddedIfNeeded = DefaultChannelPipeline.class.getDeclaredMethod("invokeHandlerAddedIfNeeded");
                        invokeHandlerAddedIfNeeded.setAccessible(true);

                        invokeHandlerAddedIfNeeded.invoke(pipeline());

                        pipeline().fireChannelRegistered();
                    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                        logger.warn("Exception caught", e);
                    }
                });

                // Return promise
                promise.setSuccess();
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClosedChannelException | NoSuchFieldException e) {
                logger.warn("Exception caught", e);
                throw new NotImplementedException("Should register channel to event loop!!!");
            }
        }
Create a new instance

@param parent the parent {@link Channel} by which this instance was created. May be {@code null}
@param ch     the underlying {@link SelectableChannel} on which it operates
plc4j/transports/serial/src/main/java/org/apache/plc4x/java/transport/serial/SerialChannel.java