从Java Web应用程序的控制C应用程序 [英] Control C application from Java web application

查看:166
本文介绍了从Java Web应用程序的控制C应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在不同地点的多台计算机上运行C应用程序。

I have C applications that will run on multiple machines at different sites.

现在我想控制和监视这些C应用程序。对此,我想使用的Servlet / JSP的Java Web应用程序。

Now I want to control and monitor these C applications. For that I am thinking about Java Web Application using Servlet/JSP.

我在想,C应用程序会连接到Java Web应用程序通过TCP。在我的web应用程序,我想实现管理器,它与C语言应用程序通过TCP通信。当Web应用程序启动时作为单独的线程,我将开始经理。而经理沟通与Servlet通过上下文和会话的请求。因此,只要用户浏览器上做一些事情,我想在服务器上使用我的经理的功能,与ServetContext一个会话的接口。

I am thinking that C applications will connect to Java Web application over TCP. In my web application, I am thinking to implement manager which communicates with C applications over TCP. I will start manager when web application starts as separate thread. And manager will communicate to servlet requests via Context and Session. So whenever user do something on browser, I want to use functionalities of my manager at server, with ServetContext an Session as interface.

这就是我的想法。所以,我想知道是否有更好的方法,还是我做错了什么?任何人都可以请建议我更好的解决方案?

So this is what I am thinking. So, I want to know if there is better approach, or I am doing anything wrong? Can anyone please suggest me better solution?

修改

目前的工作流程:每当我需要启动/停止C应用程序,我要SSH远程机器腻子终端,输入长的命令,并启动/停止它。每当有一些问题,我必须滚动很长很长的日志文件。还有几个其他像什么应用程序在做/处理所有的事情在每一秒,我不能在日志文件中随时登录活动状态。

Current workflow: whenever I need to start / stop C application, I have to SSH remote machine puTTY terminal, type long commands, and start / stop it. Whenever there is some issue, I have to scroll long long log files. There couple of other things like live status of what application is doing/processing all things at every second, that I can't log always in log file.

所以我觉得这些工作流困难。事情就是这样活的状态我无法监控。

So I find these workflow difficult. And things like live status I can't monitor.

现在我想有Web应用程序的接口吧。我可以修改我的C应用程序,并从头开始实现Web应用程序。

Now I want to have web application interface to it. I can modify my C application and implement web application from scratch.

新建工作流程来实现:我要开始从网页/停止C应用程序。我想查看日志和实时状态报告/网页上的现场图(监控什么C应用程序的执行)。我想监视设备状态也网页上。

New Workflow to implement: I want to start / stop C application from web page. I want to view logs and live status reports / live graphs on web page (monitoring what C application is doing). I want to monitor machine status also on web page.

Web界面我想用JSP / Servlet的Java的设计。

The web interface I thinking to design in Java using JSP/servlets.

所以,我将修改我的C应用程序,因此它可以与Web应用程序进行通信。

So, I will modify my C application so it can communicate with with web application.

问:

刚需作出新的工作流程指引/最佳实践。

Just need guidelines / best practices for making new workflow.

编辑2

对不起,控制器管理器之间的混淆。两者都是同样的事情。

Sorry for confusion between controller or manager. Both are same thing.

我的想法:
系统将包括C应用程序在不同的地点,爪哇控制器和Tomcat服务器平行运行的Java Web应用程序和数据库。

My thoughts: System will consist of C applications running at different sites, Java controller and Java web app running parallely in Tomcat server, and DB.

1)C的应用程序将连接到控制器通过TCP。所以,这里控制器成为服务器和C应用程序客户端。

1) C applications will connect to controller over TCP. So, controller here becomes server and C applications client.

2)C的应用程序将是多线程的,将收到来自控制器任务,并产生新的线程来执行该任务。当负责​​人告诉停止任务,C应用程序将停止该任务的线程。此外,C的应用程序将发送工作进度(原木)每一秒以控制器。

2) C applications will be multithreaded, will receive tasks from controller and spawns new thread to perform that task. When controller tells to stop task, C application will stop thread of that task. Additionally, C applications will send work progress (logs) every second to controller.

3)控制器从Web应用程序接收任务的命令(如无论是在Tomcat服务器运行的平行,两者在同一个JVM实例)和Web应用程序将收到通过HTTP从用户命令。

3) Controller receives task commands from web application (as both running parallelly in Tomcat server, both in same instance on JVM), and web application will receive commands from user over HTTP.

