草庐IT

Netty-NIO

全部标签

java - kafka.consumer.SimpleConsumer : Reconnect due to socket error: java. nio.channels.ClosedChannelException 异常

我正在为kafka运行一个简单的消费者,如下所示:inttimeout=80000;intbufferSize=64*1024;consumer=newSimpleConsumer(host,port,timeout,bufferSize,clientName);这可以正常运行几个小时,但出现异常稍后的kafka.consumer.SimpleConsumer:由于套接字错误重新连接:java.nio.channels.ClosedChannelException然后消费者停止......以前有人遇到过这个问题吗? 最佳答案 一个略

java.nio.文件.FileSystemException : The process cannot access the file because it is being used by another process

我正在编写一个程序,在第一次执行时将自己复制到特定文件夹,在linux或windows中工作。在linux中它工作得很好但是当我尝试在windows上做同样的事情时我得到以下错误:java.nio.file.FileSystemException:Theprocesscannotaccessthefilebecauseitisbeingusedbyanotherprocess(insun.nio.fs.WindowsException)那么,另一个进程是程序本身,我应该用什么来跳过这个错误呢?我的代码行是:publicvoidinstallProgram(){System.out.pr

java.nio.channels.ClosedChannelException

我该如何解决这个问题。我收到以下错误:java.nio.channels.ClosedChannelException这是编码:publicvoidrun(){try{SocketChannelsocketChannel=(SocketChannel)key.channel();ByteBufferbuffer=ByteBuffer.allocate(512);inti1=socketChannel.read(buffer);if(buffer.limit()==0||i1==-1){Sockets=null;try{s=socketChannel.socket();s.close()

java - 如何使用 netty 客户端获取服务器响应

我想写一个基于netty的客户端。它应该有方法publicStringsend(Stringmsg);应该从服务器或将来返回响应-没关系。它也应该是多线程的。像这样:publicclassClient{publicstaticvoidmain(String[]args)throwsInterruptedException{Clientclient=newClient();}privateChannelchannel;publicClient()throwsInterruptedException{EventLoopGrouploopGroup=newNioEventLoopGroup(

java - 如何在类路径中修复 "Found Netty' 的 native epoll 传输,但 epoll 不可用。使用 NIO 代替“警告?

我正在使用Cassandra,在启动期间,Netty会打印一strip有堆栈跟踪的警告:FoundNetty'snativeepolltransportintheclasspath,butepollisnotavailable.UsingNIOinstead."应用程序运行正常,但有没有办法修复警告?这是完整的堆栈跟踪:16:29:46WARNcom.datastax.driver.core.NettyUtil-FoundNetty'snativeepolltransportintheclasspath,butepollisnotavailable.UsingNIOinstead.ja

Java nio : How to add extension to an absolute path?

这感觉应该是直截了当的事情,但我似乎可以找到一个优雅的解决方案,而无需转换为File。给定一个路径Pathpath=Paths.get("/a/b/foo")如何获取路径/a/b/foo.bar?subpath将返回相对路径,无论原始路径是相对路径还是绝对路径。我宁愿不必使用额外的库。但是,也许这是唯一的方法? 最佳答案 要更改Path的文件名,请使用resolveSibling()之一方法:Thisisusefulwhereafilenameneedstobereplacedwithanotherfilename.使用此方法可确保

java - 为什么 'File.exists' 返回 true,即使 NIO 'Files.exists' 类中的 'Files' 返回 false

我正在尝试确定文件是否存在于网络文件夹中://Filenameis"\\QWERTY\folder\dir\A123456.TXT"Pathpath=Paths.get("\\\\QWERTY\\folder\\dir\\A123456.TXT")使用NIO文件:Files.exists(path)==false使用文件:path.toFile().exists()==true根据我们的测试,使用File似乎是正确的。为什么File比Files更好用?那么,它是什么?不能两者兼而有之!等等,还有Files.notExists(path)。当网络共享文件实际存在时Files.exists

java - Netty + ProtoBuffer : A few communication messages for one connection

在阅读Netty教程时,我发现了一个简单的description如何集成Netty和GoogleProtocolBuffers.我已经开始研究它的示例(因为文档中没有更多信息)并编写了一个简单的应用程序,如示例本地时间应用程序。但是这个例子是在PipeFactory类中使​​用静态初始化,例如:importorg.jboss.netty.channel.ChannelPipeline;importorg.jboss.netty.channel.ChannelPipelineFactory;importorg.jboss.netty.handler.codec.protobuf.Prot

带有通配符的 Java 7 nio 列表目录

我想使用通配符在目录中查找文件。我在Java6中有这个,但想将代码转换为Java7NIO:Filedir=newFile(mydir);FileFilterfileFilter=newWildcardFileFilter(identifier+".*");File[]files=dir.listFiles(fileFilter);没有WildcardFileFilter,我已经尝试了一些globs。 最佳答案 您可以将glob传递给DirectoryStreamimportjava.nio.file.DirectoryStream;

java - 以编程方式关闭 netty

我正在使用netty4.0.24.Final。我需要以编程方式启动/停止netty服务器。在启动服务器时,线程被阻塞在f.channel().closeFuture().sync()请提供一些正确操作的提示。下面是主类调用的EchoServer。谢谢。packagenettytests;importio.netty.bootstrap.ServerBootstrap;importio.netty.channel.ChannelFuture;importio.netty.channel.ChannelInitializer;importio.netty.channel.ChannelOp