标签: pipeline

如何决定Netty通道管道中的操作顺序

例如,如果我想构建一个websocket服务器,我想知道该initChannel方法中应该放什么。然后我在netty的源码中找到了websocket示例,其中我需要执行以下操作:

public void initChannel(final SocketChannel ch) throws Exception {
                ch.pipeline().addLast(
                    new HttpRequestDecoder(),
                    new HttpObjectAggregator(65536),
                    new HttpResponseEncoder(),
                    new WebSocketServerProtocolHandler("/websocket"),
                    new CustomTextFrameHandler());
            }
Run Code Online (Sandbox Code Playgroud)

但我不知道为什么需要按这样的顺序放置对象。在描述中HttpObjectAggregator我发现了这样的内容:

Be aware that you need to have the {@link HttpResponseEncoder} or {@link HttpRequestEncoder} before the {@link HttpObjectAggregator} in the {@link ChannelPipeline}.

但在上面的代码中,HttpObjectAggregator对象位于HttpResponseEncoder对象之前。我很困惑。我怎么知道我正在以正确的顺序放置这些对象?

pipeline websocket netty

0
推荐指数
1
解决办法
763
查看次数

Elixir Enum.map 通过管道传输到 Enum.filter 不起作用

我正在尝试编写一个工具,该工具将从 中获取文件/文件夹列表File.ls,添加它们的完整路径,并根据它们是否是目录来过滤它们。

这有效:

directory_contents = File.ls!(directory_path)

contents_with_full_paths = Enum.map directory_contents, fn(item) -> Path.join(directory_path, item) end
only_dirs = Enum.filter contents_with_full_paths, fn(item) -> File.dir?(item) end
Run Code Online (Sandbox Code Playgroud)

这不会:

directory_contents = File.ls!(directory_path)

directory_contents
|> Enum.map fn(item) -> Path.join(directory_path, item) end
|> Enum.filter fn(item) -> File.dir?(item) end
Run Code Online (Sandbox Code Playgroud)

它抛出

** (Protocol.UndefinedError) protocol Enumerable not implemented for #Function<1.10194857/1 in RepoFinder.subdirectories_in/1>, only anonymous functions of arity 2 are enumerable. This protocol is implemented for: Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream
    (elixir) …
Run Code Online (Sandbox Code Playgroud)

pipeline enumerable elixir

0
推荐指数
1
解决办法
757
查看次数

Python:使用 join 和 lambda 进行补充

我正在尝试创建将数字转换为其 Ones 的补数的管道,例如 (8)

1234 -> 7654

83743 -> 05145

我试图以这种风格创建一些东西,但我无法弄清楚如何正确构建管道。

int(''.join((my_number(lambda y: 8-y, list(my_number)))))
Run Code Online (Sandbox Code Playgroud)

错误

类型错误:“int”对象不可调用

python lambda pipeline join ones-complement

0
推荐指数
1
解决办法
48
查看次数

Python 将多个函数链接到一个函数中

我有几个字符串处理函数,例如:

def func1(s):
    return re.sub(r'\s', "", s)

def func2(s):
    return f"[{s}]"
...
Run Code Online (Sandbox Code Playgroud)

我想将它们组合成一个管道函数:my_pipeline(),以便我可以将其用作参数,例如:

class Record:
    def __init__(self, s):
        self.name = s
    
    def apply_func(self, func):
        return func(self.name)

rec = Record(" hell o")
output = rec.apply_func(my_pipeline)
# output = "[hello]"
Run Code Online (Sandbox Code Playgroud)

目标是用作my_pipeline参数,否则我需要一一调用这些函数。

谢谢。

python pipeline function chain

0
推荐指数
1
解决办法
595
查看次数

在脚本块的 Jenkinsfile 中使用 def 和不使用 def 有什么区别?

我有两个 Jenkinsfile 作为示例: A_Jenkinsfile 的内容是:

pipeline {
    agent any
    stages {
        stage("first") {
            steps {
                script {
                 foo = "bar"
                }
            sh "echo ${foo}"
            }
        }
        stage("two") {
            steps {
            sh "echo ${foo}"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

另外一个是B_Jenkinsfile,其内容是:

pipeline {
    agent any
    stages {
        stage("first") {
            steps {
                script {
                 def foo = "bar"
                }
            sh "echo ${foo}"
            }
        }
        stage("two") {
            steps {
            sh "echo ${foo}"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我构建它们时,B_Jenkinsfile 失败,A_Jenkinsfile 成功。

在脚本块的 Jenkinsfile 中使用 def 和不使用 def …

pipeline jenkins jenkins-pipeline

0
推荐指数
1
解决办法
677
查看次数

这两个指针声明有什么区别?

这些声明是不同的还是产生相同的结果?

char * const *argv;
Run Code Online (Sandbox Code Playgroud)

const char **argv;
Run Code Online (Sandbox Code Playgroud)

是否存在差异或指针指针?

背景是我正在编写一个C命令行shell并将此结构用于命令:

struct command
{
    char * const *argv;
};
Run Code Online (Sandbox Code Playgroud)

上面的结构用于调用exec.现在,当我查看另一个问题时,结构是不同的:

用shell中的管道连接n个命令?

在那个问题中,实现相同的结构是不同的.

c posix pipeline

-4
推荐指数
1
解决办法
88
查看次数