2005年08月29日

前几天看了一些关于AJAX的一些资料,算是明白一点,所以写了一个关于AJAX的类,这样以后就可以不用再写那些重复的东西了,虽然网上有些写好的类库,不过我还是写了一个,这样可以学习一下javascrip。下面就来说说我写的这个类和用到的知识吧。

AJAXAsynchronous JavaScript Technology and XML应用这个技术就可以不刷新页面的情况下访问网络资源。这一切都是围绕XMLHttpRequest类来进行的,这个类由IE5.0以后的版本支持。这项技术最好的例子就是Google Map,有空的话可以去看看。

下面说明我写的类吧。

/************************************

 * MRequest is used to ajax.

 * CopyRight(R) Joshua.M.D

 * 2005/8/9 09:17 AM

 ************************************/

/* Mrequest类的构造函数。 */

function MRequest(){

       this._request=null; //XMLHttpRequest对象的引用

       this._url=null;  //要访问的网络资源

       this._callback=null; //回调函数

      

       this.setCallBack=_setCallBack;

       this.setURL=_setURL;

       this.translate=_translate;

       this.toString=_toString;

      

       _init(); 

}

/* 初始化_request,引用一个XMLHttpRequest对象 */

function _init(){

       if (window.XMLHttpRequest) {

        this._request = new XMLHttpRequest();

    } else if (window.ActiveXObject) {

        this._request = new ActiveXObject("Microsoft.XMLHTTP");

    } else{

           alert("Can’t init request!");

    }

}

 

function _setURL(url){

       this._url=url;

}

 

function _setCallBack(cb){

       this._callback=cb;

}

/* 开始数据传输 */

function _translate(){

       this._request.open("GET", this._url, true);

    this._request.onreadystatechange=_onTranslateComplete;

    this._request.send(null);

}

/* 数据传输完成后对数据进行解析 */

function _onTranslateComplete(){

       if(this._request.readyState==4){

              if(this._request.status==200){

                     this._callback();

              }else{

                     alert("Occur Error: the errno is:"+this._request.status);

              }

       }

}

 

function _toString(){

       return  "The request is: "+this._request+"\n"+

                     "The URL is: "+this._url+"\n"+

                     "The CallBack is:\n"+this._callback;

}

Mrequest的应用:在网站中只要引入Mrequest类后就可以应用了。

我们只用声明一个回调函数和一个网络资源(URL)就可以用了。

<script src="MRequest.js"></script>

<script type="text/javascript">

