当前页面: 开发资料首页 → Java 专题 → J2EE Web服务客户端质量报告(三)
J2EE Web服务客户端质量报告(三)
摘要: Serializer 软件包暴露的每个方法捕捉产生的任何异常,以便事务的处理可以不管这些异常继续进行
<table cellSpacing=0 cellPadding=5 width=570 bgColor=#fbe392 border=0>
<tr>
<td>
<table cellSpacing=0 cellPadding=5 width=570 border=0>
<tr>
<td align=middle width=200 bgColor=#e1b004>天极IT资讯短信服务 电脑小技巧
<table cellSpacing=0 cellPadding=3 width="100%" bgColor=#fffcc0 border=0>
function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; }
<form name=dn onsubmit="return check4()" action=http://www.my5757.com/tj/join.jsp target=_blank>
<tr vAlign=center>
<td>资费:包月5元
手机: <input style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; HEIGHT: 16px" size=11 name=mobile> <input type=image height=18 width=45 src="http://www.my5757.com/yesky/images/d34.gif" align=middle border=0 name=image2> </td></tr><input type=hidden value=yjq name=stype> </form></table></td>
<td width=370 bgColor=#fbc403>介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。 </td></tr></table></td></tr></table>
Payload软件包
Payload软件包可用于客户端,也可用于服务器。它包含三个类:ClientReport、CurrentReport、和 Serializer。
<iframe align=center marginWidth=0 marginHeight=0 src="http://images.chinabyte.com/adjs/iframe-pip/y-software-pip.html" frameBorder=0 width=360 scrolling=no height=300></iframe>
ClientReport 表示一个客户端次数报告:
<table width="100%" bgColor=#ffffff>
<tr>
<td>package Payload;
import java.io.*;
import java.util.*;
/**
*
* @author Brian Connolly Brian@ideajungle.com
*/
public class ClientReport implements Serializable {
public Date clientStartDateTime;
public Date serverStartDateTime;
public long clientElapsedMS;
public String type;
public String status;
public String transactionID;
public String clientID;
//Default public constructor for WSDL
public ClientReport() {
}
/*
. . . Get, set property methods are not shown
*/</td></tr></table>
在上述代码中,clientStartDateTime记录客户端初始化事务的时间。serverStartDateTime 当前没有使用;它的用途是保存事务的服务器开始时间以便事务次数可与服务器资源使用的随时间的变化关联起来。
ClientElapsedMS是我们记录的主要工具:从客户端开始记录新事务到它收到最后一个Web服务调用的结果为止这段时间的毫秒数。
Type允许客户端使用类型特征化事务。通常,事物系统提供许多种类型的事务。我们期望某些类型对于服务器来说相对容易一些,某些类型相对难一些,这样当我们分析响应次数和测量服务器资源时我们能够将他们辨别出来。
Status记录事务完成时的完成状态。
ClientID 是客户端标记符。当分析服务品质时我们可以使用它来区别同一个客户端完成的事务。
客户端使用第二个类CurrentReport来定界应用事务:
<table width="100%" bgColor=#ffffff>
<tr>
<td>package Payload;
import java.util.*;
import java.rmi.server.*;
/**
*
* @author Brian Connolly Brian@ideajungle.com
*/
public class CurrentReport {
public static UID ClientIdentifier = new UID();
/** Holds value of property currentReport */
public static ClientReport Report;
public static ClientReport LastReport;
/** Creates a new instance of CurrentReport */
public CurrentReport() {
}
public void BeginTransaction() {
Report = new ClientReport();
Report.setClientID(ClientIdentifier.toString());
Report.setClientStartDateTime( new Date());
}
public void CommitTransaction(String transactionID, String type, String status) {
Report.setTransactionID(transactionID);
Report.setStatus(status);
Report.setType(type);
long l1 = Report.getClientStartDateTime().getTime();
long l2 = new Date().getTime();
Report.setClientElapsedMS(l2-l1);
LastReport = Report;
Report = null;
}
/** Getter for property currentReport
* @return Value of property currentReport
*/
public static ClientReport getReport() {
ClientReport last = LastReport;
LastReport = null;
return last;
}
/** Setter for property currentReport
* @param currentReport New value of property currentReport
*/
public void setReport(ClientReport Report) {
this.LastReport = Report;
}
}</td></tr></table>
CurrentReport保存进行中的事务的当前 ClientReport 。它也保存LastReport,也就是一个完成的事务。它还产生一个作为唯一设备标记符使用的客户端标记符——在实际的应用中,这个客户端标记符可被修改为全局的唯一标记符。CurrentReport是非线程安全的;我们假设在客户端应用中只有一个单线程执行服务器事务。
zmbbs=1;
↑返回目录
前一篇:
Java新手必看之Hello World 攻略
后一篇:
两种设计模式在EJB开发中的应用