2009年5月10日星期日

学习一些存储知识MPIO, SAN, iSCSI 等

相关术语:
SCSI, iSCSI
FC, SAN
DAS, NAS
MPIO, DSM, ALUA


SCSI
Small Computer System Interface
是计算机与外部设备之间的物理连接和数据传输的标准,是一种智能的通用接口标准。
与IDE有何区别?

iSCSI
Internet Small Computer System Interface
ISCSI是一种基于IP网络的存储技术。
工作原理:把SCSI数据包装成TCP数据包然后通过IP网络进行传输。


FC
Fibre Channel 光纤通道, 是SAN的支持技术。


DAS(Direct Attached Storage),存储设备直接连接到计算机或服务器。在我们日常用的普通PC中的硬盘的连接方式,就属于这类。

NAS
Network Attached Storage
一种文件级别的数据存储,它通过网络对异构网络客户端提供数据访问(基于文件的数据存储服务)。NAS支持多种协议如NFS, CIFS, FTP, HTTP,而且支持多种操作系统。

SAN
Storage Area Network
一种高速的专用网络(或子网),它把远程计算机存储设备连接到不同的服务器,使得这些设备在本地的系统中犹如本地存储设备一样。

MPIO
Multipath I/O

ALUA
Asymmetric Logical Unit Access

Windows 2008 中的 MPIO

相关网站:
1. 领先的中文存储网络媒体
http://www.watchstor.com/
2. It168存储频道
http://storage.it168.com/


Dell的一位产品经理介绍iSCSI技术视频:

2009年5月6日星期三

WMI相关资料收藏

1. WMI (Windows Management Instrumentation) - Home
http://www.computerperformance.co.uk/vbscript/wmi.htm

该站点提供一系列WMI教程,且提供非常棒的工具 Scriptomatic, 可以自动帮你生成不同语言(包括VBscript, Perl, JScript, Python)的查询脚本!

2. Access WMI using Python
http://timgolden.me.uk/python/wmi-tutorial.html

介绍如何用python访问WMI

2009年4月24日星期五

What does "out of the box" mean

最近看英文书时,经常遇见一个表达-Out of the box, 查了字典后还是觉得很confused。
下面是Wikipedia上面的解释,比较具体。我想主要有两层意思1)形容某项功能容易用,不需用户的另外操心就可发挥作用或完成任务;2)一种与过去或其他不同创新的方式

Items, functionalities, or features provided out of the box are those that do not require any additional installations, plug-ins, expansion packs, or products. In addition to being used for tangible products, the phrase is often used in a less literal sense for software, which may not be distributed in any box but offer certain functions "out of the box."

In the case of implementation of products that use other products, out of the box also has the connotation of using a system without customization, such that it is usable with a Vanilla software installation.




在Spring In Action出现这个表达就有10处, 而在 Seam In Action 出现了18次!今天抽点时间把这些句子摘取出来放在这里。

《Spring In Action》

1.
Tons of open source frameworks were blossoming on the Java landscape. In order to decide to adopt one, it had to hit the sweet spot of our needs—it had to do 80% of what we needed right out of the box.

2.
In addition to prototype, Spring offers a handful of other scoping options out of the box, as listed in table 2.5

3.
The idea of creating a base DAO class that holds the JdbcTemplate is such a good idea that Spring comes with just such a base class out of the box.


4.
Spring’s out-of-the-box support for web service proxying comes in the form of
JaxRpcPortProxyFactoryBean。

5.
Although JaxRpcPortProxyFactoryBean is the out-of-the-box solution for wiring proxies to web services in Spring, it makes no assumptions about the services it proxies and requires a lot of configuration.

6.
Spring’s AbstractExcelView and AbstractPdfView make quick work of producing Excel and PDF documents. But what if you need to produce output that isn’t covered by Spring’s out-of-the-box solutions?

7.
Spring offers several out-of-the-box view controllers from which to choose.

8.
In fact, Spring Web Flow comes with out of the box support for use in Jakarta Struts
  • JavaServer Faces
  • Spring Portlet MVC
