Topic: 寻最佳系统构架?

  Print this page

1.寻最佳系统构架? Copy to clipboard
Posted by: yadan
Posted on: 2003-06-18 10:03

分布式的环境,有jsp/servlet web服务器和ejb服务器。客户需要通过浏览器进行操作,同时,还有分布的GUI应用程序需要和服务器端进行交互。

最初想采用jdbc+session bean,不用实体bean的构架。后来发现,即使不用实体bean,实际上还是少不了类似实体bean这样的“持久类”,因为客户端应用程序也需要从服务器端取得“用户”、“订单”等等这样的对象,所有的信息交互都用session bean来作好像办不到。因此这样的对象也需要在服务器和客户端之间传递,必须实现序列化。我做了一些简单例子,好像这样是可行的。但不知道这样的模式在实际应用中会不会出问题???安全性和性能呢?

我想这里一定有人做过类似系统--既有web端,又有远程应用程序的系统。能谈谈你们系统的构架么?按照我上面那种方法作,总觉得有点不好。如果用hibernate这样的O/R mapping产生持久层对象,可以满足那样的系统需求吗,这个持久层应该放在EJB服务端还是哪里,持久对象在服务端和客户端的传递又是什么机制?如果彻底不用EJB,又有什么别的解决方案?

一口气问了这么多,这是不好意思。不是不想自己思考和摸索,只是这些问题困扰我好多天了,希望看看各位大侠的宝贵经验,先谢谢了。Smile

2.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: jameszhang
Posted on: 2003-06-18 11:28

实体BEAN不能不用,也不能全用因为它不是万能的,用户信息可以用信息有限,大量交易信息,用起来好象比较费劲了。(个人观点)

3.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: bujinwang
Posted on: 2003-06-18 11:43

Wether you would like to use EJB is determined by the following factors:
1) Transation: are there any transaction issue?
2) Concurrency: are there any concurrent access to your data?
3) Scalability-- How many clients would be there to connect to your server?
4) Naming:
5) Persistence: do you need to save data into database?
6) Resource Management: are you going to do some resource pooling yourself?

If you need some of these features, you better use ejb, 'cause it saves you from a lot of trouble.

As I understand from your descriptioni, at least you need transaction integrity, persistence, so ejb is an good option. However the same thing could be done with JDO.

4.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: floater
Posted on: 2003-06-18 12:26

I recommend you read expert one-on-one J2EE and Java enterprise best practice.
1. Persist layer should be coded against interfaces so that you can switch between different implementations, like jdbc, entity beans, hibernate, jdo, etc.
2. The only reason I see to use ejbs is the scalability with CMP. A simple one-class Transaction manager is trivial to write. Other reasons are less convincing.
3. Web or GUI interface should be isolated too. Application/business logic should be coded in javabean or standard class, session beans should serve as glues at best, or simply out of the picture if entity bean is not used.

It takes years to sort out these mess, especially in those grey areas where there is no absolutely being right and wrong(more of a style/taste of each individual).

5.Re:寻最佳系统构架? [Re: floater] Copy to clipboard
Posted by: yadan
Posted on: 2003-06-18 14:46

谢谢大家,特别是floater斑竹!Smile
小弟还有一些问题麻烦。。。。。


1. Persist layer should be coded against interfaces so that you can switch between different implementations, like jdbc, entity beans, hibernate, jdo, etc.

这条太好了。持久层做成接口,用实体bean、jdbc、jdo实现都可以。客户端只要知道这个接口就行。确实很好。小弟经验少,有点肤浅的问题,实体bean、hibernate产生的类等怎么和自己系统定义的接口很好的关联?我的意思是这样的:
假设系统定义一个接口:

public interface User extends java.io.Serializable
{
public long getID();
............
}

对接口User用EJB实体bean来实现,

public interface UserEJB extends EJBObject
{
............
}
public class UserEJBBean implements EntityBean
{
.........
}
public interface UserEJBHome extends EJBHome
{
.........
}

UserEJB怎么和User接口很好地关联?


3. Web or GUI interface should be isolated too. Application/business logic should be coded in javabean or standard class, session beans should serve as glues at best, or simply out of the picture if entity bean is not used.

