我正在使用apache ignite 2.8.0。
这是我用于将Java瘦客户端连接到服务器的代码,
ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
System.out.println("Thin client started.");
final String CACHE_NAME = "sample";
ClientCache<Integer, Object > cache = igniteClient.getOrCreateCache(CACHE_NAME);
cache.put(1,"JP");
System.out.println(cache.get(1));
} //main method
} //class
它会成功打印JP,但是之后我的瘦客户机被终止。
有什么办法可以使我的瘦客户机保持生命?
这是我的例外。
[21:48:34,942][SEVERE][grid-nio-worker-client-listener-0-#30][ClientListenerProcessor] Failed to process selector key [ses=GridSelectorNioSessionImpl [worker=ByteBufferNioClientWorker [readBuf=java.nio.HeapByteBuffer[pos=0 lim=8192 cap=8192], super=AbstractNioClientWorker [idx=0, bytesRcvd=0, bytesSent=0, bytesRcvd0=0, bytesSent0=0, select=true, super=GridWorker [name=grid-nio-worker-client-listener-0, igniteInstanceName=null, finished=false, heartbeatTs=1583770713875, hashCode=1387062740, interrupted=false, runner=grid-nio-worker-client-listener-0-#30]]], writeBuf=null, readBuf=null, inRecovery=null, outRecovery=null, closeSocket=true, outboundMessagesQueueSizeMetric=null, super=GridNioSessionImpl [locAddr=/127.0.0.1:10800, rmtAddr=/127.0.0.1:51279, createTime=1583770713811, closeTime=0, bytesSent=83, bytesRcvd=92, bytesSent0=83, bytesRcvd0=92, sndSchedTime=1583770713875, lastSndTime=1583770713875, lastRcvTime=1583770713875, readsPaused=false, filterChain=FilterChain[filters=[GridNioAsyncNotifyFilter, GridNioCodecFilter [parser=ClientListenerBufferedParser, directMode=false]], accepted=true, markedForClose=false]]]
java.io.IOException: An existing connection was forcibly closed by the remote host
at java.base/sun.nio.ch.SocketDispatcher.read0(Native Method)
at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:245)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358)
at org.apache.ignite.internal.util.nio.GridNioServer$ByteBufferNioClientWorker.processRead(GridNioServer.java:1162)
at org.apache.ignite.internal.util.nio.GridNioServer$AbstractNioClientWorker.processSelectedKeysOptimized(GridNioServer.java:2449)
at org.apache.ignite.internal.util.nio.GridNioServer$AbstractNioClientWorker.bodyInternal(GridNioServer.java:2216)
at org.apache.ignite.internal.util.nio.GridNioServer$AbstractNioClientWorker.body(GridNioServer.java:1857)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
at java.base/java.lang.Thread.run(Thread.java:834)
最佳答案
您是否尝试过以下代码:
ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
IgniteClient igniteClient = Ignition.startClient(cfg);
System.out.println("Thin client started.");
final String CACHE_NAME = "sample";
ClientCache<Integer, Object > cache = igniteClient.getOrCreateCache(CACHE_NAME);
cache.put(1,"JP");
System.out.println(cache.get(1));
//here your client will be alive