4)工作进度(原木)接收每秒从C应用到控制器,控制器然后将记录在数据库以供日后分析(需要考虑,如果它是在MySQL的RDBMS好插入日志,可能需要做很多插入,可能是100或1000每秒,永远)。 Web应用程序还可以从控制器请求最近5分钟记录并发送至用户通过HTTP。如果用户监控日志,那么Web应用程序将不得不从控制器检索日志每一秒,发送给用户通过HTTP。

4) The work progress (logs) received every second from C applications to controller, controller will then insert logs in DB for later analysis (need to consider if it is good insert logs in MySQL RDBMS, may be needed to do lot of inserts, may be 100 or 1000 every second, forever). Web application may also request recent 5 minute logs from controller and send to user over HTTP. If user is monitoring logs, then web application will have to retrieve logs every second from controller and send to user over HTTP.

5)用户监控C应用程序的任务,会看到图中的进步,每秒更新一次。可以在C应用程序偶尔会发生信息/错误的事件日志此外文本行。

5) User monitoring C application tasks, will see progress in graph, updated every second. Additionally text lines of logs of info/error events that may happen occasionally in C applications.

6)C的应用将是每个机器,将执行任何任务的用户从Web浏览器发送。 C应用程序将运行在机器的维修,这将开始在机器启动时,会连接到服务器,并保持连接到服务器,直到永远。可以空转,如果没有要执行的任务。

6) C applications will be per machine, which will execute any task user sends from web browser. C applications will be running as service in machine, which will start on machine startup, will connect to server, and will stay connected to server forever. Can be running idle if no tasks to perform.

推荐答案

这是一种有效的方法,我相信插座最分布式系统如何沟通,而且往往不是即使在同一个盒子不同的服务进行通信的方式。此外,我相信你暗示什么Java Web服务是很典型的,将很好地工作(这可能会增加复杂性超出了目前你在想什么,但你描述的archetecture是一个良好的开端)。

It is a valid approach, I believe sockets is how most distributed systems communicate, and more often than not even different services on the same box communicate that way. Also I believe what you are suggesting for the java web service is very typical and will work well (It will probably grow in complexity beyond what you are currently thinking, but the archetecture you describe is a good start).

如果是由你的C类业务也independantly管理体系运行,那么你可能要扭转这种局面,并有管理的系统连接到服务(除非你的防火墙prevents它)。

If your C services are made to also run independantly of the management system then you might want to reverse it and have the management system connect to the services (Unless your firewall prevents it).

您肯定希望一个小的,定义明确的协议。如果要发送大量的领域,你甚至可以让一切您发送JSON或XML,因为他们已经拥有解析器来验证格式。

You will certainly want a small, well-defined protocol. If you are sending lots of fields you could even make everything you send JSON or xml since they will already have parsers to validate the format.

要注意安全!在C面保证你不会得到任何缓冲区溢出,如果你分析自己的信息,严格大约扔掉(和记录!)数据看起来不正确。在Java中的缓冲区溢出不是太大的问题,但要确保你登录不适合你正好协议同时检测漏洞和入侵的数据包。

Be careful about security! On the C side ensure that you won't get any buffer overflows and if you parse the information yourself, be strict about throwing away (and logging!) data that doesn't look right. On Java the buffer overruns aren't as much of a problem but be sure that you log packets that don't fit your protocol exactly to detect both bugs and intrusions.

这是可以考虑的另一个解决方案 - 您的系统共享一个数据库已经可以通过发送DB命令和响应(假设命令/响应不发生过于频繁)。我们不这样做完全是,但我们分享,我们把指示我们的系统性能和配置(这是2路)不同方面的名称/值对的变量表,这可能不是最优的,但既然已经极其灵活让我们在运行时重新配置我们的系统(其值在每个服务本地缓存,并重新读取/每30秒更新一次)。

Another solution that you might consider--Your systems all share a database already you could send commands and responses through the DB (Assuming the command/responses are not happening too often). We don't do this exactly, but we share a variable table in which we place name/value pairs indicating different aspects of our systems performance and configuration (it's 2-way), this is probably not optimal but has been amazingly flexible since it allows us to reconfigure our system at runtime (the values are cached locally in each service and re-read/updated every 30 seconds).

