varnish,squid,apache,nginx缓存文件比较

一,测试环境

1,硬件是奔腾双核,机子三年前买的。系统是archlinux

2,测试varnish和squid的时候,web服务用的apache

3,测试apache的时候,启动了5个进程,不过随着压力的增加,进程会增加的。

4,测试nginx的时候,启动了十个nginx进程,20个php-cgi进程

 

5,varnish,squid,nginx用的是反向代理的形势,也就是说访问图片的时候,要先透过缓存工具

二,测试

1,varnish

[root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.

Speed=476508 pages/min, 47258114 bytes/sec.
Requests: 158836 susceed, 0 failed.

访问了这么次,没有缓存只有一次,效率真的很高。

2,squid

[root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.

Speed=133794 pages/min, 7475018 bytes/sec.
Requests: 44598 susceed, 0 failed.

从测试效果来说,squid挺让我失望的,在测试前,我心里是这样估计的,缓存最好的是varnish,其次是squid,然后nginx,最后是apache,现在呢,squid是最差的。后来我看了一下log文件,发现正常情况下,缓存和没有缓存的比率不是1:2,如果在高压力下,缓存和没有缓存的比率更小。

3,apache

[root@BlackGhost conf]# /usr/local/bin/webbench -c 100 -t 20 http://localhost/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.

Speed=160890 pages/min, 15856005 bytes/sec.
Requests: 53630 susceed, 0 failed.

4,nginx

[root@BlackGhost conf]# /usr/local/bin/webbench -c 100 -t 20 http://localhost:10000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost:10000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.

Speed=304053 pages/min, 30121517 bytes/sec.
Requests: 101351 susceed, 0 failed.

从上面的测试结果我们可以发现,varnish > nginx > apache > squid,我想这个结果,根大家预期的结果有点出入,因为squid做老牌文件缓存工具怎么会这么差呢,squid的命中率低,我在网上查了一下,很多人都是这样的,这个可能根个人配置有关系,也许真正的高手,才能让squid发挥最大功力。

原文地址:http://blog.51yip.com/server/1032.html

初步试用Squid的替代产品──Varnish Cache网站加速器

Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang (vg.no) 使用3台Varnish代替了原来的12台squid,性能比以前更好。

Varnish的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多。在1975年时,储存媒介只有两种:内存与硬盘。但现在计算机系统的内存除了主存外,还包括了cpu内的L1、L2,甚至有L3快取。硬盘上也有自己的快取装置,因此squid cache自行处理物件替换的架构不可能得知这些情况而做到最佳化,但操作系统可以得知这些情况,所以这部份的工作应该交给操作系统处理,这就是Varnish cache设计架构。

Varnish可以在FreeBSD 6.0和Linux 2.6内核上运行。

1、编译安装varnish HTTP加速器:

引用
wget http://blog.s135.com/soft/linux/varnish/varnish-1.1.1.tar.gz
tar zxvf varnish-1.1.1.tar.gz
cd varnish-1.1.1
./configure –prefix=/usr/local/varnish
make && make install

2、简单启动varnish守护进程,用本机80端口去反向代理加速127.0.0.1:81上的Apache服务器:

引用
/usr/local/varnish/sbin/varnishd -a :8080 -b 127.0.0.1:81 -p thread_pool_max=1500 -p thread_pools=5 -p listen_depth=512 -p client_http11=on -w 1,10000,120

Varnish官方网站:http://www.varnish-cache.org/

另有一份PDF文档,说明Varnish原理的:http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=2163384

我测试了一下,在同等配置环境下,Varnish的性能确实要超过Squid,稳定性也不错,值得继续去深入研究。

 

原文地址:http://blog.s135.com/post/290/

使用Varnish代替Squid做网站缓存加速器的详细解决方案

今天写的这篇关于Varnish的文章,已经是一篇可以完全替代Squid做网站缓存加速器的详细解决方案了。网上关于Varnish的资料很少,中文资料更是微乎其微,希望本文能够吸引更多的人研究、使用Varnish。
在我看来,使用Varnish代替Squid的理由有三点:
1、Varnish采用了“Visual Page Cache”技术,在内存的利用上,Varnish比Squid具有优势,它避免了Squid频繁在内存、磁盘中交换文件,性能要比Squid高。
2、Varnish的稳定性还不错,我管理的一台图片服务器运行Varnish已经有一个月,没有发生过故障,而进行相同工作的Squid服务器就倒过几次。
3、通过Varnish管理端口,可以使用正则表达式快速、批量地清除部分缓存,这一点是Squid不能具备的。

点击在新窗口中浏览此图片


下面来安装Varnish网站缓存加速器(Linux系统):
1、创建www用户和组,以及Varnish缓存文件存放目录(/var/vcache):

/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /var/vcache
chmod +w /var/vcache
chown -R www:www /var/vcache

2、创建Varnish日志目录(/var/logs/):

mkdir -p /var/logs
chmod +w /var/logs
chown -R www:www /var/logs

3、编译安装varnish:

wget http://blog.s135.com/soft/linux/varnish/varnish-1.1.2.tar.gz
tar zxvf varnish-1.1.2.tar.gz
cd varnish-1.1.2
./configure –prefix=/usr/local/varnish
make && make install

4、创建Varnish配置文件:

vi /usr/local/varnish/vcl.conf

输入以下内容:

引用
backend myblogserver {
set backend.host = “192.168.0.5”;
set backend.port = “80”;
}

acl purge {
“localhost”;
“127.0.0.1”;
“192.168.1.0”/24;
}

sub vcl_recv {
if (req.request == “PURGE”) {
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
lookup;
}

if (req.http.host ~ “^blog.s135.com”) {
set req.backend = myblogserver;
if (req.request != “GET” && req.request != “HEAD”) {
pipe;
}
else {
lookup;
}
}
else {
error 404 “Zhang Yan Cache Server”;
lookup;
}
}

sub vcl_hit {
if (req.request == “PURGE”) {
set obj.ttl = 0s;
error 200 “Purged.”;
}
}

sub vcl_miss {
if (req.request == “PURGE”) {
error 404 “Not in cache.”;
}
}

sub vcl_fetch {
if (req.request == “GET” && req.url ~ “\.(txt|js)$”) {
set obj.ttl = 3600s;
}
else {
set obj.ttl = 30d;
}
}

这里,我对这段配置文件解释一下:
(1)、Varnish通过反向代理请求后端IP为192.168.0.5,端口为80的web服务器;
(2)、Varnish允许localhost、127.0.0.1、192.168.0.***三个来源IP通过PURGE方法清除缓存;
(3)、Varnish对域名为blog.s135.com的请求进行处理,非blog.s135.com域名的请求则返回“Zhang Yan Cache Server”;
(4)、Varnish对HTTP协议中的GET、HEAD请求进行缓存,对POST请求透过,让其直接访问后端Web服务器。之所以这样配置,是因为POST请求一般是发送数据给服务器的,需要服务器接收、处理,所以不缓存;
(5)、Varnish对以.txt和.js结尾的URL缓存时间设置1小时,对其他的URL缓存时间设置为30天。

5、启动Varnish

ulimit -SHn 51200
/usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on

6、启动varnishncsa用来将Varnish访问日志写入日志文件:

/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/varnish.log &

7、配置开机自动启动Varnish

vi /etc/rc.local

在末尾增加以下内容:

引用
ulimit -SHn 51200
/usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on
/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/youvideo.log &

8、优化Linux内核参数

vi /etc/sysctl.conf

在末尾增加以下内容:

引用
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000    65000

 


再看看如何管理Varnish:
1、查看Varnish服务器连接数与命中率:

/usr/local/varnish/bin/varnishstat

点击在新窗口中浏览此图片

2、通过Varnish管理端口进行管理:
用help看看可以使用哪些Varnish命令:

/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 help

 

引用
Available commands:
ping [timestamp]
status
start
stop
stats
vcl.load
vcl.inline
vcl.use
vcl.discard
vcl.list
vcl.show
param.show [-l] []
param.set
help [command]
url.purge
dump.pool

3、通过Varnish管理端口,使用正则表达式批量清除缓存:
(1)、例:清除类似http://blog.s135.com/a/zhangyan.html的URL地址):

/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge /a/

(2)、例:清除类似http://blog.s135.com/tech的URL地址:

/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge w*$

(3)、例:清除所有缓存:

/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge *$

4、一个清除Squid缓存的PHP函数(清除Varnish缓存同样可以使用该函数,无需作任何修改,十分方便):

  1. <?php
  2. function purge($ip, $url)
  3. {
  4.     $errstr = ”;
  5.     $errno = ”;
  6.     $fp = fsockopen ($ip, 80, $errno, $errstr, 2);
  7.     if (!$fp)
  8.     {
  9.          return false;
  10.     }
  11.     else
  12.     {
  13.         $out = “PURGE $url HTTP/1.1\r\n”;
  14.         $out .= “Host:blog.s135.com\r\n”;
  15.         $out .= “Connection: close\r\n\r\n”;
  16.         fputs ($fp, $out);
  17.         $out = fgets($fp , 4096);
  18.         fclose ($fp);
  19.         return true;
  20.     }
  21. }
  22. purge(“192.168.0.4”, “/index.php”);
  23. ?>

附1:Varnish官方网站:http://www.varnish-cache.org/

附2:2007年12月10日,我写了一个每天0点运行,按天切割Varnish日志,生成一个压缩文件,同时删除上个月旧日志的脚本(/var/logs/cutlog.sh):
/var/logs/cutlog.sh文件内容如下:

引用
#!/bin/sh
# This file run at 00:00
date=$(date -d “yesterday” +”%Y-%m-%d”)
pkill -9 varnishncsa
mv /var/logs/youvideo.log /var/logs/${date}.log
/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/youvideo.log &
mkdir -p /var/logs/youvideo/
gzip -c /var/logs/${date}.log > /var/logs/youvideo/${date}.log.gz
rm -f /var/logs/${date}.log
rm -f /var/logs/youvideo/$(date -d “-1 month” +”%Y-%m*”).log.gz

设置在每天00:00定时执行:

/usr/bin/crontab -e

或者

vi /var/spool/cron/root

输入以下内容:

引用
0 0 * * * /bin/sh /var/logs/cutlog.sh

 

 

原文地址:http://blog.s135.com/post/313/

15 Best iPhone Games Of June 2011 You Love To Play

Apple is most popular multinational corporation that designs-  Personal Computers, iPhone, iPad, Laptop(MacBook), iPod with the  best known operating system Macintosh( Mac OS x). Now a days, this organization is growing day by day with its new technologies and gadgets like iPhone 4, Macbook Air, OS x Lion etc. Apple has a great bond with its users and always try to make place among gadget geeks and whom crazy for new and fresh technologies. Two months ago. Apple hits millstone- Apple’s iTunes App store has more than 500000 application. Apple announced on Thursday hits millstone – 15 billion downloads applications.

Apple has a big collection of Application in every section like – Business, Games, Lifestyle, Music, Social Media, News, Design, Development and many more has huge collection of Apps. Today we are going to share best iPhone games of June 2011.

 

I have been searching best games for your iPhone and finally i got the Best iPhone games of June 2011 for having fun and enjoy.

Few days ago, we had been provided best free Android games and 3d Linux games.  Thanks a lot to our readers for appreciate these articles.  I hope iPhone users will love to plays these games and share their views in comment section below.

1) Army Of Darkness Defence

 

2) Burger Queen

