没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|其它|编辑:郝浩|2004-02-24 09:33:00.000|阅读 2552 次
概述:
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
Session Beans
Session beans represent particular business process steps. They capture the interaction or conversation between the user and the system. Session beans come in two flavors: stateful and stateless. Stateful session beans maintain state across multiple remote method invocations by a client on the same client-proxy of the session bean. Every method invocation by the client is routed to the same session bean instance on the server. These are useful when you need to carry out a long conversation with the server and you need the server object to save the conversational state. An example of a stateful session bean is an online shopping cart, where a client might use remote methods to add, remove, or modify the products in the shopping cart.
Stateless session beans do not maintain any state that the client can depend on between multiple remote method invocations. These are useful for situations where the duration of the method execution constitutes a complete unit of work from the client's perspective. For an example of a Stateless Session Bean, open the 'TraderEJBClient.jws' sample project in WebLogic Workshop. As you can see from the JWS operations (see Figure 4), this component has only two methods: Buy and Sell.
[FIGURE 4 OMITTED]
The EJB control (which wraps the interfaces of the EJB itself) actually has a third interface: Create. In fact, every session and entity EJB contains this method. This is how the instance of the bean is actually created. When dealing with entity beans, this method must be explicitly called--since creating an instance of an entity bean actually creates a new row in the corresponding datasource. However, with WebLogic Workshop it is not necessary to fire off the Create method of session beans. The BEA control framework automatically creates an instance of the bean when any of the methods are called. Even if you do explicitly call the Create method, you might not get a new instance. WebLogic Server may simply return an existing instance of the bean.
Since this is a fine-grained component, I have included both the Buy and Sell method calls in Listing 3. You'll notice that there is very little (if any) validation going on here. One glaring weakness is the lack of any validation that the user actually owns a sufficient quantity of shares to cover the sale. This validation is best added into the client portion of your application, or as part of a larger Web service--one that integrates an entity bean for account management and a stateful session bean to handle an extended conversation with the server (perhaps for transacting multiple stock sales). You want this validation complete before you even instantiate this bean.
Listing 3 /** * Invokes the target EJB's <b>buy</b> method and returns the result. * Trades are restricted to 500 shares. * * @return A String describing the result of the transaction. * * @jws:operation */ public String buy(String tickerSymbol, int numberOfShares) { TradeResult tr; try { tr = trader.buy(tickerSymbol, numberOfShares); } catch (RemoteException re) { return "Error " + re.getLocalizedMessage(); } return String.valueOf(tr.getNumberTraded()) + " shares of " + tr.getStockSymbol() + " bought."; } /** * Invokes the target EJB's <b>sell</b> method and returns the result. * Trades are restricted to 500 shares. * * @return A String describing the result of the transaction. * * @jws:operation */ public String sell(String tickerSymbol, int numberOfShares) { TradeResult tr; try { tr = trader.sell(tickerSymbol, numberOfShares); } catch (RemoteException re) { return "Error " + re.getLocalizedMessage(); } return String.valueOf(tr.getNumberTraded()) + " shares of " + tr.getStockSymbol() + " sold."; } }
Message-Driven Beans
Message-driven Beans (MDBs) enable the development of asynchronous applications. They essentially sit on the server and wait for Java Message Service (JMS) messages. They are anonymous in that no client may hold a reference to an MDB--only the EJB container may access the bean directly. They have neither a home nor a remote interface. As such, they cannot be used inside WebLogic Workshop. There is, however, an alternative. The BEA control framework includes a JMS control that you can add to your Workshop project. It can then listen for callbacks. Figure 5 shows a JWS project for credit reporting that uses a JMS control to receive credit information from the queue. Listing 4 shows the receiveMessage callback handler that processes the callback. This provides the same basic functionality of an MDB from within the Workshop environment.
[FIGURE 5 OMITTED]
Listing 4 /** * Callback handler for the CreditScoreControl JMS control's * receiveMessage callback. This handler is invoked when the * CreditScoreControl invokes its receiveMessage callback. */ private void creditScoreJMS_receiveMessage(int score) throws java.rmi.RemoteException { /* * Add the score received by the credit scoring application to * the data known about the applicant. */ m_currentApplicant.creditScore = score; /* * Using the ValidateCreditControl EJB control, request a credit * rating from an Enterprise Java Bean (EJB). Store the return * value in the approvalLevel field of the m_currentApplicant * object. */ m_currentApplicant.approvalLevel = validateCreditEJB.validate(m_currentApplicant.creditScore); /* * If the member variable m_callbackURL has value other than * null, then send a message to the client via the callback */ if( m_callbackURL != null ) { callback.onCreditReportDone(m_currentApplicant, "Credit score received."); } /* * If the member variable m_callbackURL has the value null, * then the client cannot accept callbacks. * Make the message available to the client through the * synchronous method checkForResults. */ else { /* * Mark the investigation as complete by setting the * isInvestigationComplete field to "true". Clients that * cannot accept callbacks will call checkForResults to * poll for investigation results; * m_isInvestigationComplete is used to determine what checkForResults should return. */ m_isInvestigationComplete = true; } }
Summary
Mission-critical applications that depend on tried-and-tested code benefit greatly from component reuse. WebLogic Server--in conjunction with WebLogic Workshop--can make the integration of these components a breeze.
Chris Brooke is director of Enterprise Technology for ComponentSource, a software asset value provider and global award-winning marketplace for reusable software assets for all platforms. He has contributed to both books and periodicals, and speaks regularly on reuse methodologies and technologies at conferences around the country.
CONTACT... chrisb@componentsource.com
COPYRIGHT 2003 Sys-Con Publications, Inc.本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号