【问题标题】:Apache Ignite - Java Thin Client terminatedApache Ignite - Java 瘦客户端终止
【发布时间】:2020-06-21 05:26:47
【问题描述】:

我正在使用 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)

【问题讨论】:

  • 我猜是因为您在创建客户端时在这里使用了try-with-resources。您的客户端已自动关闭。请在 try-with-resources 块之外创建客户端实例。
  • 我试过了,但是样本结果。它在服务器端引发以下异常 - “无法处理选择器键”
  • 尝试从我下面的答案中检查代码。
  • 能否提供完整的例外情况?无法处理选择器键 - 当前消息应该与其他内容有关。

标签: java caching server ignite


【解决方案1】:

您是否尝试过以下代码:

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  

【讨论】:

【解决方案2】:

这看起来像是一个已知且已修复的问题 IGNITE-12032。请检查 2.8.0 版本(适用于 download on Apache Ignite website 和其他地方),看看它是否真的消失了。

【讨论】:

  • 我只使用 2.8.0
  • 我曾尝试在 2.8.0 中多次运行此代码,但从未收到此错误消息。请使用最少的复制器重新检查。
猜你喜欢
  • 2019-07-20
  • 2020-02-14
  • 2019-11-09
  • 2021-09-22
  • 2021-11-17
  • 2021-10-04
  • 2021-05-23
  • 2020-12-20
  • 2022-07-11
相关资源
最近更新 更多