sessin bean最好作为粘合剂?(业务逻辑和数据层之间的?)或者说如果实体bean不用的话,session bean也彻底不要了(out of the picture是这个意思么,见笑Tongue)。如果session bean不要,GUI的程序有什么方式得到远程对象?

6.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: floater
Posted on: 2003-06-18 22:22

For #1, this is the general rule. However for entity beans, this is exceptional(that's why I say that if no entity bean). The reason behind it is the cost of network traffic. You have to reduce the network overhead for entity beans by using local interfaces of entity beans.

For other options, jdbc, hibernate, etc. It's pretty straight forward

public interface User
{
public long getID();
}

public class JDBCUser implements User
{
public long getID()
{
//get DataSource, get connection, get user
}
}

public class JDOUser() implements User
{
public long getID()
{
//do it in JDO way
}
}

....

Then in your client code using User would like this:
User user = (User) DB.createUser();
long i = user.getID();

In your DB class:
public User createUser()
{
//get class name from configure file and initiate the class, it must be one of JDBCUser, JDOUser, etc.
//return the object.
}

You may need to pass in some parameters to create the user object.

For #3, there are many options with certain restrains on the network side. I don't know the way that your GUI connects to the server, it could be http, rmi, or sockets, etc. So my point is whenever possible, don't use session bean for business logic(out of the picture=get it out of my way, Tongue). Otherwise you would have a dependency from business logic to ejb container, this doesn't make sense in general.

7.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: Julian13
Posted on: 2003-06-19 09:09

agree with floater that data object should be abstracted from your persistence mechanism. this make you flexible to adopt different way to do the persistence job, either entity bean, hibernate or even jdbc directly.
for these implementation, i guess the xdoclet may help your fasten the job by utilizing its tag for entity bean or hibernate. thus, you can minimize the tedious coding work Wink of course, coding by hand let you consider more about the persistence design.

floater also bring out point that business logic should be decouple from technnology (or the ejb container as he stated). for these implementation, i think we can make those business operation remain inside your domain model classes or some business classes and wrapping them by a session bean for its ACID. such that you can wrapped those operation by different transaction mechanism later. for me, i used to wrapper those operation with a jdbc connection since my project scope need not using j2ee container Tongue

about the UI, as long as the MVC pattern being enforced. it should capable to deal with web frontend, swing GUI or even text mode console. of course, the value-object pattern will play an important role for different nature of UI implementation.

8.Re:寻最佳系统构架? [Re: floater] Copy to clipboard
Posted by: yadan
Posted on: 2003-06-19 10:23

#3: 我的GUI应用程序连接服务器的方式是用EJB的方式获取远程对象,通过session bean(甚至实体bean)和服务器交互。我想这是一种糟糕的形式,需要在网络间传递大量对象。但是EJB的远程调用方式封装了双方传输协议,如果不用EJB,写socket,rmi编码工作量可能要大很多,是不是?还有,我不知道我下面这样的机制能不能行的通:

public interface User extends java.io.Serializable
{
public long getID();
}

public class EJBUser implements User
{
public long getID()
{
//get DataSource, get connection, get user
}
}

public interface UserManager
{
  public User createUser();
}

public class EJBUserManager implements UserManager
{
  public User createUser()
  {
   //获取一个session bean,在服务器端执行创建一个newuser(注意)
   return newuser;
  }
}

上面这些类在服务器端和远程GUI程序都有(否则不能编译)。在GUI程序调用
User newuser = getUserManager().createUser();
getUserManager()返回一个EJBUserManager对象,调用EJBUserManager的createUser()方法,
这个方法先获取一个session bean,在服务器端执行session bean的一个方法,进行数据库操作,并返回一个newuser。
由于User接口实现了Serializable接口,远程的User对象可以传递到客户端,GUI程序就得到这个对象。
对这种方式,1我不知道能否行得通,2如果行的通,感觉这种方式很别扭,不知道怎么改进。

你们说session bean不要实现业务逻辑,我觉得很有道理。但是在这种远程GUI需要和服务器端进行对象交互和传递时,不用ejb用什么方式更好?