3) Flick Golf Extreme

The most addictive golf game to blaze its way onto the App Store. Incredibly simple to play, just flick the ball and hit the hole. Our trademark spin control, combined with insanely fun gameplay brings you the world’s first truly extreme golf game.

 

4) Mortal Kombat

“FINISH HIM!” Fight as all 23 Klassic Warriors from the original Ultimate Mortal Kombat 3, including Cyrax, Sektor, Scorpion, Kabal, and Reptile…Experience multiple game modes, fully kustomizable controls, and updated visuals maximizing Retina Display…Relive the brutal kombos and vicious fatalities that made Mortal Kombat one of the most iconic fighting game series EVER!

5) Bit Ninja

 

6) Sonic All Star Racing

The world’s fastest hedgehog, Sonic, and the SEGA All-Stars are zooming on to your iPhone and iPad for the ultimate party racing showdown. Race as your favorite character across 15 white-knuckle courses in a frantic race to the finish line.

7) Ducati Challenge

Get ready for breathtaking challenges and unique thrills riding official Ducati motorbikes in a graphically stunning 3D racing game – supporting the retina display. Wheelies, stoppies, overtaking, high speed and steering precision make Ducati Challenge a must-have game for Ducati and motorbike fans alike.

8 ) Toast And Chicken

“Toast the Chicken is a new experience for puzzle game aficionados”. Toast The Chicken is an unique and challenging puzzle game where you have to toast all the chickens with fire.

