简体   繁体   English

在Java EE Web应用程序中使用JPL(Java + Prolog)

[英]Using JPL (Java + Prolog) in a Java EE web application

I would like to develop a Java EE web application that requires Prolog, via JPL, for certain search related tasks. 我想开发一个Java EE Web应用程序,该应用程序需要通过JPL的Prolog来完成某些与搜索有关的任务。 The web application will be deployed in the JBoss application server. 该Web应用程序将部署在JBoss应用程序服务器中。 The Prolog engine can be either YAP or SWI (afaik the only Prolog engines compatible with JPL at the moment). Prolog引擎可以是YAP或SWI(afaik是目前唯一与JPL兼容的Prolog引擎)。 The Prolog queries depend on information stored in a (potentially large) database. Prolog查询取决于存储在(可能很大)数据库中的信息。

If someone has tried this or something similar, could you please give me feedback about the following questions?: 如果有人尝试过此方法或类似方法,能否请您对以下问题给我反馈?:

  • What is the best way to manage concurrent http sessions that need access to the Prolog engine?. 管理需要访问Prolog引擎的并发http会话的最佳方法是什么? Is it possible -desirable?- to assign to each separate session its own Prolog engine ?. 是否有可能-希望为每个单独的会话分配自己的Prolog引擎? If this solution works, is it possible to implement something similar to a 'Prolog engine pooling' to quickly assign prolog engines to new sessions ? 如果该解决方案有效,是否有可能实现类似于“ Prolog引擎池”的功能以快速将Prolog引擎分配给新会话? . Or the best solution is to have a single Prolog engine that will manage all the query requests synchronously ? 还是最好的解决方案是拥有单个Prolog引擎,该引擎将同步管理所有查询请求? (and slowly). (然后慢慢地)。
  • How could be managed the interaction of Prolog with the database ?. 如何管理Prolog与数据库的交互? If the data is changing often in the database and Prolog needs this data to solve its queries, what is the best strategy to keep the facts in the Prolog engine synchronized with the data in the database ?. 如果数据库中的数据经常更改,并且Prolog需要此数据来解决其查询,那么使Prolog引擎中的事实与数据库中的数据保持同步的最佳策略是什么? The navy option of starting from scratch at each new session (eg, reloading all the data from the database as Prolog facts) does not seem to be a good idea if the database grows large. 如果数据库变大,那么在每个新会话中从头开始的明智选择(例如,从Prolog事实中重新加载数据库中的所有数据)似乎不是一个好主意。
  • Any other expected issues/difficulties related to the java-prolog-database interaction during the implementation ? 在实现过程中是否还有其他与java-prolog-database交互相关的预期问题/难处?

Thanks in advance! 提前致谢!

What is the best way to manage concurrent http sessions that need access to the Prolog engine?. 管理需要访问Prolog引擎的并发http会话的最佳方法是什么?

If I look at the source of JPL, it looks like it uses an engine pool. 如果我看一下JPL的源代码,看起来它使用了一个引擎池。 The query data type implements the enumerator pattern plus a close() operation. 查询数据类型实现枚举器模式以及close()操作。 I guess an engine is automatically assigned to a query as long as it is active. 我猜只要引擎处于活动状态,它就会自动分配给查询。

So each http request can independently access the Prolog system via new query objects. 因此,每个http请求都可以通过新的查询对象独立访问Prolog系统。 If you don't want to close your query object during a http request, I guess you can also attach it to a http session. 如果您不想在http请求期间关闭查询对象,我想您也可以将其附加到http会话。 And reuse it an another request. 并重用另一个请求。

How could be managed the interaction of Prolog with the database ? 如何管理Prolog与数据库的交互?

This depends on the usage pattern of the data in the database and the available access paths. 这取决于数据库中数据的使用模式和可用的访问路径。 It could be that you can quickly access very large databases during a request and refetch the data during each request. 可能是您可以在请求期间快速访问大型数据库,并在每个请求期间重新获取数据。 For example if the needed matching data set is small and if the database has good indexes, so that the matching data can be quickly accessed. 例如,如果所需的匹配数据集很小,并且数据库具有良好的索引,则可以快速访问匹配的数据。

Otherwise you would need to implement some intelligent caching. 否则,您将需要实现一些智能缓存。 I am currently working at a solution where I use a kind of a check-in/check-out pattern. 我目前正在使用一种签入/签出模式的解决方案。 But this is not suitable for a web server, where you have multiple users. 但这不适合您有多个用户的Web服务器。 I am using this pattern for a standalone solution where there is one user and one checked out data junk in memory. 我将此模式用于一个独立的解决方案,其中有一个用户和一个签出的内存中的数据垃圾。 For a web server with varying multiple users the junks could overflow the webserver memory. 对于具有多个用户的Web服务器,垃圾邮件可能会使Web服务器的内存溢出。

So caching only works if you can limit and throttle the junks or if you have a very large webserver memory. 因此,只有在您可以限制和限制垃圾邮件或Web服务器内存很大的情况下,缓存才起作用。 Maybe you can find such an invariant for your application. 也许您可以为您的应用找到这样的不变式。 Otherwise the conclusion could be that you cannot go Java EE independent of whether you use Prolog or not. 否则的结论可能是,无论是否使用Prolog,您都不能独立于Java EE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM