Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从Infinispan缓存读取数据进入无限循环_Java_Groovy_Apache Nifi_Infinispan - Fatal编程技术网

Java 从Infinispan缓存读取数据进入无限循环

Java 从Infinispan缓存读取数据进入无限循环,java,groovy,apache-nifi,infinispan,Java,Groovy,Apache Nifi,Infinispan,我正在使用Nifi创建数据流管道,在这里我使用Infinispan作为缓存服务器,但当我使用带有Groovy脚本的executescript时,它会无限循环并打开许多套接字连接。我试图关闭相同的,但它仍然打开了许多连接,然后抛出 java.net.SocketException: No buffer space available (maximum connections reached?): connect 通过以下链接,我更改了注册表 然后使用netstat-nI检查打开的连接,由于上述

我正在使用Nifi创建数据流管道,在这里我使用Infinispan作为缓存服务器,但当我使用带有Groovy脚本的executescript时,它会无限循环并打开许多套接字连接。我试图关闭相同的,但它仍然打开了许多连接,然后抛出

java.net.SocketException: No buffer space available (maximum connections reached?): connect
通过以下链接,我更改了注册表

然后使用
netstat-n
I检查打开的连接,由于上述设置,我打开65534

下面是从Infinispan缓存读取的groovy脚本

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.apache.commons.io.IOUtils;
import java.nio.charset.StandardCharsets;

def cacheName = "mycache"

def configuration = new ConfigurationBuilder()
.addServer().host("localhost").port(11322).build();

def cacheManager = new RemoteCacheManager(configuration)

RemoteCache cacheA = cacheManager.getCache(cacheName)

flowFile = session.get()
if(!flowFile) return
key = flowFile.getAttribute('key')
id = flowFile.getAttribute('id')
jsonFromCache = cacheA.get(key + "_" + id);
if(cacheA != null) {
cacheA.stop()
}
if(cacheManager != null) {
cacheManager.stop()
}

flowFile = session.write(flowFile, {outputStream ->
  outputStream.write(jsonFromCache.getBytes(StandardCharsets.UTF_8))
} as OutputStreamCallback)
session.transfer(flowFile, REL_SUCCESS)

在从会话获取文件之前,您正在打开到缓存的连接

因此,您正在打开连接,在下面的一行中,只退出脚本而不关闭它:

if(!flowFile) return
另一点: 您可以使用ExecuteGroovyScript处理器。然后可以管理处理器的启动和停止。您可以在此处找到示例:

import org.apache.nifi.processor.ProcessContext
导入java.util.concurrent.AtomicLong
类常数{
静态日期开始时间=空;
静态AtomicLong triggerCount=null;
}
静态onStart(ProcessContext上下文){
Const.startTime=新日期()
Const.triggerCount=new AtomicLong(0)
println“onStart$context${Const.startTime}”
}
静态桌面(ProcessContext上下文){
def alive=(System.currentTimeMillis()-Const.startTime.getTime())/1000
println“onStop$context在${alive}秒内执行${Const.triggerCount}次”
}
def flowFile=session.get()
如果(!flowFile)返回
flowFile.trigger.count'=Const.triggerCount.incrementAndGet()

REL_SUCCESS在从会话获取文件之前,您正在打开与缓存的连接

因此,您正在打开连接,在下面的一行中,只退出脚本而不关闭它:

if(!flowFile) return
另一点: 您可以使用ExecuteGroovyScript处理器。然后可以管理处理器的启动和停止。您可以在此处找到示例:

import org.apache.nifi.processor.ProcessContext
导入java.util.concurrent.AtomicLong
类常数{
静态日期开始时间=空;
静态AtomicLong triggerCount=null;
}
静态onStart(ProcessContext上下文){
Const.startTime=新日期()
Const.triggerCount=new AtomicLong(0)
println“onStart$context${Const.startTime}”
}
静态桌面(ProcessContext上下文){
def alive=(System.currentTimeMillis()-Const.startTime.getTime())/1000
println“onStop$context在${alive}秒内执行${Const.triggerCount}次”
}
def flowFile=session.get()
如果(!flowFile)返回
flowFile.trigger.count'=Const.triggerCount.incrementAndGet()

你试过finispan吗?(对不起……我忍不住。)@user2478398我的问题有什么不对吗?绝对没有。我只是不成熟(因此抱歉)。如果我对这里的任何库都足够了解,能够提供帮助,我会的,但恐怕我不知道。在从会话获取文件之前,您正在打开与缓存的连接。您正在打开连接,在这一行只退出脚本而不关闭它:
如果(!flowFile)返回
顺便说一句,可以处理处理器的启动和停止,以便每个处理器进行一次缓存连接。您尝试过finispan吗?(对不起……我忍不住。)@user2478398我的问题有什么不对吗?绝对没有。我只是不成熟(因此抱歉)。如果我对这里的任何库都足够了解,能够提供帮助,我会的,但恐怕我不知道。在从会话获取文件之前,您正在打开与缓存的连接。您正在打开连接,在这一行只退出脚本而不关闭它:
如果(!flowFile)返回
顺便说一句,可以处理处理器的启动和停止,以便每个处理器进行一次缓存连接。