9) BalliStik Wars

Spray of missiles! Smashing super weapons!
Produce units with single tap. Light-hearted strategy game!
This is “Ballistik Wars”!

10) ToFu

 

11) Boost2

Boost 2 features –
Three brand new game modes, including online multiplayer
A completely redesigned interface and HUD
Game Center and OpenFeint with online leaderboards and achievements

 

12) Mighty Fin

Mighty Fin is an addictive arcade game that’s easy to pick up, hard to master… and impossible to put down. The controls are simple: touch the screen to dive and let go to soar through the air.

12) Feed Me Oil

 

13) Superbrothers

14) Mod Speedrun

Jump, dodge and race Mos through 25 glorious stages of fast paced retro platforming action! Get ready for a real gaming challenge on your phone!

 

15) X-men

 

 

http://zoomzum.com/best-iphone-games-of-june-2011/

android:SQLite数据库 增、删、改、查

学习android开发不可避免的会涉及数据库的使用,android使用的是SQLite数据库。对于SQLite数据库的基本信息这里就不过多的介绍,我们主要看哈是怎么用的就是了。

与以往数据库不一样的地方

以前我们做javaWeb开发时用jdbc连接,现在变了,个人觉得变得简单了。在应用程序中直接就可以去创建数据库,然后对其进行操作。不用像以前写连接代码。

