客户端-服务器程序中逻辑的服务器端脚本编写方法
我正在寻找最佳实践或通用方法,以使常规非程序员可以修改服务器端应用程序。它不必进行热修改;它可以被重新编译和重新部署。
假设系统位于 EJB 或 Spring 容器中。该系统是消息驱动的(可能是EJB3.1)。有许多 POJO 从客户端应用程序(RCP 或 RIA)接收消息,对这些消息做出反应,并向同一客户端应用程序和其他客户端应用程序发送更多消息。使系统易于修改的最佳方法是什么?如果我正确地分离了服务器的逻辑组件,什么技术或设计方法允许我用新的 POJO 替换逻辑 POJO,从而改变应用程序的行为?
我认为我所描述的是一种策略模式。这些 POJO 可以从一组人类可读和可编辑的规则生成吗?像 Drools 这样的规则引擎是解决这个问题的正确方法吗?
它也可以与状态机生成器结合使用,以便每个状态都有输入消息和对每个消息的响应、转换规则等的列表吗?
玩具示例:
- State_Evening
- 输入卖出股票
- 回复“晚上不能卖,要等到白天。”
- 输入卖出股票
- 州日
- 输入卖出股票
- 出售股票
- 回复“股票售价_”
- 输入卖出股票
等。
现在我这样写出来,看起来脚本语言几乎与编程相同......
我只是寻找正确方向的指针。或者可能是我把简单的事情过于复杂化了。也许我应该尽可能清晰地分离业务逻辑并在代码中进行更改?
为了清晰起见,于 2012 年 2 月 22 日编辑
I’m looking for best practices or a general approach towards making a server-side application modifiable by regular non-programmers. It doesn’t have to be hot-modified; it can be recompiled and redeployed.
Suppose the system is in a EJB or Spring container. The system is message driven (perhaps EJB3.1). There are a number of POJOs that receive messages from client applications (RCPs or RIAs), react to those messages, and send more messages to the same and other client apps. What is the best approach to make the system easily modifiable? If I correctly separate the server's logic components, what technology or design approach would allow me to swap out logic POJOs with new POJOs, thereby changing the application's behavior?
I think what I'm describing is a Strategy Pattern. Can these POJOs be generated from a set of human-readable and editable rules? Is a rule engine like Drools the right way to approach this problem?
Can this be combined with a state machine generator as well, so that each state has a list of input messages and responses to each, transition rules, and so forth?
Toy example:
- State_Evening
- input sellStocks
- reply "Cannot sell in evening, wait until daytime."
- input sellStocks
- State_Day
- input sellStocks
- do SellStocks
- reply "Stocks sold for _"
- input sellStocks
etc.
Now that I write it out like that, it looks like the scripting language would be almost the same as programming...
I'm just looking for a pointer in the right direction. Or it could be that I'm over-complicating something simple. Perhaps I should just make the business logic as cleanly separated as possible and make the changes in the code?
Edited on Feb 22 2012 for clarity
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意 JB Nizet 关于手术刀的评论。
无论如何:对你的问题的一些答案:
EJB 不会以这种方式工作,他们将需要像 Glassfish 或 Websphere Application Server 这样的 EJB 容器。但如果您使用 Spring,则不需要 EJB(您可以使用 Spring Beans)。如果您使用 Spring,那么您主要拥有一个 Spring Servlet,并且所有 Web 内容均由 Spring MVC 框架处理 - 这与经典的 Servelt 编程(无框架)不同 动态
更改某些代码的一种方法是使用脚本语言。因此,您可以使用 Rino 在 JVM 中运行 java 脚本代码。
但实际上,当我需要完成你的工作时,我会尝试为服务器和客户端实现一些框架,这使得用 java 编写游戏变得容易。因此,您的学生可以使用普通的 IDE 或者 Maven 来部署完整的应用程序。
I agree to JB Nizet comment about the scalpel.
Anyway: some answers to your probelm:
EJB will not work this way, they will need a EJB Container like Glassfish or Websphere Application Server. But if you use Spring, then you do not need EJBs (you have Spring Beans instead). If you use Spring, then you mostly have one Spring Servlet, and all the web stuff is handled by the Spring MVC Framework -- this divers from classis Servelt programming (without framework)
One way to change some code on the fly is using a scripting language. So you can use for example Rino to run java script code within the JVM.
But really, when I would need to do your job, then I would try to implement some framework for server and client, that make it easy to write the games in java. So your studends can use a normal IDE and maybe maven to deploy the complete application.