9.Re:寻最佳系统构架? [Re: Julian13] Copy to clipboard
Posted by: floater
Posted on: 2003-06-19 12:49

Julian13 wrote:
agree with floater that data object should be abstracted from your persistence mechanism. this make you flexible to adopt different way to do the persistence job, either entity bean, hibernate or even jdbc directly.
for these implementation, i guess the xdoclet may help your fasten the job by utilizing its tag for entity bean or hibernate. thus, you can minimize the tedious coding work Wink of course, coding by hand let you consider more about the persistence design.

floater also bring out point that business logic should be decouple from technnology (or the ejb container as he stated). for these implementation, i think we can make those business operation remain inside your domain model classes or some business classes and wrapping them by a session bean for its ACID. such that you can wrapped those operation by different transaction mechanism later. for me, i used to wrapper those operation with a jdbc connection since my project scope need not using j2ee container Tongue

about the UI, as long as the MVC pattern being enforced. it should capable to deal with web frontend, swing GUI or even text mode console. of course, the value-object pattern will play an important role for different nature of UI implementation.

Thank you, thank you. I love this.

10.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: floater
Posted on: 2003-06-19 12:51

yadan wrote:

你们说session bean不要实现业务逻辑,我觉得很有道理。但是在这种远程GUI需要和服务器端进行对象交互和传递时,不用ejb用什么方式更好?

use session bean wrap your logic classes, like this great man said above.

11.Re:寻最佳系统构架? [Re: floater] Copy to clipboard
Posted by: juweiping
Posted on: 2003-06-19 13:34

我发表一下我的解决方案:
yadan是说两种客户端方式,Web/GUI,存取相同业务逻辑。
我们采用Web/GUI-->Http---〉BussinessProxy---〉SessionBussinessBean---〉SessionFacade----〉EntityBean-----〉BMP(DAO/VO)/CMP----〉DB方式。
成熟经验,已有产品。

12.Re:寻最佳系统构架? [Re: juweiping] Copy to clipboard
Posted by: yadan
Posted on: 2003-06-19 15:08

juweiping wrote:
我发表一下我的解决方案:
yadan是说两种客户端方式,Web/GUI,存取相同业务逻辑。
我们采用Web/GUI-->Http---〉BussinessProxy---〉SessionBussinessBean---〉SessionFacade----〉EntityBean-----〉BMP(DAO/VO)/CMP----〉DB方式。
成熟经验,已有产品。

嗨,谢谢! Smile
能不能具体说说你们产品的GUI->Http层->BussinessProxy的方式吗?

13.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: juweiping
Posted on: 2003-06-19 15:49

GUI->Http->Web层->BussinessProxy的方式:
即前台采用的Swing GUI客户端,以自定义代理方式经由Http通道透明访问商业逻辑,此商业逻辑实际位于Web应用服务器上。这样整个应用有统一的商业逻辑(包括Web与GUI),并且此GUI应用是跨防火墙的(因为经由Http)。

14.Re:寻最佳系统构架? [Re: juweiping] Copy to clipboard
Posted by: yadan
Posted on: 2003-06-19 16:07

juweiping wrote:
GUI->Http->Web层->BussinessProxy的方式:
即前台采用的Swing GUI客户端,以自定义代理方式经由Http通道透明访问商业逻辑,此商业逻辑实际位于Web应用服务器上。这样整个应用有统一的商业逻辑(包括Web与GUI),并且此GUI应用是跨防火墙的(因为经由Http)。


Great,听起来真的很不错!
不知道有没有类似的开源项目可以学习学习就好了Smile

15.Re:寻最佳系统构架? [Re: yadan] Copy to clipboard
Posted by: juweiping
Posted on: 2003-06-19 16:26

BSF is the one(http://www.bs-factory.org)
但是需要你自己改进来适合web/Gui统一模式。
你可以借鉴他的代理模式与前端GUI组织方式(框架)。
真正的重点在后台的Framework!
祝你好运,你可以通过EMail与我联系,发悄悄话给我,我告诉你My EmailSmileSmile


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923