class MessageGate extends ChannelDuplexHandler {

    @Override
    public void write( ChannelHandlerContext ctx, Object msg, ChannelPromise promise )
    {
        if ( !gated.test( msg ) )
        {
            ctx.write( msg, promise );
        }
        else if ( pending != null )
        {
            pending.add( new GatedWrite( msg, promise ) );
        }
        else
        {
            promise.setFailure( new RuntimeException( "Gate failed and has been permanently closed." ) );
        }
    }

    public  MessageGate( Predicate<Object> gated );

}