         self.handler = handler
         self.pipeline = pipeline
         self.eventLoop = pipeline.eventLoop
+        if let handler = handler as? _ChannelInboundHandler {
+            self.inboundHandler = handler
+        } else {
+            self.inboundHandler = nil
+        }
+        if let handler = handler as? _ChannelOutboundHandler {
+            self.outboundHandler = handler
+        } else {
+            self.outboundHandler = nil
+        }
     }
     
     public func fireChannelRegistered() {

        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")
        
        (handler as! _ChannelOutboundHandler).register(ctx: self, promise: promise)
    }
    
    func invokeBind(to address: SocketAddress, promise: Promise<Void>?) {
        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")

        (handler as! _ChannelOutboundHandler).bind(ctx: self, to: address, promise: promise)
    }
    
    func invokeConnect(to address: SocketAddress, promise: Promise<Void>?) {
        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")

        (handler as! _ChannelOutboundHandler).connect(ctx: self, to: address, promise: promise)
    }

    func invokeWrite(data: IOData, promise: Promise<Void>?) {
        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")

        (handler as! _ChannelOutboundHandler).write(ctx: self, data: data, promise: promise)
    }

    func invokeFlush(promise: Promise<Void>?) {
        assert(inEventLoop)
        
        (handler as! _ChannelOutboundHandler).flush(ctx: self, promise: promise)
    }
    
    func invokeWriteAndFlush(data: IOData, promise: Promise<Void>?) {

            let writePromise: Promise<Void> = eventLoop.newPromise()
            let flushPromise: Promise<Void> = eventLoop.newPromise()
            
            self.outboundHandler.write(ctx: self, data: data, promise: writePromise)
            self.outboundHandler.flush(ctx: self, promise: flushPromise)
            
            writePromise.futureResult.whenComplete(callback: callback)
            flushPromise.futureResult.whenComplete(callback: callback)
        } else {
            self.outboundHandler.write(ctx: self, data: data, promise: nil)
            self.outboundHandler.flush(ctx: self, promise: nil)
        }
    }
    
    func invokeRead(promise: Promise<Void>?) {
        assert(inEventLoop)
        
        self.outboundHandler.read(ctx: self, promise: promise)
    }
    
    func invokeClose(promise: Promise<Void>?) {
        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")

        self.outboundHandler.close(ctx: self, promise: promise)
    }
    
    func invokeTriggerUserOutboundEvent(event: Any, promise: Promise<Void>?) {
        assert(inEventLoop)
        assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled")
        
        self.outboundHandler.triggerUserOutboundEvent(ctx: self, event: event, promise: promise)
    }
    
    func invokeHandlerAdded() throws {