我也许能够给你更多的信息,如果我知道更多的细节你会怎么做 - 例如,如何往往会将浏览器更新它的领域,什么样的命令信号或数据的请求将被发送什么样的数据,你指望回来?虽然你当然不必在这里张贴的东西,你必须考虑它 - 我建议嘲笑你的浏览器页面来启动

I might be able to give you more info if I knew more specifics about what you expected to do--for instance, how often will your browser update it's fields, what kind of command signals or data requests will be sent and what kind of data do you expect back? Although you certainly don't have to post that stuff here, you must consider it--I suggest mocking up your browser page to start.

根据意见修改:
听起来不错,只是一对夫妇的意见:

edits based on comments: Sounds good, just a couple comments:

2)任何良好的数据库应该能够处理记录数据的量,但您可能需要使用一个很好的缓存在你的DB之上。

2) Any good database should be able to handle that volume of data for logging but you may want to use a good cache on top of your DB.

5),你可能会想一个Web框架来渲染图形和管理更新。有很多,大部分可以做你在说什么pretty容易,但尝试做这一切没有自己的某种类型的框架可能是艰难的。我只能说这是因为你没有提到它。

5) You will probably want a web framework to render the graph and manage updates. There are a lot and most can do what you are saying pretty easily, but trying to do it all yourself without a framework of some sort might be tough. I only say this because you didn't mention it.

6)请确保你能处理掉线,然后重新连接。当您在测试,拉你的服务器上的插头(至少网线),并离开它10分钟,然后确保当你插回你得到你所期望的结果(如果客户端自动重新连接?如果它稳守日志或扔掉?多长时间守住日志?)

6) Be sure you can handle dropped connections and reconnecting. When you are testing, pull the plug on your server (at least the network cable) and leave it out for 10 minutes, then make sure when you plug it back in you get the results you expect (Should the client automatically reconnect? Should it hold onto the logs or throw them away? How long will it hold onto logs?)

您可能希望的方式为建设重新启动你的C服务。因为他们作为服务启动,简单的发送,告诉他们停止/退出一般会工作,因为系统将重新启动他们的命令。您可能还需要一点点的监测循环,重新启动它们在一定标准(如他们没有从服务器获得一个命令n分钟)。这可以在上午10时派上用场,当你在加利福尼亚州正试图与在凌晨2点在Austraillia一个C的服务工作。

You may want to build in a way to "Reboot" your C services. Since they were started as a service, simply sending a command that tells them to terminate/exit will generally work since the system will restart them. You may also want a little monitoring loop that restarts them under certain criteria (like they haven't gotten a command from the server for n minutes). This can come in handy when you're in california at 10am trying to work with a C service in Austraillia at 2am.

此外,考虑攻击者可以在客户端和服务器之间插入自己。如果您使用的是SSL套接字你应该没问题,但如果它是一个原始套接字,你必须非常小心。

Also, consider that an attacker can insert himself between your client and server. If you are using an SSL socket you should be okay, but if it's a raw socket you must be VERY careful.

更正:

您可能将许多记录到一个MySQL数据库的问题。如果没有索引,你尽量减少对其进行查询,你可能会好起来。您可以通过保持最后5分钟的所有日志在内存中,所以你不必索引数据库,并通过分组插入或有一个很好的调整缓存实现这一​​目标。

You may have problems putting that many records into a MySQL database. If it is not indexed and you minimize queries against it you may be okay. You can achieve this by keeping the last 5 minutes of all your logs in memory so you don't have to index your database and by grouping inserts or having a very well tuned cache.

有一个更好的办法可能是放弃数据库,并只使用平面的日志文件pre-过滤什么单个用户可能希望看到的,所以,如果用户要求的最后5分钟警告和DEBUG 从一台机器的邮件,你可以只是读从机日志文件到内存中,跳过所有但警告/调试消息,并显示这些。这有它自己的问题,但应该比索引数据库更具可扩展性。这也将让你拉上旧数据(即用户不希望对查询更多)在磁盘空间节约70-90%。

A better approach might be to forgo the database and just use flat log files pre-filtered to what a single user might want to see, so if the user asks for the last 5 minutes "WARN" and "DEBUG" messages from a machine you could just read the logfile from that machine into memory, skipping all but warn/debug messages, and display those. This has it's own problems but should be more scalable than an indexed database. This would also allow you to zip up older data (that a user won't want to query against any more) for a 70-90% savings in disk space.

这篇关于从Java Web应用程序的控制C应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