<!–//

      function cb(){

             alert("ok");

      }

      function t(){

             var req=new MRequest();

             req.setCallBack(cb);

             req.setURL(‘http://localhost:8080/’);

             req.translate();

      }

//–>

</script>

<input type="button" value="Click Me!" onClick="t()">

在本次编写过程中,只是将一些工作封装了一下,这样我们就可以只关心数据的处理而不用关心这些繁琐的代码。但是真正用的话还是应该用一些比较成型的系统,这只是一个例子而已。

一、概念

Martin Fowler的文章:Continuous Integration  中文翻译:持续集成

二、工具

传统工具:JBuilder,VisualSourceSafe,Rational ClearCase

自动编译工具:Ant

回归测试工具:JUnit

代码检查工具:CheckStyle

持续集成工具:CruiseControl

三、步骤

  • CruiseControl监控远程版本控制系统的变化

  • 变化发生时CruiseControl调用编译工具进行编译(Ant等)

  • 编译成功后调用JUnit进行回归测试

  • 编译成功后调用CheckStyle进行代码检查

  • 打包,部署,更新版本控制系统

  • 完毕后将编译结果、测试结果、代码检查结果发送至开发人员、主管经理,并发布至网站,甚至报警器

    所有这一切都是按照编制好的脚本自动进行的

四、实施示例

目前我们使用的是ClearCase,主控软件为CruiseControl,其脚本文件为cccc.xml

  • 配置远程版本控制系统

<modificationset quietperiod="60">

  <clearcase branch="main" viewpath="D:\cc_view\chelseafc\Nucleus2.0\Port" recursive="true" />

</modificationset>

  • 配置编译工具

<schedule interval="60">

  <ant antscript="C:\Java\JBuilder2005\thirdparty\ant\bin\ant.bat" buildfile="D:\cc_view\chelseafc\Nucleus2.0\Port\clearcase-build.xml" target="cleanbuild" multiple="1" />

</schedule>

  • 配置测试用例(在ant的配置文件中)

<target name="test" depends="init" description="Run unit tests">

  <delete dir="${junit.results}" />

  <mkdir dir="${junit.results}" />

  <junit fork="yes" haltonfailure="yes">

  <classpath refid="project.class.path" />

  <formatter type="plain" usefile="false" />

  <formatter type="xml" />

  <batchtest todir="${junit.results}">

  <fileset dir="${build.dir}" includes="**/*TestCase.class" />

  <fileset dir="${build.dir}" includes="**/*TestSuite.class" />

  </batchtest>

  </junit>

</target>

  • 配置报告形式

<publishers>

  <currentbuildstatuspublisher file="currentbuild.txt" />

  <htmlemail mailhost="mail.chelseafc.com.cn" returnaddress="workflow_engine@chelseafc.com.cn" subjectprefix="ContinuousIntegration:" buildresultsurl="http://chelsea:8044/cruisecontrol/buildresults" spamwhilebroken="true" xsldir="F:\software\Agile.Net\cruisecontrol-2.2\reporting\jsp\xsl" css="F:\software\Agile.Net\cruisecontrol-2.2\reporting\jsp\css\cruisecontrol.css" logdir="D:\Tomcat 4.1\webapps\cruisecontrol\samplelogs">

  <always address="chelsea@chelseafc.com.cn" />

  <always address="ajax@chelseafc.com.cn" />

  <map alias="chelsea" address="chelsea@chelseafc.com.cn" />

  </htmlemail>

  </publishers>

  • 其中CruiseControl暂时没有提供代码检查工具的支持,建议使用Ant来调用CheckStyle,示例如下(没有真正运行过):

<target name="web.checkstyle">

  <mkdir dir="${target.temp}/checkstyle" />

  <mkdir dir="${target.web}/checkstyle" />

  <taskdef resource="checkstyletask.properties">

  <classpath>

  <fileset dir="${support.tools}/checkstyle31" includes="**/*.jar"/>

  </classpath>

  </taskdef>

  <copy file="${support.tools}/checkstyle31/custom.xml" overwrite="true" tofile="${target.temp}/checkstyle/custom.xml">

  <filterset>

  <filter token="source.java" value="${basedir}/${source.java}" />

  <filter token="target.checkstyle" value="${basedir}/${target.temp}/checkstyle" />

  </filterset>

  </copy>

  <checkstyle config="${target.temp}/checkstyle/custom.xml" failOnViolation="false">

  <fileset dir="${source.java}/main" includes="**/*.java" />

  <formatter type="plain" />

  <formatter type="xml" toFile="${target.temp}/checkstyle/checkstyle_errors.xml" />

  </checkstyle>

  <style basedir="${target.temp}/checkstyle" destdir="${target.web}/checkstyle" includes="checkstyle_errors.xml" style="${support.tools}/checkstyle31/checkstyle-noframes.xsl" />

  </target>

  • 打包、部署(在ant的配置文件中)

<target name="jar">

<jar jarfile="${dist.dir}\nucleus_engine.jar">

  <fileset dir="${build.dir}" />

</jar>

<jar jarfile="../../M1/Web/lib/service_gateway.jar">

  <fileset dir="${build.dir}" />

</jar>

</target>

<target name="war">

  <ant antfile="build-war.xml" />

</target>

  • check out 版本控制工具中的配置项(在ant的配置文件中)

<target name="checkoutzipfile">

  <cccheckout viewpath="../Release/nucleus2.0.zip" reserved="true" branch="main" />

</target>

  • 压缩zip文件(在ant的配置文件中)

<target name="zip">

  <zip destfile="../Release/nucleus2.0.zip" basedir="../Release/nucleus2.0" />

</target>

  • check in 版本控制工具中的配置项(在ant的配置文件中)

<target name="checkinzipfile">

  <cccheckin viewpath="../Release/nucleus2.0.zip" identical="true" />

</target>

五、几点提示

  • CruiseControl会自动根据本地ClearCase的View监控远程VOB

  • 其实除了监控远程版本控制系统外其它的任务都可以由Ant来完成,CC只负责监控变化并调用Ant即可

  • CruiseControl2.2的<htmlemail>好像无法在jdk5.0下运行,如果需要集成jdk5.0的项目,则需要为Ant的<javac>指定source和target,而CruiseControl2.2依然用jdk1.4启动

  • 可以为cruisecontrol.bat加入启动参数“-port 8055”,这样可以用JMX(http://localhost:8055)来控制cc

  • 最好避免中文路径,否则就需要手工为几个Xml格式的文件,如cc的report Servlet的Web.xml等加入编码方式“<?xml version="1.0" encoding="UTF-8" ?>,或者将中文路径映射为虚拟硬盘:“subst Y: "D:\cc_view\chelsea\Platform\开发\Nucleus2.0\Source"”

  • 中文log无法正常显示时,需要设置CruiseControl配置文件中<log>元素的“encoding”属性,如:

    <log dir="D:\Tomcat 4.1\webapps\cruisecontrol\samplelogs" encoding="utf-8">

      <merge dir="D:\cc_view\chelseafc\Nucleus2.0\Port\test-results" />

    </log>

  • 编译失败后,在下次checkin之前,一般不需要重新编译,这时可设置<project >的“buildafterfailed”属性为false来避免重新编译

  • <htmlemail>的几个属性好像没有缺省设置,虽然文档里说从2.1.7开始有缺省设置,包括xsldir,css,logdir

  • 可使用JBuilder辅助生成ant文件

  • 各种工具的安装、使用,在各自的文档里都非常详细,网上亦有无数资源

六、参考资料

2005年08月26日
Asynchronous JavaScript Technology and XML (AJAX)
With Java 2 Platform, Enterprise Edition

By Greg Murray, June 9, 2005  


 

by Jesse James Garrett

February 18, 2005

If anything about current interaction design can be called “glamorous,” it’s creating Web applications. After all, when was the last time you heard someone rave about the interaction design of a product that wasn’t on the Web? (Okay, besides the iPod.) All the cool, innovative new projects are online.

Despite this, Web interaction designers can’t help but feel a little envious of our colleagues who create desktop software. Desktop applications have a richness and responsiveness that has seemed out of reach on the Web. The same simplicity that enabled the Web’s rapid proliferation also creates a gap between the experiences we can provide and the experiences users can get from a desktop application.

That gap is closing. Take a look at Google Suggest. Watch the way the suggested terms update as you type, almost instantly. Now look at Google Maps. Zoom in. Use your cursor to grab the map and scroll around a bit. Again, everything happens almost instantly, with no waiting for pages to reload.

Google Suggest and Google Maps are two examples of a new approach to web applications that we at Adaptive Path have been calling Ajax. The name is shorthand for Asynchronous JavaScript + XML, and it represents a fundamental shift in what’s possible on the Web.

Defining Ajax

Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming together in powerful new ways. Ajax incorporates:

The classic web application model works like this: Most user actions in the interface trigger an HTTP request back to a web server. The server does some processing — retrieving data, crunching numbers, talking to various legacy systems — and then returns an HTML page to the client. It’s a model adapted from the Web’s original use as a hypertext medium, but as fans of The Elements of User Experience know, what makes the Web good for hypertext doesn’t necessarily make it good for software applications.

Ajax Overview 1

Figure 1: The traditional model for web applications (left) compared to the Ajax model (right).

This approach makes a lot of technical sense, but it doesn’t make for a great user experience. While the server is doing its thing, what’s the user doing? That’s right, waiting. And at every step in a task, the user waits some more.

Obviously, if we were designing the Web from scratch for applications, we wouldn’t make users wait around. Once an interface is loaded, why should the user interaction come to a halt every time the application needs something from the server? In fact, why should the user see the application go to the server at all?

How Ajax is Different

An Ajax application eliminates the start-stop-start-stop nature of interaction on the Web by introducing an intermediary — an Ajax engine — between the user and the server. It seems like adding a layer to the application would make it less responsive, but the opposite is true.

Instead of loading a webpage, at the start of the session, the browser loads an Ajax engine — written in JavaScript and usually tucked away in a hidden frame. This engine is responsible for both rendering the interface the user sees and communicating with the server on the user’s behalf. The Ajax engine allows the user’s interaction with the application to happen asynchronously — independent of communication with the server. So the user is never staring at a blank browser window and an hourglass icon, waiting around for the server to do something.

Ajax Overview 2

Figure 2: The synchronous interaction pattern of a traditional web application (top) compared with the asynchronous pattern of an Ajax application (bottom).

Every user action that normally would generate an HTTP request takes the form of a JavaScript call to the Ajax engine instead. Any response to a user action that doesn’t require a trip back to the server — such as simple data validation, editing data in memory, and even some navigation — the engine handles on its own. If the engine needs something from the server in order to respond — if it’s submitting data for processing, loading additional interface code, or retrieving new data — the engine makes those requests asynchronously, usually using XML, without stalling a user’s interaction with the application.

Who’s Using Ajax

Google is making a huge investment in developing the Ajax approach. All of the major products Google has introduced over the last year — Orkut, Gmail, the latest beta version of Google Groups, Google Suggest, and Google Maps — are Ajax applications. (For more on the technical nuts and bolts of these Ajax implementations, check out these excellent analyses of Gmail, Google Suggest, and Google Maps.) Others are following suit: many of the features that people love in Flickr depend on Ajax, and Amazon’s A9.com search engine applies similar techniques.

These projects demonstrate that Ajax is not only technically sound, but also practical for real-world applications. This isn’t another technology that only works in a laboratory. And Ajax applications can be any size, from the very simple, single-function Google Suggest to the very complex and sophisticated Google Maps.

At Adaptive Path, we’ve been doing our own work with Ajax over the last several months, and we’re realizing we’ve only scratched the surface of the rich interaction and responsiveness that Ajax applications can provide. Ajax is an important development for Web applications, and its importance is only going to grow. And because there are so many developers out there who already know how to use these technologies, we expect to see many more organizations following Google’s lead in reaping the competitive advantage Ajax provides.

Moving Forward

The biggest challenges in creating Ajax applications are not technical. The core Ajax technologies are mature, stable, and well understood. Instead, the challenges are for the designers of these applications: to forget what we think we know about the limitations of the Web, and begin to imagine a wider, richer range of possibilities.

It’s going to be fun.

2005年08月24日

Gentoo Linux x86 Quick Install Guide

Sven Vermeulen  Author
Steven Wagner Author

Updated August 20, 2005

1. Quick Install Guide

Installation Media

Download a CD from one of our mirrors. You can find the ISOs in releases/<architecture>/<release>/installcd. The minimal installation CD is only useful for Internet-based installations; with the universal installation CD you can perform a network less installation as well.

Burn the CD and boot it. Press F2 at the boot screen to find out what boot options exist. Once booted, you need to start the pcmcia init script if you need PCMCIA support.

The installation CDs allow you to start an sshd server, add additional users, run irssi (a command-line chat client) and surf the web using lynx or links2.

Network Configuration

If your network does not work already, you can use net-setup to configure your network. You might need to load support for your network card using modprobe prior to the configuration. If you have ADSL, use adsl-setup and adsl-start. For PPTP support, first edit /etc/ppp/chap-secrets and /etc/ppp/options.pptp and then use pptp <server ip>.

For wireless access, use iwconfig to set the wireless parameters and then use either net-setup again or run ifconfig, dhcpcd and/or route manually.

If you are behind a proxy, do not forget to initialize your system using export http_proxy, ftp_proxy and RSYNC_PROXY.

Preparing the Disks

Use fdisk or cfdisk to create your partition layout. You need at least a swap partition (type 82) and one Linux partition (type 83).

Use mke2fs, mke2fs -j, mkreiserfs, mkfs.xfs and mkfs.jfs to create file systems on your Linux partitions. Initialize your swap partition using mkswap and swapon.

Mount the freshly created file systems on /mnt/gentoo. Create directories for the other mount points (like /mnt/gentoo/boot) if you need them.

Setting Up The Stage

First make sure your date is set correctly using date MMDDhhmmYYYY. Next, download a stage from one of our mirrors or use the one available on the installation CD (/mnt/cdrom/stages). Go to /mnt/gentoo and unpack the stage using tar -xvjpf <stage tarball>.

Install a Portage snapshot if you are performing a network less installation: go to /mnt/gentoo/usr and run tar -xvjf /mnt/cdrom/snapshots/<snapshot>. Other users can download a portage snapshot and install it likewise.

For a network less installation, copy over the source code files from /mnt/cdrom/distfiles/ to /mnt/gentoo/usr/portage/distfiles/.

Edit /mnt/gentoo/etc/make.conf to suit your needs (USE flag, CFLAGS and CXXFLAGS). You can use the nano editor for this.

Installing the Gentoo Base System

Mount the /proc file system first, copy over the /etc/resolv.conf file and then chroot into your Gentoo environment.


Code Listing 1.1: Preparing and chrooting

# mount -t proc none /mnt/gentoo/proc
# cp /etc/resolv.conf /mnt/gentoo/etc/
# chroot /mnt/gentoo /bin/bash
# env-update && source /etc/profile

If you are not running a network less installation, issue emerge –sync to update your Portage tree.

Next, make sure /etc/make.profile points to the right profile. The default one should suffice for most users; sub profiles are available for different kernels (like 2.4/ for 2.4-kernel based profiles). Change the profile using ln -sf.

  • Bootstrapping (not available for network less installations) happens using scripts/bootstrap.sh in the /usr/portage directory.
  • System installation (not available for network less installations) happens using emerge -e system (or -N if you haven’t altered the default CFLAGS/CXXFLAGS).

Kernel Configuration

Set your time zone information by changing the /etc/localtime symbolic link to the correct location in /usr/share/zoneinfo using ln -sf.

Install a kernel source (gentoo-sources and vanilla-sources are available for network less installations) and configure it using make menuconfig followed by make &&make modules_install inside /usr/src/linux. Copy the arch/i386/boot/bzImage file over to /boot. You can also emerge genkernel and use genkernel all.

Genkernel users will need to emerge coldplug and rc-update add coldplug default.

Configuring the System

Edit your /etc/fstab; an example follows:


Code Listing 1.2: Example fstab

/dev/hda1   /boot     ext2    defaults,noatime     1 2
/dev/hda2   none      swap    sw                   0 0
/dev/hda3   /         ext3    noatime              0 1
none        /proc     proc    defaults             0 0
none        /dev/shm  tmpfs   nodev,nosuid,noexec  0 0
/dev/cdroms/cdrom0    /mnt/cdrom    auto      noauto,user    0 0

Edit /etc/conf.d/hostname and /etc/conf.d/domainname, run rc-update add domainname default and edit /etc/conf.d/net to configure your network. Add the net.eth0 init script to the default run level. If you have multiple NICs, symlink them to the net.eth0 init script and add them to the default run level as well.

Edit /etc/hosts; examples are given below:


Code Listing 1.3: Example /etc/hosts

(For static IPs)
127.0.0.1     localhost
192.168.0.5   jenny.homenetwork jenny
192.168.0.6   benny.homenetwork benny
192.168.0.7   tux.homenetwork tux

(For a dynamic IP)
127.0.0.1     localhost.homenetwork tux localhost

Emerge pcmcia-cs and add it to the default run level if you need it.

Set the root password using passwd.

Set the necessary system configuration in /etc/rc.conf, /etc/conf.d/rc, /etc/conf.d/keymaps, /etc/conf.d/clock.

Installing System Tools

2.4 kernel users need to emerge –unmerge udev and emerge devfsd.

Install a system logger like syslog-ng and add it to the default run level. Do the same for a cron daemon like vixie-cron (optional).

Install the necessary file system tools (xfsprogs, reiserfsprogs or jfsutils) and networking tools (dhcpcd or rp-pppoe).

Configuring the Bootloader

Emerge grub or lilo. Edit /boot/grub/grub.conf or /etc/lilo.conf to your likings. Below you will find an example for each.


Code Listing 1.4: Example grub.conf

default 0
timeout 30
splashimage=(hd0,0)/grub/splash.xpm.gz

# genkernel users
title=Gentoo Linux 2.6.11-r3
root (hd0,0)
kernel /kernel-genkernel-x86-2.6.11-gentoo-r3 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/hda3 udev
initrd /initramfs-genkernel-x86-2.6.11-gentoo-r3

# non-genkernel users (no initrd)
title=Gentoo Linux 2.6.11 r3
root (hd0,0)
kernel /kernel-2.6.11-gentoo-r3 root=/dev/hda3

# Only in case you want to dual-boot
title=Windows XP
root (hd0,5)
makeactive
chainloader +1


Code Listing 1.5: Example lilo.conf

boot=/dev/hda
prompt
timeout=50
default=gentoo

# For non-genkernel users
image=/boot/kernel-2.6.11-gentoo-r3
  label=gentoo
  read-only
  root=/dev/hda3

# For genkernel users
image=/boot/kernel-genkernel-x86-2.6.11-gentoo-r3
  label=gentoo
  read-only
  root=/dev/ram0
  append="init=/linuxrc ramdisk=8192 real_root=/dev/hda3 udev"
  initrd=/boot/initramfs-genkernel-x86-2.6.11-gentoo-r3

# For dual-booting
other=/dev/hda6
  label=windows

GRUB users need to install GRUB in the MBR using grub-install /dev/hda after copying /proc/mounts to /etc/mtab. LILO users need to run /sbin/lilo.

Exit the chrooted environment, unmount all file systems and reboot.

Finalizing the Installation

Log in as root, then add one or more users for day-to-day use using useradd -m -G <groups> <username>.

If you performed a network less installation, mount the packages CD at /mnt/cdrom and export PKGDIR="/mnt/cdrom" after which you can emerge -k <package> to install additional software like kde.

Thanks for installing Gentoo!


2005年08月23日
天蝎座2005年运程

事业运势:得心应手,颇有成就感天蝎座最佳的职业:警察,律师,补习班老师。

天蝎座的人对工作有权力欲望和野心,不爱说废话,也不爱交际应酬,是实干派,对人有一点冷漠,对工作上有厉害关系的人会保持距离,对于自己定下的目标会不择手段地去完成。

2005年对于天蝎们来说将会是一个充满机遇,有望发展的年份。天王星会一直以其正面的力量给予天蝎们非凡的灵感与创意。配合上半年土星的良好位置,天蝎们行事会相当稳重谨慎,在判断力上也颇为犀利独到,为其成功奠定了良好的基础。不过,下半年的时候,土星与海王星的负面因素将开始慢慢显现,天蝎们将逐渐感受到他们所带来的压力与困惑。

2005年对天蝎的上班一族来说可是颇有成就感的一年呢。在今年,天蝎们对于本职工作可谓得心应手。除了6、7月份需要特别注意一下,年内大部分的时间里,天蝎们都是可以较为轻松的胜任各项工作,并取得不错的业绩。

在2005年,天蝎的求职一族们有不错的求职运气,会较容易得到他人的支持,如自家长辈或是有一些较有能力的年长的朋友帮忙。尤其下半年更是得偿所愿。

感情运势:机会良多,要及时解决感情问题。

天蝎座对既定的目标视为生命的一部分,专情而誓死保护,不容别人批评,也强悍绝不妥协地坚持己爱,没有解释和商量的余地,爱恨分明。

卸下想耍小手段的心机,会让对方觉得更想依附你,未婚者被宴请的机会多,也在不知不觉中燃起爱的火花。如有暗恋的对象在2004年可因为你适度的表达,进而恋情明朗化。但是要特别注意你的热度一定要持续加温,不然恐怕会半途杀出程咬金,夺走所爱。所以在爱情方面最重要的工作是要筑起一个坚固且温馨的城堡,把对方层层包围,但千万别将对方视为禁□,否则只会增加反效果。已婚者需要注意你的伴侣会因你的难以沟通而大搞外遇,应即时的解决问题。属兔、猪、羊、狗者运气较好,爱情方面问题不大;属马、鼠、鸡、龙的朋友运气较差,需小心应战;其他生肖次之。

幸运花:芙蓉 幸运宝石:欧泊石

风水感情增运法:天蝎座的你要在西南方放置一面大型的镜子,并在镜子上方挂一个小香包,可以增加你的异性缘,让你把他电得麻麻的!而将一小袋盐包放在衣橱中,可除去恋爱时的种种阻碍。

爱的咒语:Ohm-skoh-ree-pay-ohs-ohm 当遇上困难,轻声诵读五次,并配合以下的愿望:“我愿意控制自己的情绪和坏脾气,让守护神以他的灵光启发我,带领我进入更深层的感情世界,了解爱情的奥妙。多谢法老。”

  【牡羊座(ARIES)03/21-04/19】

  ●张飞-牡羊座

  长阪坡上张飞据水断桥一声大喝,惊得曹军人仰马翻而退。展现牡羊座豪侠爽快、一马当先的精神。

【金牛座(TAURUS)04/20-05/20】

  ●董卓-金牛座

  董卓大权在握後到处收刮百姓,并在长安成外,别筑郿坞,藏尽天下金银财宝,俊男少女,与美人貂蝉共享荣华富贵,可说是个会享受的金牛座。

【双子座(GEMINI)05/21-06/21】

  ●杨修-双子座

  杨修,博学能文,才思过人,後因多言贾祸,被曹操以扰乱军心的罪名斩首。双子座善於言语也困於言语。

【巨蟹座(CANCER)06/22-07/22】

  ●曹植-巨蟹座

  曹植十岁时即能写出很漂亮的文章,才思敏捷,下笔成章。曹丕即帝後,忌其才华,欲杀曹植,但曹植七步成诗感动曹丕,展现了巨蟹座之亲情感人。

【狮子座(LEO)07/23-08/22】

  ●关公-狮子座

  过五关斩六将的关公说:「吾极知曹公待我厚,然吾受刘将军厚恩,誓以共死,不可背之。吾终不留,吾要当立效以报曹公乃去。显示狮子座光明磊落之作风。

【处女座(VIRGO)08/23-09/22】

  ●处女座-周瑜

  出身官宦之家,仪表英俊,聪颖过人,多谋略,为人器量狭小,阴狠刻毒,见诸葛亮比自己高明,便处处加以暗算。处女座多才多艺只是心胸不宽。

【天秤座(LIBRA)09/23-10/22】

  ●吕布-天平座

  吕布号称:"飞将军",三国时代最优秀的武将。一生有勇无谋,反覆无常,英雄气短,儿女情长。是天秤之优点也是缺点。

【天蝎座(SCORPIO)10/23-11/21】

  ●诸葛亮-天蝎座

  自比管仲乐毅,一生忠心辅佐刘备,精通阴阳五行,善能步罡踏斗,料敌如神,善於用计,是个标准的神秘兮兮天蝎座。

【射手座(SAGITTARIUS)11/22-12/21】

  ●华陀-人马座

  精通内科、儿科、妇科、针灸,用"麻沸散"使病人麻醉,施行剖腹手术,外号"神医"。後为曹操治病因尊重专业太过直言而被杀。人马座向来以医术和直爽见称於世。

【魔羯座(CAPRICORN)12/22-01/19】

  ●曹操-魔羯座

  从小聪明机警,有侠气。被人评为「治世之能臣,乱世之奸雄」,一生用人重才不重德,只求达到目的不择手段,是标准的魔羯座。

【水瓶座(AQUARIUS)01/22-02/18】

  ●庞统-宝瓶座

  号称凤雏,与诸葛亮齐名。其貌不扬,向曹操献连环计,成为赤壁之战的胜负关键。为一天才型之宝瓶座代表人物。

【双鱼座(PISCES)02/19-03/20】

  ●刘备-双鱼座

  这是对(三)中问题的一些思考。

  对于一个Bean来说,如果它含有对自己属于检验的函数,我就把它叫做可以自检的Bean,反之就称做非自检函数,非自检的函数就需要其它人(主要是Action)的监督。

  以一个Person类为例。

  public class Person{

            …

             private int age;

             public void setAge(int age){this.age=age;}

             public int getAge(){return this.age;}

             …

        }

  这个Bean中并没有任何检测,这样的Bean在应用中会出现很多问题,比如说一个人的年龄为负数,这显然是不合理的。但这个检测应该由谁来做呢?由Bean自己来做,还是由Action来做?

  这就是一个自检和监督的问题,我们应该更侧重哪一方面?

  我个人而言,我更侧重于监督,自检为了适应更广泛的应用,只能对Bean较少的,最基本的检测,而其它大部分的事情都应该由其它人来做。

对于每一个Action来说,都应在Monitor中对Action的监督条件进行说明,由Monitor来进行监督,Action将所有监督的职责交给Monitor

监督的好处:

1.    Bean来说,他只存储信息,对Action来说,他只处理业务逻辑,而其中的所有检测工作都交给了Monitor

2.    检测条件有时候会发生改变,对于不同的Action改变会有所不同,但是他们可能应用同一个Bean。在条件发生改变时,针对Action只改变Monitor中的检测即可。

3.    BeanAction都从数据检测中脱离出来,加强数据的整洁度。

个人想法,希望会对大家有用。

2005年08月22日

  今天在做东西的时候发现关于validate的一点点问题。

  struts在对bean的验证时,把这个任务交给了bean,但是我感觉对bean这项工作应该交给action。

  我觉得应该由Action决定Bean有什么样的权力或者说属性值,虽然说Bean应该了解自己,也就是说Bean应该来验证它自己是否合格,但是对于不同的Action来说,不同的Bean有不同的属性值,就像一个人是否生病,虽然可以由自己进行判断,但是还是应该由医生来诊判。并且在诊判的时候来要去不同的部门。这是将Bean应用于不同的Action的一种想法,但是如果将Bean应用于完全相同的Action中的话,那么应该是在Bean中验证的,这样减轻的Action的负担。

  这只是我一时的想法,也许设计者在设计的时候想到的更多,在做了权衡之后才选择了这种方案。希望理解的人能够解除我的困惑。

维基百科,自由的百科全书

        运动补偿是一种描述相邻帧(相邻在这里表示在编码关系上相邻,在播放顺序上两帧未必相邻) 差别的方法,具体来说是描述前面一帧(相邻在这里表示在编码关系上的前面,在播放顺序上未必在当前帧前面)的每个小块怎样移动到当前帧中的某个位置去。这种方法经常被视频压缩/视频编解码器用来减少视频序列中的空域冗余。它也可以用来进行去交织(deinterlacing)的操作。

一个视频序列包含一定数量的图片–通常称为。相邻的图片通常很相似,也就是说,包含了很多冗余。使用运动补偿的目的是通过消除这种冗余,来提高压缩比。

最早的运动补偿的设计只是简单的从当前帧中减去参考帧,从而得到通常含有较少能量(或者成为信息)的"残差",从而可以用较低的码率进行编码。解码器可以通过简单的加法完全恢复编码帧。

一个稍微复杂一点的设计是估计一下整帧场景的移动和场景中物体的移动,并将这些运动通过一定的参数编码到码流中去。这样预测帧上的像素值就是由参考帧上具有一定位移的相应像素值而生成的。这样的方法比简单的相减可以获得能量更小的残差,从而获得更好的压缩比–当然,用来描述运动的参数不能在码流中占据太大的部分,否则就会抵消复杂的运动估计带来的好处。

通常,图像帧是一组一组进行处理的。每组的第一帧(通常是第一帧)在编码的时候不使用运动估计的办法,这种帧称为帧内编码帧(Intra frame)或者I帧。该组中的其它帧使用帧间编码帧(Inter frame),通常是P帧。这种编码方式通常被称为IPPPP,表示编码的时候第一帧是I帧,其它帧是P帧

在进行预测的时候,不仅仅可以从过去的帧来预测当前帧,还可以使用未来的帧来预测当前帧。当然在编码的时候,未来的帧必须比当前帧更早的编码,也就是说,编码的顺序和播放的顺序是不同的。通常这样的当前帧是使用过去和未来的I帧或者P帧同时进行预测,被称为双向预测帧,即B帧。这种编码方式的编码顺序的一个例子为 IBBPBBPBBPBB。

目录

[隐藏]

全局运动补偿

全局运动补偿中, 运动模型基本上就是反映摄像机的各种运动,包括平移,旋转,变焦等等。这种模型特别适合对没有运动物体的静止场景的编码。 全局运动补偿有下面的一些优点:

  • 该模型仅仅使用少数的参数对全局的运行进行描述,参数所占用的码率基本上可以忽略不计。
  • 该方法不对帧进行分区编码,这避免了分区造成的块效应。
  • 在时间方向的一条直线的点如果在空间方向具有相等的间隔,就对应了在实际空间中连续移动的点。其它的运动估计算法通常会在时间方向引入非连续性。

但是,缺点是,如果场景中有运动物体的话,全局运动补偿就不足以表示了。这时候应该选用其它的方法。

分块运动补偿

在分块运动补偿 (BMC for block motion compensation) 中,每帧被分为若干像素块 (在大多数视频编码标准,如MPEG中,是分为16×16的像素块)。从参考帧的某个位置的等大小的块对当前块进行预测,预测的过程中只有平移,平移的大小被称为运动矢量

对分块运动补偿来说,运动矢量是模型的必要参数,必须一起编码加入码流中。由于运动矢量之间并不是独立的(例如属于同一个运动物体的相邻两块通常运动的相关性很大),通常使用差分编码来降低码率。这意味着在相邻的运动矢量编码之前对它们作差,只对差分的部分进行编码。使用熵编码对运动矢量的成分进行编码可以进一步消除运动矢量的统计冗余(通常运动矢量的差分集中于0矢量附近)。

运动矢量的值可以是非整数的,此时的运动补偿被称为亚像素精度的运动补偿。这是通过对参考帧像素值进行亚像素级插值,而后进行运动补偿做到的。最简单的亚像素精度运动补偿使用半像素精度,也有使用1/4像素和1/8像素精度的运动补偿算法。更高的亚像素精度可以提高运动补偿的精确度,但是大量的插值操作大大增加了计算复杂度。

分块运动补偿的一个大缺点在于在块之间引入的非连续性,通常称为块效应。当块效应严重时,解码图像看起来会有像马赛克一样的效果,严重影响视觉质量。另外一个缺点是,当高频分量较大时,会引起振铃效应。关于高频分量,请参见对运动补偿后的残差进行变换的方法: 变换编码

变块大小运动补偿

Variable block-size motion compensation (VBSMC) is the use of BMC with the ability for the encoder to dynamically select the size of the blocks. When coding video, the use of larger blocks can reduce the number of bits needed to represent the motion vectors, while the use of smaller blocks can result in a smaller amount of prediction residual information to encode. Older designs such as H.261 and MPEG-1 video typically use a fixed block size, while newer ones such as H.263, MPEG-4 Part 2, H.264/MPEG-4 AVC, and VC-1 give the encoder the ability to dynamically choose what block size will be used to represent the motion.


Overlapped分块运动补偿

Overlapped block motion compensation (OBMC) is a good solution to these problems because it not only increases prediction accuracy but also avoids blocking artifacts. When using OBMC, blocks are typically twice as big in each dimension and overlap quadrant-wise with all 8 neighbouring blocks. Thus, each pixel belongs to 4 blocks. In such a scheme, there are 4 predictions for each pixel which are summed up to a weighted mean. For this purpose, blocks are associated with a window function that has the property that the sum of 4 overlapped windows is equal to 1 everywhere.

Studies of methods for reducing the complexity of OBMC have shown that the contribution to the window function is smallest for the diagonally-adjacent block. Reducing the weight for this contribution to zero and increasing the other weights by an equal amount leads to a substantial reduction in complexity without a large penalty in quality. In such a scheme, each pixel then belongs to 3 blocks rather than 4, and rather than using 8 neighboring blocks, only 4 are used for each block to be compensated. Such a scheme is found in the H.263 Annex F Advanced Prediction mode.

运动估计

Motion estimation (BME, OBME) is the process of finding optimal or near-optimal motion vectors. The amount of prediction error for a block is often measured using the mean squared error (MSE) or sum-of-absolute-differences (SAD) between the predicted and actual pixel values over all pixels of the motion-compensated region.

To find optimal motion vectors, one basically has to calculate the block prediction error for each motion vector within a certain search range and pick the one that has the best compromise between the amount of error and the number of bits needed for motion vector data. The motion estimation technique of simply exhaustively testing all possible motion representations to perform such an optimization is called full search. A faster and sub-optimal method is to use a coarse search grid for a first approximation and to refine the grid in the surrounding of this approximation in further steps. One common method is the 3-step search, which uses search grids of 3×3 motion vectors and 3 refinement steps to get an overall search range of 15×15 pixel.

For OBME, the pixel-wise prediction errors of a block and its overlapping neighbouring blocks have to be weighted and summed according to the window function before being squared. As in the process of successively finding/refining motion vectors some neighbouring MVs are not known yet, the corresponding prediction errors can be ignored (not added) as a sub-optimal solution.

The major disadvantages of OBMC are increased computational complexity of OBME, and the fact that prediction errors and, thus, also the optimal motion vectors depend on neighbouring blocks/motion vectors. Therefore, there is no algorithm with polynomial computational complexity that guarantees optimal motion vectors. However, there are near-optimal iterative and non-iterative methods with acceptable computational complexity.