9.
Before we end our discussion on Spring Web Flow, let’s see how to use Spring Web Flow’s out-of-the-box support for integration with Jakarta Struts and JSF.

10.
In addition, Spring provides several out-of-the-box mock implementations such as MockHttp-
ServletRequest and MockHttpServletResponse that are useful for testing controllers.



《Seam In Action》


1.
As I mentioned earlier, seam-gen produced projects that are configured to deploy to JBoss AS out of the box.

2.
Seam configures three profiles out of the box: dev, prod, and test.

3.
But, if you are on the fence, I find NetBeans easier to get into if you are a new user. It has less clutter and it is geared specifically towards Java EE development out of the box.

4.
Out of the box, seam-gen creates a build process that is biased towards JBoss AS.

5.
Instead, GlassFish is prepared to use the TopLink Essentials implementation out of the box.

6.
At the time of writing, there is an outstanding feature request for seam-gen to support GlassFish out of the box.

7.
For those savvy JSF readers, I will admit that you can use a custom PhaseListener to execute code prior to the Render Response phase. However, doing so requires a lot of redundant work on your part to achieve what Seam gives you right out of the box.

8.
Right out of the box, injections are transient without you having to add the transient keyword on all of the fields marked with @In.

9.
Seam supports both Hibernate 3 and the Java Persistence API (JPA) out of the box.

10.
The XML-based approach is amazingly flexible, in a large part due to the capabilities of the Seam
component model and the ubiquitous EL. When defined in this way, the component can be used a JSF backing bean, action listener, or both, right out of the box.

11.
Enabling security is a bit of a misnomer in Seam. Security is always enabled by default, unless you forcefully disable it. However, out of the box, there is no way for users to authenticate themselves. That requires that you specify which method will act as the authentication handler

12.
In fact, out of the box, JAAS can only work using this principle. The idea is that instead of requiring users to login before doing anything, the application attempts to allow them to use as
much of the application as possible before authenticating.

13.
Seam only supports the first scenario out of the box.

14.
Seam supports three basic transformations out of the box, listing in table 13.2.

15.
Out of the box, jBPM supports persisting executions to the database using Hibernate.

16.
Spring's persistence layer can scope the persistence context anywhere from a single operation (method call) to an entire request. But out of the box, it cannot go any further. Even if a solution came about in the future (as software is ever changing) it still wouldn't integrate better with the Seam life cycle when compared to what Seam offers today.

17.
You could probably spark a heated debate over the importance of the transaction around the view, but suffice to say that Spring just doesn't support it out of the box.

18.
Java EE 5 application servers have escaped their legacy. They now offer, in my opinion, a much better development experience than a servlet container like Tomcat. They are just as fast to start, in some cases faster, they behave according to a rather decent specification, and
they offer many more services out of the box.

Java中的随机数

相关类:
java.util.Random
java.util.Math
java.security.SecureRandom

Math提供了一个静态方法random(),该方法返回一个 等于或大于0.0小于1.0(0.0 <<= returned value <1.0)的double型随即数。它其实也依赖于一个Random对象来生成这个随机数的。

SecureRandom能够生成具有安全性的随机数, 其应用例子如用于生成Http会话ID(在Tomcat 等容器有SessionIdGenerator类用于生产Http会话ID). SecureRandom类的设计上采用了Service-Provider的模式,它继承了Random, 重写了Random中的next(int numBits)和nextBytes(byte[] bytes)方法,把实际的随机数的生成工作delegate给具体的provider, 如果用户没提供provider,它会默认用Sun的implementation. SecureRandom是如何做到保证生成的随机数具备安全性呢?主要是使到随机数不可预测性,不想Random那样可以推测出之前或之后的随机数出来。

相关资料

1. Sun的Tech Tips 文档 USING RANDOM NUMBERS FOR TESTING AND SIMULATION

2. A Java Programmer’s Guide to Random Numbers
Part 1: Beyond java.util.Random
Part 2: Not just coins and dice

2009年4月23日星期四

读Effective Java笔记

Item 8: Obey the general contract when override equals