操作数据库

一,SQLiteOpenHelper 类

其中:

getReadableDatabase()得到可读的数据库,返回SQLiteDatabase对象,然后通过对象进行数据库操作。

getWritableDatabase()得到可写的数据库,返回SQLiteDatabase对象,然后通过对象进行数据库操作。

onCreate(SQLiteDatabase db)在第一次创建数据库时调用。

onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)在更改数据库时都会调用。

onOpen(SQLiteDatabase db)当数据库打开时调用。

close()关闭数据库。

二,SQLiteDatabase类

这个类提供了对数据库的一些基本操作:

insert()

delete()

update()

query()

。。。。。等等。

代码:

SQLiteOpenHelper 的子类:

  1. import android.content.Context;
  2. import android.database.sqlite.SQLiteDatabase;
  3. import android.database.sqlite.SQLiteDatabase.CursorFactory;
  4. import android.database.sqlite.SQLiteOpenHelper;
  5. /**
  6.  * 通过getReadableDatabase()和getWritableDatabase()可以获得数据库对象。
  7.  * 提供onCreate()-创建数据库时,onUpgrade()-升级数据库时,两个回调函数。
  8.  */
  9. public class DatabaseHelper extends SQLiteOpenHelper {
  10.     // 按要求必须要有构造函数
  11.     public DatabaseHelper(Context context, String name, CursorFactory factory,
  12.             int version) {
  13.         super(context, name, factory, version);
  14.     }
  15.     // 当第一次得到SQLiteDatabase对象时,调用该方法
  16.     @Override
  17.     public void onCreate(SQLiteDatabase db) {
  18.         String sql = “create table MSG(id int,body varchar(100))”;
  19.         db.execSQL(sql);
  20.         System.out.println(“创建了一个数据库!”);
  21.     }
  22.     // 当更新数据库时执行该方法
  23.     @Override
  24.     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  25.         System.out.println(“更新了数据库!”);
  26.         // 还可以写其他的操作
  27.     }
  28. }

有了这个类后,我们就可以对数据库进行增、删、改、查操作了。
插入数据:

  1. //生成ContentValues对象,key:列名,value:想插入的值
  2.                 ContentValues values = new ContentValues();
  3.                 values.put(“id”, 1);
  4.                 values.put(“body”, “hello”);
  5.                 DatabaseHelper dbhelper = new DatabaseHelper(SqliteActivity.this, “text_msg”, null, 2);
  6.                 //得到可写的SQLiteDatabase对象
  7.                 SQLiteDatabase db = dbhelper.getWritableDatabase();
  8.                 //调用insert方法,将数据插入数据库
  9.                 //参数1:表名
  10.                 //参数2:如果你想插入空值,那么你必须指定它的所在的列
  11.                 db.insert(“MSG”, null, values);
  12.                 System.out.println(“插入了:1, hello”);

删除数据:

  1. DatabaseHelper dbhelper = new DatabaseHelper(SqliteActivity.this, “text_msg”, null, 2);
  2.                 //得到可写的SQLiteDatabase对象
  3.                 SQLiteDatabase db = dbhelper.getWritableDatabase();
  4.                 //调用delete方法,删除数据
  5.                 db.delete(“MSG”, “id=?”, new String[]{“1”});
  6.                 System.out.println(“删除了:id=1”);

修改数据:

  1. ContentValues values = new ContentValues();
  2.                 values.put(“body”, “my dear!”);
  3.                 DatabaseHelper dbhelper = new DatabaseHelper(SqliteActivity.this, “text_msg”, null, 2);
  4.                 //得到可写的SQLiteDatabase对象
  5.                 SQLiteDatabase db = dbhelper.getWritableDatabase();
  6.                 //调用insert方法,将数据插入数据库
  7.                 //参数3:where 子句 “?”是占位符号,对应后面的”1”,这和web开发时的语法是一样的
  8.                 db.update(“MSG”, values, “id=?”, new String[]{“1”});
  9.                 System.out.println(“更新了:hello–>my dear!”);

查询数据:

  1. DatabaseHelper dbhelper = new DatabaseHelper(SqliteActivity.this, “text_msg”, null, 2);
  2.                 //得到可读的SQLiteDatabase对象
  3.                 SQLiteDatabase db = dbhelper.getReadableDatabase();
  4.                 //参数1:表名
  5.                 //参数2:要想显示的列
  6.                 //参数3:where子句
  7.                 //参数4:where子句对应的条件值
  8.                 //参数5:分组方式
  9.                 //参数6:having条件
  10.                 //参数7:排序方式
  11.                 Cursor cursor = db.query(“MSG”, new String[]{“id”,”body”}, “id=?”, new String[]{“1”}, null, null, null);
  12.                 System.out.println(“查到的数据为:”);
  13.                 while(cursor.moveToNext()){
  14.                         int id = cursor.getInt(cursor.getColumnIndex(“id”));
  15.                         String name = cursor.getString(cursor.getColumnIndex(“body”));
  16.                         System.out.println(“–>”+id+”::::::::::”+name);
  17.                     }

