使用Scala关闭Drools Kiesession时数据丢失

时间:2018-07-16 10:30:59

标签: scala drools kie

我有一个应用程序,该应用程序是用KieSession状态满对象创建的,并处理规则,并将结果生成到Iterator中。但是,当我处理完同分会话后尝试返回结果时,我遇到了问题。

def ruleExucetion[T](originalData: Iterator[T], drtFile: String ): Iterator[T] = {
 val kSession = getKieSession(drtFile)
 val processedData = getDataModels(kSession, originalData)
 // processedData.size ==> printing the value, but after dispose function, I lost the Iterator data.
 kSession.dispose()
 return processedData
}

在这里,我如何处置/关闭连接而不会丢失processedData。我们可以为上面的Iterator设置(scala)紧急加载吗?

已编辑:

def getDataModels[T](kSession: KieSession, originalData: Iterator[T]): Iterator[T] = {
   val dataModels = originalData.map(dataModel => {
   kSession.insert(dataModel)
   dataModel
  })
  kSession.fireAllRules()
  return dataModels
}

下面是错误放样跟踪:-

ERROR ApplicationMaster: User class threw exception:       java.lang.IllegalStateException: Illegal method call. This session was previously disposed.
java.lang.IllegalStateException: Illegal method call. This session was previously disposed.
at org.drools.core.impl.StatefulKnowledgeSessionImpl.checkAlive(StatefulKnowledgeSessionImpl.java:1255)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1493)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1454)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1448)
at com.giri.rules.Run$$anonfun$1.apply(Run.scala:36)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
at scala.collection.Iterator$class.foreach(Iterator.scala:893)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
at scala.collection.TraversableOnce$class.size(TraversableOnce.scala:107)
at scala.collection.AbstractIterator.size(Iterator.scala:1336)

0 个答案:

没有答案