当你的类具有逻辑意义上的等同性的内涵(即使类的实例的标识不同但其内容是一样的,那么它们也是相等的),你就必须重写equals方法。这样的类一般是携带值的类(value classes)。重写equals方法要遵循以下contract:
1. Reflexivity
2. Symmetry
3. Transitivity
4. Consistency

按下面的steps可写出高质量的equals方法:
1. 用 "==" 检查参数是否是指向本对象的一个引用
2. 用 "instanceof" 检查参数的类型是否和本对象的类型一样
3. 把参数转换到正确的类型
4. 检测参数的字段和本对象的相应字段是否匹配相等
如果这些步骤都成功,就返回true.

Item 9: Always override hasCode when you override equals

Object的技术规范指出,如果两个对象根据equals方法比较的结果是等同的,那么这个两个对象的hashCode方法必须返回相同的整数值。这样在把这样的对象作为基于hash的map时,才不会在存取数据时出现问题。查看一下HashMap.put方法的代码:

public V put(K key, V value) {
if (key == null)
return putForNullKey(value);
int hash = hash(key.hashCode());
int i = indexFor(hash, table.length);
for (Entry e = table[i]; e != null; e = e.next) {
Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
V oldValue = e.value;
e.value = value;
e.recordAccess(this);
return oldValue;
}
}

modCount++;
addEntry(hash, key, value, i);
return null;
}

put同时用到key的hashCode和equals方法。显然,e.hash == hash && ((k = e.key) == key || key.equals(k))这个条件和两个对象等同则其hash必须一样的协约吻合。

编写一个好的hashCode方法也是有规可循的。书中给出了很具体的操作要点。下面是书中给出的一个例子:

public final class PhoneNumber {
private final short areaCode;
private final short prefix;
private final short lineNumber;
//omitted some lines
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof PhoneNumber))
return false;
PhoneNumber pn = (PhoneNumber)o;
return pn.lineNumber == lineNumber
&& pn.prefix == prefix
&& pn.areaCode == areaCode;
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + areaCode;
result = 31 * result + prefix;
result = 31 * result + lineNumber;
return result;
}
}

17是随意的一个数,31则是一个传统的选择,但要最好是一个质数。

2009年4月22日星期三

什么是 Port Forwarding及SSH Tunnel

这两天在看SSh的东东,对其中提到的SSH Tunnel/Port Forwarding甚感兴趣。首先什么是Port Forwarding呢?

简单的理解,就是把发往某个端口的数据包转发到另外的一个端口去,后者可以是同台主机上也可以是另一台主机。Port Forwarding 使一台不私有网络的主机可访问私有网络中的某台主机,如通过设置Router的转发规则,把到路由的tcp/80端口的连接forward到内网的某台主机的80端,从而可以让这台只有内部Ip的主机对外提供web服务。

SSH Tunnel 也是属于port forwarding, 它建立在ssh连接上的一个加密的通道,利用它可以传输没经加密的数据从而达到安全的目的。创建了SSH Tunnel之后,你不用直接去访问远程的服务(假使你是连接某个远程服务),相反你访问你本机的某个端口,而SSH Client就会把你的数据通过已建立的加密通道转发到远程主机的目的端口去。网上有很多关于用SSH Tunnel来实现用客户端安全接受发邮件的例子。


相关资料
1. Tunneling protocol
http://en.wikipedia.org/wiki/Tunneling_protoco

2. Port Forwarding
http://alumni.ox.compsoc.net/~steve/portforwarding.html
该文中有个很好的例子,展示了路由在做portforwarding事修改数据报的表头中的目的/源的地址和port。

3. Port Forwarding How To
http://www.home-network-help.com/port-forwarding.html
该文有三个小例说明如何设置路由让内部网的三台机子分别能对外网提供Web服务,Remote Destop连接和游戏服务器。

4. HOWTO: SSH Tunneling Made Easy
http://www.revsys.com/writings/quicktips/ssh-tunnel.html

5. Using ssh Port Forwarding to Print at Remote Locations
http://www.linuxjournal.com/article/5462

2009年4月21日星期二

SSH 和 MindTerm笔记