怎样使用adb查看数据库?

SQLite没有客户端,不能直接的查看数据库,所以用它提供的adb吧。

1,进入命令行后输入adb回车,会显示很多的信息。

2,输入adb shell回车,就进入了Linux命令行,现在就可以使用Linux的命令了。

3,ls回车,显示所有的东西,其中有个data。(ls:显示所有,cd:进入)

4,cd data回车,再ls回车,cd data回车,ls回车后就会看到很多的com.。。。的东西,那就是机器上的应用程序,找到你应用程序的包名,然后进入。

5,进去后在查看所有,会发现个databases,进入databases,显示所有就会发现你的数据库名字,我这里使用的是”text_msg”。

6,sqlite3 text_msg回车就进入了你的数据库了,然后“.schema”就会看到该应用程序的所有表及建表语句。

7,现在你就可以使用标准的SQL语句查看刚才生成的数据库及数据了。

对数据库的操作方法很多,这只是其中一种。

原文地址:http://blog.csdn.net/zzy916853616/article/details/6599898

Android 盘点所有Dialog 对话框 大合集 详解

雨松MOMO带大家盘点Android 中的对话框

今天我用自己写的一个Demo 和大家详细介绍一个Android中的对话框的使用技巧。


1.确定取消对话框

对话框中有2个按钮   通过调用 setPositiveButton 方法 和 setNegativeButton 方法 可以设置按钮的显示内容以及按钮的监听事件。

我们使用AlerDialog 创建对话框

  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);

使用builder设置对话框的title button icon 等等

  1. builder.setIcon(R.drawable.icon);
  2.        builder.setTitle(“你确定要离开吗?”);
  3.        builder.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
  4.            public void onClick(DialogInterface dialog, int whichButton) {
  5.                //这里添加点击确定后的逻辑
  6.                showDialog(“你选择了确定”);
  7.            }
  8.        });
  9.        builder.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {
  10.            public void onClick(DialogInterface dialog, int whichButton) {
  11.                //这里添加点击确定后的逻辑
  12.                showDialog(“你选择了取消”);
  13.            }
  14.        });
  15.        builder.create().show();

这个dialog用于现实onClick后监听的内容信息

  1. private void showDialog(String str) {
  2. w AlertDialog.Builder(MainDialog.this)
  3.      .setMessage(str)
  4.      .show();
  5. }

2.多个按钮信息框

  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);
  2. builder.setIcon(R.drawable.icon);
  3. builder.setTitle(“投票”);
  4. builder.setMessage(“您认为什么样的内容能吸引您?”);
  5. builder.setPositiveButton(“有趣味的”, new DialogInterface.OnClickListener() {
  6.     public void onClick(DialogInterface dialog, int whichButton) {
  7.         showDialog(“你选择了有趣味的”);
  8.     }
  9. });
  10. builder.setNeutralButton(“有思想的”, new DialogInterface.OnClickListener() {
  11.     public void onClick(DialogInterface dialog, int whichButton) {
  12.         showDialog(“你选择了有思想的”);
  13.     }
  14. });
  15. builder.setNegativeButton(“主题强的”, new DialogInterface.OnClickListener() {
  16.     public void onClick(DialogInterface dialog, int whichButton) {
  17.         showDialog(“你选择了主题强的”);
  18.     }
  19. });
  20. builder.create().show();

3.列表框

这个数组用于列表选择

  1. final String[] mItems = {“item0″,”item1″,”itme2″,”item3″,”itme4″,”item5″,”item6”};
  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);
  2.         builder.setTitle(“列表选择框”);
  3.         builder.setItems(mItems, new DialogInterface.OnClickListener() {
  4.             public void onClick(DialogInterface dialog, int which) {
  5.                 //点击后弹出窗口选择了第几项
  6.                 showDialog(“你选择的id为” + which + ” , ” + mItems[which]);
  7.             }
  8.         });
  9.         builder.create().show();

4.单项选择列表框

