我准备用grizzly做一个高并发的TCP程序,我使用的是grizzly-nio-framework-1.9.9.jar的包!服务端的代码如下:
final Controller controller = new Controller();
final ReadFilter readFilter = new ReadFilter();
final LogFilter logFilter = new LogFilter();
controller.setProtocolChainInstanceHandler(new DefaultProtocolChainInstanceHandler() {
public ProtocolChain poll() {
ProtocolChain protocolChain = (ProtocolChain)protocolChains
.poll();
if (protocolChain == null) {
protocolChain = new DefaultProtocolChain();
protocolChain.addFilter(readFilter);
protocolChain.addFilter(logFilter);
}
return protocolChain;
}
});
controller.start();
此服务端启动后我用TCP工具模拟客户端连接没有问题(没有发送数据),当往此通道中发送数据时就会报错,报错信息如下:
java.lang.NullPointerException
at com.sun.grizzly.filter.ReadFilter.execute(ReadFilter.java:124)
at com.sun.grizzly.filter.ReadFilter.execute(ReadFilter.java:100)
也就是ReadFilter类中的这一段代码:
if (byteBuffer == null) {
byteBuffer = ((WorkerThread)Thread.currentThread()).getByteBuffer();
}
if (!byteBuffer.hasRemaining()){
throw new IllegalStateException("ByteBuffer is full: " + byteBuffer);
}
"if (!byteBuffer.hasRemaining())" 错误指向的是这句话,也就是说byteBuffer此时为null
以上服务端的代码我都是按照grizzly的API文档上面写的,就是搞不清楚到底是怎么回事?小弟刚开始研究grizzly,希望JE的各位大虾们帮助解决一下!谢谢先!
final Controller controller = new Controller();
final ReadFilter readFilter = new ReadFilter();
final LogFilter logFilter = new LogFilter();
controller.setProtocolChainInstanceHandler(new DefaultProtocolChainInstanceHandler() {
public ProtocolChain poll() {
ProtocolChain protocolChain = (ProtocolChain)protocolChains
.poll();
if (protocolChain == null) {
protocolChain = new DefaultProtocolChain();
protocolChain.addFilter(readFilter);
protocolChain.addFilter(logFilter);
}
return protocolChain;
}
});
controller.start();
此服务端启动后我用TCP工具模拟客户端连接没有问题(没有发送数据),当往此通道中发送数据时就会报错,报错信息如下:
java.lang.NullPointerException
at com.sun.grizzly.filter.ReadFilter.execute(ReadFilter.java:124)
at com.sun.grizzly.filter.ReadFilter.execute(ReadFilter.java:100)
也就是ReadFilter类中的这一段代码:
if (byteBuffer == null) {
byteBuffer = ((WorkerThread)Thread.currentThread()).getByteBuffer();
}
if (!byteBuffer.hasRemaining()){
throw new IllegalStateException("ByteBuffer is full: " + byteBuffer);
}
"if (!byteBuffer.hasRemaining())" 错误指向的是这句话,也就是说byteBuffer此时为null
以上服务端的代码我都是按照grizzly的API文档上面写的,就是搞不清楚到底是怎么回事?小弟刚开始研究grizzly,希望JE的各位大虾们帮助解决一下!谢谢先!