SSH 为 Secure Shell 的缩写,是建立在应用层和传输层基础上的安全协议议。

优点:
  • 安全可靠
  • 传输的数据是经过压缩,可加快传输速度
  • 为PPP提供一个安全的“通道”
基于这些特点,它可代替telnet, rlogin等这些由于传输数据的明文而缺乏安全性等远程登陆工具。

SSH主要包括下面三个协议:
  1. 传输层协议(The Transport Layer Protocol)
  2. 用户认证协议(The User Authentication Protocol)
  3. 连接协议(The Connection Protocol)

MindTerm 是 一个用纯Java语言编写的SSH的客户程序。可把它当作一个单独的Java程序也可以作为Applet嵌套在网页中运行,可能更有价值的是可以把它整合到你的产品中,例如提供一些console功能,不过用于商业用途(用户多于25个)是要收费的。
下载地址:http://www.mindbright.se/

资料
1. Securing UNIX Servers with the Secure Shell (ssh)
2. 免费 SSH client 工具 PuTTY
3. 免费开源ssh套件OpenSSH(服务端,客户端和密钥工具等)

2009年4月20日星期一

Deadlock stack trace

最近遇见了一个死锁问题,由于除了处理死锁的经验不足,不知道利用堆栈轨迹(thread stack trace)来调试问题,花费了不少时间比较不同版本的不同和插入debug信息来跟踪deadlock发生的位置,最后客户提醒了一下lock stack trace才意识到自己之前的方式有问题,最后google了一下,发现很多很不错的相关信息(不过,暂时没时间好好总结实践一下)。

1. Java thread dump
http://www.myloadtest.com/java-thread-dump/
该文简单介绍了用Thread Dump Analyzer分析thread dump,以Dining Philosophers 为例。

2. Of Thread dumps and stack traces
http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/

该文包括下面几方面内容:
  • Anatomy of a stack trace
  • Innovative usage of stack traces
  • Thread dump 101
  • Debugging run away CPU
  • Debugging performance issues
  • Debugging “hang” problems

3. An Introduction to Java Stack Traces
http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/
该文比较详细介绍了Java Stack Traces 和如何分析stack traces.

"What is a Java stack trace? A Java stack trace is a user-friendly snapshot of the threads and monitors in a Java1 Virtual Machine (JVM). Depending on how complex your application or applet is, a stack trace can range from fifty lines to thousands of lines of diagnostics. .."


Sun 也提供了一个产生死锁了例子:http://java.sun.com/docs/books/faq/src/thr/DeadlockExample.html

下面是我的运行结果:

D:\java DeadlockExample

threadA.getLockCounter(1) = 0
threadA.getLockCounter(2) = 0
threadB.getLockCounter(1) = 0
threadB.getLockCounter(2) = 0
Started DeadlockThread(a, b)
Started DeadlockThread(b, a)

threadA.getLockCounter(1) = 440
threadA.getLockCounter(2) = 439
threadB.getLockCounter(1) = 1
threadB.getLockCounter(2) = 0

threadA.getLockCounter(1) = 440
threadA.getLockCounter(2) = 439
threadB.getLockCounter(1) = 1
threadB.getLockCounter(2) = 0

(enter the key sequence ctrl+break)

2009-04-20 21:41:57
Full thread dump Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing):

"DestroyJavaVM" prio=6 tid=0x002f6400 nid=0x1f8 waiting on condition [0x00000000
..0x0091fd50]
java.lang.Thread.State: RUNNABLE

"Thread-1" prio=6 tid=0x02b0f000 nid=0xa64 waiting for monitor entry [0x02eaf000
..0x02eafd18]
java.lang.Thread.State: BLOCKED (on object monitor)
at DeadlockThread.grabSecondLock(DeadlockExample.java:137)
- waiting to lock <0x2b77f0a0> (a java.lang.String)
at DeadlockThread.grabFirstLock(DeadlockExample.java:131)
- locked <0x2b77f0b8> (a java.lang.String)
at DeadlockThread.grabLocks(DeadlockExample.java:125)
at DeadlockThread.run(DeadlockExample.java:105)