mSingleChoice 用于记录单选中的ID

  1. int mSingleChoiceID = -1;
  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);
  2. mSingleChoiceID = -1;
  3. builder.setIcon(R.drawable.icon);
  4.     builder.setTitle(“单项选择”);
  5.     builder.setSingleChoiceItems(mItems, 0, new DialogInterface.OnClickListener() {
  6.         public void onClick(DialogInterface dialog, int whichButton) {
  7.                 mSingleChoiceID = whichButton;
  8.                 showDialog(“你选择的id为” + whichButton + ” , ” + mItems[whichButton]);
  9.         }
  10.     });
  11.     builder.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
  12.         public void onClick(DialogInterface dialog, int whichButton) {
  13.             if(mSingleChoiceID > 0) {
  14.             showDialog(“你选择的是” + mSingleChoiceID);
  15.             }
  16.         }
  17.     });
  18.     builder.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {
  19.         public void onClick(DialogInterface dialog, int whichButton) {
  20.         }
  21.     });
  22.    builder.create().show();

5.进度条框

点击进度条框按钮后 开启一个线程计算读取的进度 假设读取结束为 100
Progress在小于100的时候一直在线程中做循环++ 只到读取结束后,停止线程。

  1.           mProgressDialog = new ProgressDialog(MainDialog.this);
  2.      mProgressDialog.setIcon(R.drawable.icon);
  3.      mProgressDialog.setTitle(“进度条窗口”);
  4.      mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  5.      mProgressDialog.setMax(MAX_PROGRESS);
  6.      mProgressDialog.setButton(“确定”, new DialogInterface.OnClickListener() {
  7.          public void onClick(DialogInterface dialog, int whichButton) {
  8.              //这里添加点击后的逻辑
  9.          }
  10.      });
  11.      mProgressDialog.setButton2(“取消”, new DialogInterface.OnClickListener() {
  12.          public void onClick(DialogInterface dialog, int whichButton) {
  13.              //这里添加点击后的逻辑
  14.          }
  15.      });
  16.      mProgressDialog.show();
  17.      new Thread(this).start();
  18. ic void run() {
  19. int Progress = 0;
  20. while(Progress < MAX_PROGRESS) {
  21. try {
  22.     Thread.sleep(100);
  23.     Progress++;
  24.     mProgressDialog.incrementProgressBy(1);
  25. } catch (InterruptedException e) {
  26.     // TODO Auto-generated catch block
  27.     e.printStackTrace();
  28. }
  29. }

6.多项选择列表框

MultiChoiceID 用于记录多选选中的id号 存在ArrayList中
选中后 add 进ArrayList
取消选中后 remove 出ArrayList

  1. ArrayList <Integer>MultiChoiceID = new ArrayList <Integer>();
  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);
  2. MultiChoiceID.clear();
  3. builder.setIcon(R.drawable.icon);
  4.     builder.setTitle(“多项选择”);
  5.     builder.setMultiChoiceItems(mItems,
  6.             new boolean[]{false, false, false, false, false, false, false},
  7.             new DialogInterface.OnMultiChoiceClickListener() {
  8.                 public void onClick(DialogInterface dialog, int whichButton,
  9.                         boolean isChecked) {
  10.                    if(isChecked) {
  11.                        MultiChoiceID.add(whichButton);
  12.                        showDialog(“你选择的id为” + whichButton + ” , ” + mItems[whichButton]);
  13.                    }else {
  14.                        MultiChoiceID.remove(whichButton);
  15.                    }
  16.                 }
  17.             });
  18.     builder.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
  19.         public void onClick(DialogInterface dialog, int whichButton) {
  20.             String str = “”;
  21.             int size = MultiChoiceID.size();
  22.             for (int i = 0 ;i < size; i++) {
  23.             str+= mItems[MultiChoiceID.get(i)] + “, “;
  24.             }
  25.             showDialog(“你选择的是” + str);
  26.         }
  27.     });
  28.     builder.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {
  29.         public void onClick(DialogInterface dialog, int whichButton) {
  30.         }
  31.     });
  32.    builder.create().show();

7.自定义布局


讲到自定义布局我就得多说一说了,为什么要多说一说呢?
其实自定义布局在Android的开发中非常重要 因为它能让开发者做出自己五彩缤纷的Activity 而不用去使用系统枯燥的界面。

自定义dialog有什么好处?

比如我们在开发过长当中 要通过介绍系统发送的一个广播弹出一个dialog . 但是dialog必需是基于activity才能呈现出来 如果没有activity 的话 程序就会崩溃。所以我们可以写一个自定义的 dialog 把它定义成一个activity
这样我们收到一条打开dialog的广播后 直接启动这个 activity  程序正常运行~~

这就是自定义dialog的好处。

