简体   繁体   English

将Java服务器应用程序集成到应用程序服务器中,如TomCat,GlassFish等

[英]Integration of Java server application into Application Server like TomCat, GlassFish, etc

I am working on a server application that does the following: 我正在处理执行以下操作的服务器应用程序:

  1. Read data from a measuring device that is being addressed via a serial interface (javax.comm, RXTX) or sockets. 从通过串行接口(javax.comm,RXTX)或插座寻址的测量设备读取数据。
  2. Exchange data (read and write) with another server application using sockets. 使用套接字与另一个服务器应用程序交换数据(读取和写入)。
  3. Insert data from (1) and (2) into a database using JDBC. 使用JDBC将数据从(1)和(2)插入数据库。
  4. Offer the data from steps (1) to (3) to a JavaScript-based web app. 将步骤(1)到(3)中的数据提供给基于JavaScript的Web应用程序。

My current prototype is a stand-alone Java application and implements task (4) by writing the data to an XML file that is being delivered to the client via a web server (Apache), but I consider this to be a hack, not a clean solution. 我当前的原型是一个独立的Java应用程序,通过将数据写入通过Web服务器(Apache)传递给客户端的XML文件来实现任务(4),但我认为这是一个hack,而不是清洁解决方案

This server application needs to start up and work also without any web clients being present. 此服务器应用程序需要在没有任何Web客户端的情况下启动和工作。

I would like to integrate this server application into a Java application server, but I do not have much experience with these technologies and don't know where to start. 我想将此服务器应用程序集成到Java应用程序服务器中,但我对这些技术没有太多经验,也不知道从哪里开始。 I have tried some simple examples for TomCat and GlassFish, but that did not bring me any further because they are all built around serving web requests synchronously and stop where it would be getting interesting for me. 我已经为TomCat和GlassFish尝试了一些简单的例子,但这并没有让我更进一步,因为它们都是围绕同步服务Web请求而构建的,并且停止了对我来说有趣的地方。

  • Is this possible to run such an app within TomCat or GlassFish? 这可以在TomCat或GlassFish中运行这样的应用程序吗?

  • If yes, where would be a good point to start (examples, which base classes, ...)? 如果是,那么开始的好点(例子,基类,......)?

  • Would it make any sense to split the application and implement only task (4) in a servlet, the rest in an ordinary application, communication via sockets, etc.? 拆分应用程序并在servlet中只实现task(4),在普通应用程序中实现其余部分,通过套接字进行通信等等,这是否合理?

  • Would other servers, eg JBoss, be a better choice and if yes, why? 其他服务器,例如JBoss,是否是更好的选择?如果是,为什么?

Edit: 编辑:
The reasons I want to use a Java EE container are: 我想使用Java EE容器的原因是:

  • I would like to have a clean external interface for step (4). 我想为步骤(4)设置一个干净的外部接口。

  • On the long run, the application will need to scale to a huge number of simultaneous clients (at least several 10.000), so a want a standard way of scalability and application management. 从长远来看,应用程序将需要扩展到大量的并发客户端(至少几个10.000),因此需要一种标准的可扩展性和应用程序管理方式。

I would loosely couple the solution and not try to do everything on the Java EE/Servlet container as exchanging data using sockets (managed by the application itself) is not something you typically want to do from a Java EE/Servlet container. 我会松散地耦合解决方案,而不是尝试在Java EE / Servlet容器上执行所有操作,因为使用套接字(由应用程序本身管理)交换数据不是您通常希望从Java EE / Servlet容器执行的操作。

Running this on a Java EE container might also be overkill as this doesn't sound like a typical enterprise application where stuff like security and transaction management is important and the app could benefit from services provided by the Java EE/Servlet container. 在Java EE容器上运行它也可能有点过分,因为这听起来不像典型的企业应用程序,其中安全和事务管理等内容很重要,应用程序可以从Java EE / Servlet容器提供的服务中受益。

In general, it's not a good idea to implement all of this in a servlet container such as Tomcat. 通常,在诸如Tomcat之类的servlet容器中实现所有这些并不是一个好主意。

A servlet container is designed to service requests from a client. servlet容器旨在为来自客户端的请求提供服务。 It sounds like you have a process which will be running all the time or at least periodically. 听起来你有一个将一直运行或至少定期运行的进程。 You can do this in Tomcat, but it's probably easier to do it outside. 您可以在Tomcat中执行此操作,但在外部执行此操作可能更容易。 Leave Tomcat to do what it's good at, servicing requests from browsers. 让Tomcat做好它的擅长,为浏览器的请求提供服务。 It's happiest when the requests are short lived. 请求是短暂的,这是最快乐的。

So I would do as you suggest, and only have step 4 in the container. 所以我会按照你的建议做,并且只在容器中有第4步。 You can easily interrogate the database populated in step 3, so there is no need to create web services to populate the servlet container. 您可以轻松查询在步骤3中填充的数据库,因此无需创建Web服务来填充servlet容器。

For step 4, you will need to expose some services from Tomcat, either through rest, soap, whatever you like. 对于第4步,您需要通过rest,soap,以及任何您喜欢的方式从Tomcat中公开一些服务。 The javascript clients can then interrogate these services. 然后,javascript客户端可以查询这些服务。 This is all completely doable with Tomcat. Tomcat完全可以做到这一点。

For scalability, there shouldn't be a problem using Tomcat. 对于可伸缩性,使用Tomcat应该没有问题。 If all it's doing is pumping data from the database to the client, there probably isn't a reason to choose a J2EE container. 如果它所做的只是将数据从数据库泵送到客户端,那么可能没有理由选择J2EE容器。 If you don't have need of complex transaction management or security, try using something open source. 如果您不需要复杂的事务管理或安全性,请尝试使用开源的东西。 It sounds like you can get what you want from Tomcat (& hibernate & spring security if necessary). 听起来你可以从Tomcat获得你想要的东西(如果需要的话,还有hibernate和spring security)。 If you start to have performance problems, then the fix will probably be the same for JBoss & Tomcat: you need more servers. 如果您开始遇到性能问题,那么JBoss和Tomcat的修复可能会相同:您需要更多服务器。

My advice: stick to the simple open source solutions and move to an application server only if you find it to be necessary. 我的建议:坚持使用简单的开源解决方案,只有在您认为有必要时才转移到应用程序服务器。

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

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