"Thread-0" prio=6 tid=0x02b0e800 nid=0x614 waiting for monitor entry [0x02e5f000
..0x02e5fd98]
java.lang.Thread.State: BLOCKED (on object monitor)
at DeadlockThread.grabSecondLock(DeadlockExample.java:137)
- waiting to lock <0x2b77f0b8> (a java.lang.String)
at DeadlockThread.grabFirstLock(DeadlockExample.java:131)
- locked <0x2b77f0a0> (a java.lang.String)
at DeadlockThread.grabLocks(DeadlockExample.java:125)
at DeadlockThread.run(DeadlockExample.java:105)

"Low Memory Detector" daemon prio=6 tid=0x02b01800 nid=0xe90 runnable [0x0000000
0..0x00000000]
java.lang.Thread.State: RUNNABLE

"CompilerThread0" daemon prio=10 tid=0x02af8400 nid=0xbf4 waiting on condition [
0x00000000..0x02d6f844]
java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x02af6c00 nid=0xbec runnable [0x00000000..
0x00000000]
java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x02b13c00 nid=0x608 waiting on condition
[0x00000000..0x00000000]
java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x02ab0000 nid=0xd48 in Object.wait() [0x02c7f000.
.0x02c7fc98]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x22940b28> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
- locked <0x22940b28> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x02aaec00 nid=0x1f0 in Object.wait() [0x
02c2f000..0x02c2fd18]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x22940a30> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
- locked <0x22940a30> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x02aad400 nid=0x9ec runnable

"VM Periodic Task Thread" prio=10 tid=0x02b03000 nid=0x90c waiting on condition


JNI global references: 594


Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x02b20ca4 (object 0x2b77f0a0, a java.lang.String),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x02ab492c (object 0x2b77f0b8, a java.lang.String),
which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
at DeadlockThread.grabSecondLock(DeadlockExample.java:137)
- waiting to lock <0x2b77f0a0> (a java.lang.String)
at DeadlockThread.grabFirstLock(DeadlockExample.java:131)
- locked <0x2b77f0b8> (a java.lang.String)
at DeadlockThread.grabLocks(DeadlockExample.java:125)
at DeadlockThread.run(DeadlockExample.java:105)
"Thread-0":
at DeadlockThread.grabSecondLock(DeadlockExample.java:137)
- waiting to lock <0x2b77f0b8> (a java.lang.String)
at DeadlockThread.grabFirstLock(DeadlockExample.java:131)
- locked <0x2b77f0a0> (a java.lang.String)
at DeadlockThread.grabLocks(DeadlockExample.java:125)
at DeadlockThread.run(DeadlockExample.java:105)

Found 1 deadlock.

Heap
def new generation total 960K, used 280K [0x22940000, 0x22a40000, 0x22e20000)

eden space 896K, 31% used [0x22940000, 0x229861a8, 0x22a20000)
from space 64K, 0% used [0x22a20000, 0x22a20000, 0x22a30000)
to space 64K, 0% used [0x22a30000, 0x22a30000, 0x22a40000)
tenured generation total 4096K, used 0K [0x22e20000, 0x23220000, 0x26940000)
the space 4096K, 0% used [0x22e20000, 0x22e20000, 0x22e20200, 0x23220000)
compacting perm gen total 12288K, used 365K [0x26940000, 0x27540000, 0x2a94000
0)
the space 12288K, 2% used [0x26940000, 0x2699b768, 0x2699b800, 0x27540000)
ro space 8192K, 63% used [0x2a940000, 0x2ae58810, 0x2ae58a00, 0x2b140000)
rw space 12288K, 53% used [0x2b140000, 0x2b7ad300, 0x2b7ad400, 0x2bd40000)

2009年4月19日星期日

高焕堂CSDN访谈


高焕堂,台湾软件架构设计大师,从事IT行业近30年,台湾oo技术的代表人物。

前不久看了《User Case 入门与实例》才知道高焕堂这个人的,当时觉得那书写的不错,很受益。
今天看了这个视频也很受启发。高老师娴熟地将中国哲学运用于软件架构设计之中,大师就是大师!