注明:下面这个例子只是写了自定义dialog 没有把它单独的写在一个activity中 如果须要的话 可以自己改一下。

  1. AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);
  2.  LayoutInflater factory = LayoutInflater.from(this);
  3.  final View textEntryView = factory.inflate(R.layout.test, null);
  4.      builder.setIcon(R.drawable.icon);
  5.      builder.setTitle(“自定义输入框”);
  6.      builder.setView(textEntryView);
  7.      builder.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
  8.          public void onClick(DialogInterface dialog, int whichButton) {
  9.          EditText userName = (EditText) textEntryView.findViewById(R.id.etUserName);
  10.          EditText password = (EditText) textEntryView.findViewById(R.id.etPassWord);
  11.          showDialog(“姓名 :”  + userName.getText().toString()  + “密码:” + password.getText().toString() );
  12.          }
  13.      });
  14.      builder.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {
  15.          public void onClick(DialogInterface dialog, int whichButton) {
  16.          }
  17.      });
  18.    builder.create().show();
  1. <span style=”color:#000000;”><?xml version=”1.0″ encoding=”utf-8″?>
  2. <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
  3. android:layout_height=”wrap_content”
  4. android:layout_width=”wrap_content”
  5. android:orientation=”horizontal”
  6. android:id=”@+id/dialog”>
  7. <LinearLayout
  8. android:layout_height=”wrap_content”
  9. android:layout_width=”wrap_content”
  10. android:orientation=”horizontal”
  11. android:id=”@+id/dialogname”>
  12. <TextView android:layout_height=”wrap_content”
  13.    android:layout_width=”wrap_content”
  14.   android:id=”@+id/tvUserName”
  15.   android:text=”姓名:” />
  16. <EditText android:layout_height=”wrap_content”
  17.   android:layout_width=”wrap_content”
  18.   android:id=”@+id/etUserName”
  19.   android:minWidth=”200dip”/>
  20. </LinearLayout>
  21. <LinearLayout
  22. android:layout_height=”wrap_content”
  23. android:layout_width=”wrap_content”
  24. android:orientation=”horizontal”
  25. android:id=”@+id/dialognum”
  26.  android:layout_below=”@+id/dialogname”
  27. >
  28.   <TextView android:layout_height=”wrap_content”
  29.    android:layout_width=”wrap_content”
  30.   android:id=”@+id/tvPassWord”
  31.   android:text=”密码:” />
  32. <EditText android:layout_height=”wrap_content”
  33.   android:layout_width=”wrap_content”
  34.   android:id=”@+id/etPassWord”
  35.   android:minWidth=”200dip”/>
  36.  </LinearLayout>
  37.   </RelativeLayout></span>


8.读取进度框

显示一个正在转圈的进度条loading

 

  1. mProgressDialog = new ProgressDialog(this);
  2.  mProgressDialog.setTitle(“读取ing”);
  3.  mProgressDialog.setMessage(“正在读取中请稍候”);
  4.  mProgressDialog.setIndeterminate(true);
  5.  mProgressDialog.setCancelable(true);
  6.  mProgressDialog.show();

最后如果你还是觉得我写的不够详细 不要紧我把源代码的下载地址贴出来 欢迎大家一起讨论学习 雨松MOMO希望可以和大家一起进步。

15 Best Free Android Games You Love To Play

Android is open sources OS (operating System) for smart phones. Google’s mobile platform, the second most popular operating system using smart phones. Android has a big library of free apps and its growing day by day. Android Market has a big collection of free apps and free games, Android gaming market is also growing as well. So today we come with some best Android games for free download, you would love playing.

Our Last article, related to games appreciated by our readers a lot- best Linux 3D Games For free to use. And again this time we catch best android games for free to use. if you have Android phone then you must try these free Android games for kill free time and having fun.

I have been searching free games for android to make a best list for Android platform users. And finally i got the best list of free games for Android smart phones for having fun and enjoy. These games are the latest version of year 2011.

 

I hope Android platform users whom loves to play games on their smart phones will love to use these free android games. here we have listed 15 best free android games you love to play. You can share your views in our comment section below.

1. Bubble Blast 2

2. Angry Birds


3.  Yoo Ninja

4. Paradise Island

5. Drag Racing

6. Unblock Me

7. Mouse Trap

8. Paper Toss

9. Ant Smasher

10. iRunner

11. SpeedX

12. Air Control

13. Speed Anatomy

14. Aporkalypse Free

15. Math Maniac

 

CentOS 6正式发布,免费的企业级Linux

CentOS 6 正式版已于7月9日发布。

CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。两者的不同在于,CentOS并不包含封闭源代码软件。

CentOS 6.0 基于上游的 Red Hat Enterprise Linux 6.0 制作,同时基本包含了所有的上游软件包。CentOS 完全遵守上游供应商的再发行政策,并且以百分之百的软件兼容性为目标,但相对于 RHEL ,CentOS 最主要的改变是去除了上游供应商的商标及美工图。

CentOS 6上游版本发行注记和文档:Red Hat Enterprise Linux 6

CentOS 6相对于上游版本 RHEL 6,修改、删除和新增了部分组件,详细情况参阅:发行注记

