我正在尝试学习 netty 通道处理程序,并且我在本教程中遇到了困难。
在文件中NettyServer.java,作者提到了将通道处理程序注册到通道管道。
ch.pipeline().addLast(
new RequestDecoder(),
new ResponseDataEncoder(),
new ProcessingHandler());
Run Code Online (Sandbox Code Playgroud)
这个顺序让我有点困惑。我会按如下方式注册订单
响应被解码是正确的顺序。
ch.pipeline().addLast(
new RequestDecoder(),
new ProcessingHandler(),
new ResponseDataEncoder());
Run Code Online (Sandbox Code Playgroud)Netty 中不同排序背后的原因是什么?
我正在尝试使用 netty 4.1.16.Final 创建简单的 HTTP 服务器。
以下是 HTTP 服务器的代码 -
EventLoopGroup masterGroup = new NioEventLoopGroup();
EventLoopGroup slaveGroup = new NioEventLoopGroup();
final ServerBootstrap bootstrap =
new ServerBootstrap()
.group(masterGroup, slaveGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast("codec", new HttpServerCodec());
ch.pipeline().addLast("aggregator",
new HttpObjectAggregator(512 * 1024));
ch.pipeline().addLast("request",
new HTTPSimpleChannelInboundHandler());
}
}).option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
channel = bootstrap.bind(8080).sync();
Run Code Online (Sandbox Code Playgroud)
HTTP 处理程序类的代码HTTPSimpleChannelInboundHandler如下 -
public class HTTPSimpleChannelInboundHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
HttpResponseStatus responseStatus = OK;
FullHttpResponse …Run Code Online (Sandbox Code Playgroud) 我有下面的代码
ThreadLocal<Map<String, Service<Request, Response>>> connectinonMapThread = new ThreadLocal<Map<String, Service<Request, Response>>>() {
@Override
protected Map<String, Service<Request, Response>> initialValue() {
return new HashMap<String, Service<Request, Response>>();
}
};
Run Code Online (Sandbox Code Playgroud)
我想使用 lambda 表达式来编写它,如下所示 -
ThreadLocal<Map<String, Service<Request, Response>>> connectinonMapThread2 = new ThreadLocal<Map<String, Service<Request, Response>>>(() -> new HashMap<String, Service<Request, Response>>());
Run Code Online (Sandbox Code Playgroud)
我尝试了另一种。
ThreadLocal<Map<String, Service<Request, Response>>> connectinonMapThread2 = initialValue() -> {
return new HashMap<String, Service<Request, Response>>();
};
Run Code Online (Sandbox Code Playgroud)
但我收到编译错误。但 IntelliJ Idea 建议这可以写成 lambda 表达式。
我写了下面的包装类Int.
case class Wrapper[Int](value: Int) {
def map(f: Int => Int): Wrapper[Int] = Wrapper(f(value))
def flatMap(f: Int => Wrapper[Int]): Wrapper[Int] = f(value)
def filter(f: Int => Boolean): Wrapper[Int] = Wrapper(if(f(value)) 0 else value)
}
Run Code Online (Sandbox Code Playgroud)
当我编译代码时,我得到以下错误 -
type mismatch;
[error] found : Int(0)
[error] required: Int
[error] def filter(f: Int => Boolean): Wrapper[Int] = Wrapper(if (f(value)) 0 else value)
[error] ^
[error] one error found
Run Code Online (Sandbox Code Playgroud)
我找不到任何明显的错误原因.任何想法如何解决这个问题.
程序的许多方法作为参数接收List [Map [String,String]].
我想通过定义一个类来形式化它并使其更具可读性,例如:
class MyClass extends List[Map[String, String]]
Run Code Online (Sandbox Code Playgroud)
但是它会抛出一个错误:
Illegal inheritance from sealed class 'List'
Run Code Online (Sandbox Code Playgroud)
有没有正确的方法来处理它?
我正在学习Rust,并按照教程进行一些小练习。
当我使用编译和构建时rustc,它会生成一个可执行文件。
我只想.rs在project / chapter1,Chapter2等目录下添加文件,而忽略该rustc命令生成的可执行文件。
我不知道该怎么做,因为Rust生成的可执行文件没有任何扩展名。
如何使用.gitignore忽略这些可执行文件?
我在做下面的运动。
创建一个包含四个元素的切片。创建一个新的切片,并将第三个和第四个元素仅复制到其中。
我已经返回了以下程序
package main
import "fmt"
func main() {
var elements = make([]string, 4)
elements[0] = "1"
elements[1] = "2"
elements[2] = "3"
elements[3] = "4"
fmt.Println(elements)
var newElements = make([]string, 2)
newElements = append(elements[:0], elements[:2]...)
fmt.Println(newElements)
}
Run Code Online (Sandbox Code Playgroud)
我程序的输出是。但我希望newElements切片为[3 4]-
[1 2 3 4]
[1 2]
Run Code Online (Sandbox Code Playgroud)
我的程序出了什么问题。
我是一名新的 Go 语言程序员。以下是我的程序,但我收到此错误:
#command-line-arguments
.\helloworld.go:20: undefined: json.Marshall
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么会收到错误?
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type API struct {
Message string "json:message"
}
func main() {
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
message := API{"Hello, World!!!"}
output, err := json.Marshall(message)
if err != nil {
fmt.Println("Something went wrong")
}
fmt.Fprintf(w, string(output))
})
http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud) 我今天才刚刚开始编码Haskell,停留在构建函数上,该函数从用户那里获取一个整数,将其乘以3,加一并检查它是否为Even。返回输出为布尔值,如果为偶数则返回true。抱歉,如果代码错误,我是Haskell新手。
checkIfEven :: Int -> Bool
x <- readLn
let checkIfEven x = (even ((x*3)+1))
print checkIfEven
error:
Variable not in scope: checkIfEven :: Int -> Bool
Run Code Online (Sandbox Code Playgroud) 我目前正在从事一个项目,并且不断收到错误消息。我被困住了并且已经联系了很多人(包括我的教练),现在我已经转向你们。
到目前为止,这是我的代码。
public class Circle
private int radius = getRadius();
private double area = getArea();
public Circle(int r)
{
r = radius;
}
public int getRadius()
{
return radius;
}
public double getArea(int r)
{
return area = Math.PI * r * r;
}
}
Run Code Online (Sandbox Code Playgroud)
/
java.util.Scanner;
public class CircleTest
{
public CircleTest()
{
int radius = getRadius();
double area = getArea(r);
}
public static void main (String[] args)
{
Scanner kboard = new Scanner(System.in);
System.out.print("Give the radius of a …Run Code Online (Sandbox Code Playgroud)