官方网站:http://www.centos.org/

下载页面:http://www.centos.org/modules/tinycontent/index.php?id=15

敏捷方法中测试人员的价值?

敏捷方法在软件开发中受到青睐,特别是在互联网应用服务系统的开发中,越来越多的公司采用敏捷方法,包括XPScrumLeanCrystalFDD等。具体的敏捷方法在操作时有一些区别,但基本思想是一致的,如客户至上、拥抱变化、缩短迭代周期、自我组织等。在敏捷方法中,流程相对灵活,强调沟通,通过充分的沟通来及时解决问题,由于沟通充分,文档不是很重要,而且有可能不采用Word等独立的文件格式,而是采用Wiki、空间等web内容方式。

在敏捷方法中,需求变化比较快、产品开发周期很短(一、两周),给软件测试带来很大的挑战!例如,功能测试的自动化实现就比较困难,没有足够时间开发自动化测试脚本,要花大量时间讨论产品特性,及时进行产品的验收测试。自动化测试,更多的是在单元测试这个层次上实现。而单元测试自动化、持续集成等一些关键实践,开发人员能发挥更大的作用,而测试人员难以很好地发挥作用。在敏捷方法中,开发人员的主导作用更明显,讨论需求、实现需求,再修改需求、再实现、再重构,不断完善产品,测试人员容易边缘化。甚至在Crystal方法中,可以不需要测试人员,开发人员能承担所有技术性的工作。 在敏捷方法中,测试人员的价值又如何体现?

  1. 首先在需求讨论上,测试人员可以站在客户角度上来阐述自己的观点,和产品人员、开发人员等进行充分的交流和讨论,使自己在用户体验、业务逻辑等等方面的经验充分体现出来。
  2. 在开发过程中,测试人员不仅扮演“用户代表”角色,而且可以及时提供更全面的质量反馈,包括代码质量、接口一致性等。测试人员不写代码,可以参与代码复审(code review),将质量问题及时提交给项目组,保证在产品构造的整个过程中质量受到足够的关注,提高质量改进的持续性和可视性。
  3. 测试人员还是可以参与单元测试。即使单元测试由开发人员做,测试人员可以推进开发人员进行单元测,检查单元测试状态,如确保单元测试达到80%以上覆盖率,以及帮助开发人员开发出具有良好可测试性的代码。
  4. 即使在敏捷方法中,集成测试、端到端(end-to-end)测试、性能测试等是不可少的。因为在敏捷方法中,往往将一个大的系统开发分解成多个小的子系统(模块/组件),集成测试和端到端(end-to-end)测试显得更重要。测试人员在功能测试上工作量会降低,但在这些测试上发挥更大的作用。
  5. 随着迭代的不断深入,回归测试的工作量很大,这也是测试人员的用武之地。 测试人员可以针对稳定的产品特性开发自动化测试脚本,这也是一种持续的努力,使回归测试自动化。
  6. 测试人员对缺陷进行分析,总结出一些规律,帮助开发人员建立良好的习惯,改进代码的质量。

而且:

  • 在敏捷方法中,我们也要采用敏捷测试,不要再写几十页的测试计划书,而是在每个迭代周期,写出一页纸的测试计划,将测试要点列出来。
  • 在敏捷测试中,可能不需要测试用例,而是针对use case 或user story直接进行验证,并进行探索性测试。而节约出来的时间,用于开发原有功能的自动化测试脚本,为回归测试服务。自动化测试脚本将代替测试用例,成为软件组织的财富。
  所以:

敏捷功能测试 = 新特性的手工测试 (use case验证和探索性测试) + 原有功能的自动化测试 (回归测试)

理想情况下,测试人员具有很好的编程能力,可以和开发人员进行角色互换。在当前版本开发(/迭代周期)中担任测试人员角色,在下一个版本开发(/迭代周期)中担任开发人员角色,而开发人员则担任测试人员角色,让开发人员深刻地理解用户的需求角度来考虑系统功能的设计,这样会更好地保证产品的质量,沟通的障碍也会消除,开发的效率会有很大的提高。这也是对测试人员的一个挑战。

敏捷测试也是一个持续测试的过程,而这持续测试的基础是具备一个灵活的、开放的自动化测试框架。测试人员在自动化测试框架构建上、测试工具开发或第3方测试工具前期研究、试用等方面可以发挥主导作用。

项目采用敏捷方法,要获得成功,项目组中每个人都有很强的质量意识,具有质量的主人翁精神,特别是开发人员,每时每刻提醒自己——“质量是构建出来的”,与客户或产品设计人员进行充分沟通,遵守高度一致的质量标准。测试人员将是促进质量文化不断提升的中坚力量。

原作者:朱少民