Record video with Webcam and Raspberry Pis

When I got the Raspberry Pi, I always have question what else we can use it for.  In a recent conference, we want to demonstrate our mod_cluster's function:  we cut off the power supply/disconnect one server , the web app running in the jboss7 still works and served by other servers.We don't have another projector and professional photographer to record the video and project to a big screen. So we tried to create our home made video recorder to get this : WebCam with Raspberry Pi (powered by battery).  It's better than the video recorder , because it can  start a video stream sever. The video can be accessed by http client , a normal  web browser. So speaker can project the video from his laptop, audience can also connect to the server to see what happens, it's more interactive, isn't it ?
    These are my equipments to make this work:

  •     Raspberry Pi  + 8G SD Card

  •  Microsoft  HD-3000 Webcam

  • TP-Link WN725N Wireless N Nano USB adapater

  • Portable battery

  • Micro USB cable

After you get these things , you only need two steps to start the http stream server :
1. Burn the Raspbian "wheezy" image to your sd card. Follow the this guide is pain free to do this.
2. Compile mpeg-stream from source code on wheezy.Wolf Paulus wrote a great blog to guide you compile it.  Follow it , it is also pain free to do that. After it is compiled, go to the  mjpg-streamer, run start.sh. You can now get the video stream from remote server. 


Updated jdk 1.6 to latest version

When you try the Jopr 2.3 release and hit license validation errors, you may need to update you Sun's jdk1.6 version to update 10 or higher . Ian pointed me this jdk issue is only fixed in jdk1.6 update 10 or higher version . So do not try to check or update the license file when you see this error .


Jopr jbpm plugin sneak peak

If you download and play with the new released jBPM4.1, you will find there are lots cool things: gwt based jPDL process designer , tomcat support , other enhancements and bug fixes. If you svn check out the jBPM4 code base and dig it , you will find there are enriched apis you can use to build some interesting stuff. As Joram says the jBPM4 is not a black-box system and you can always get things under control : you can extend it ,customize it and you can monitor and manage it . Here I write a plugin for it to demonstrate what you can use its apis to clearly see what is running in jBPM. The jBPM4 provides many apis and command to let user get all the running and history information abou process instances, tasks , activities and other things . It all can be probed by invoking these jbpm4's apis . In this entry , I'll show you my work about this jopr and jbpm plugin.

As you may know , there is a new improved management console based on embededJopr in jbossAS5. The management console can also be extended by writing a jopr plugin . Here I extend it by adding my developed jbpm plugin to allow operators monitor and manage the jbpm4 engine :

  1. There are components for JBPM engine to show the jbpm health , number of deployed process , running instance, ended process instance and average instance duration :
  2. Process deployment management : you can use these operations or add/delete resource button to deploy , suspend ,resume and delete the deployments.
  3. All the process definitions will be listed under Process definitions directory . Unfold the process definition, you can monitor its status and the activities of this process definition.
  4. History process instances , process instance , tasks and history tasks are all viewable . There are operations for you to select all these items what you want to see.
  5. The running process instance and ended process instance directory help you to monitor the process instances you interested in nearly real time . The latest status value of process instance and tasks will be listed in the added instance tree.
  6. Job component provides the visibility to all kinds of job : message , timer and even exceptional job :

There is also a screencast for this plugin to show how it works : jopr jbpm plugin


Get Jboss system property map

If you look at the {jboss.home}/server/default/conf/jboss-service.xml, you can find the code base references the
system property:


JBoss managed the system properties and support you use ${varibleName} to reference its value in the configurations.
You may want to know how can I know what system property we can reference .
Here is the answer :

1.Open the Jboss JMX console : http://localhost:8080/jmxp-console

2.Ctrl+F SystemProperties and find this MBean

3.Cliek link for this MBean and find and invoke showAll jmx method.

What do you find ?


Track down the jar version in JBoss5

If you want to find which version jboss-remoting or jboss-web shipped in JBoss5.0.0.GA, check this maven configuration file :



RHQ Agent Error

有时候当启动RHQ agnet时,agent会hang在那里,有的时候运行ping命令也没有返回,在等待一段时间后agent会显示出错信息。Heiko对agent的错误进行了详细的分析, 并且给出了两种解决方法:


2.使用rhq-agent.sh --clean重新配置agent.



记得大学期间拨号上网,查询信息还是通过Yahoo和Excite这两个网站.记得为了了解电脑上AGP接口和IDE接口有什么不同,自己会花好长时间去查询,研究.很多新事物,新科技产品的工作原理都可以在 HowStuffWorks找到答案,Howstuffworks的动画或者图解能够帮助我们理解一个高科技设备的基本原理,所以这个网站至今一直收藏,阅读。昨天突然想查一下Tomcat6中Http11Protocol中是如何工作的。 Howstuffworks没有software的专栏,如果有的话,一定可以从这个网站找到满意的答案。昨天的问题没有通过Google找到答案,所以开始Dig code ...

在tomcat启动时候,会把Connector, Host, Engine, Wrapper等对象都创建出来。当给Connector的protocol配置成Http1.1 时, Connector会调用Http11Protocol,直到servlet.service().

上图是tomcat6中接受和处理socket请求(Http请求)有关的类. Connetor是连接处理的控制类,在配置文件中的<connector/>都是这个类来负责处理。 如果配置的protocol是Http/1.1, Connector则会启动Http11Protocol. Http11Protocol会创建JIoEdpoint来正在接受socket并且分配到具体的线程中处理。 Acceptor用来接受Socket请求,WorkerStack是Tomcat自己内部的线程池。Tomcat6同时也支持Executor线程池。 在每个线程中会调用Http11ConnectionHandler来处理每个socket,如果是servlet请求,则会调用CoyoteAdapter.process去执行servlet.service().

在JIoEndpint中通过createWorkerThread()方法来将创建好的woker, offer()到WorkerStack中。Woker在创建的同时start(),但run()方法会block直到assin()方法被调用,Woker才处理socket对象。 Acceptor接受到socket后,通过调用getWorkerThread().assign(socket); 来激活worker.run()方法:

public void run() {

// Process requests until we receive a shutdown signal
while (running) {

// Wait for the next socket to be assigned
Socket socket = await();
if (socket == null)

// Process the request from this socket
if (!setSocketOptions(socket) || !handler.process(socket)) {
// Close socket
try {
} catch (IOException e) {

// Finish up this request
socket = null;



从以上代码可以看出socket的真正的处理是在HttpConnectionHandler中。 HttpConnectionHandler是Http11Protocol中的static class,它由一个Http11Protocol创建。在HttpConnectionHandler中有Http11processor队列,Http11Processor可以设置Adapato。在创建 Http11processor时,会将Http11protocol上的CoyoteAdapter设置给Http11Processor。在运行HttpConnectionHandler.process()时会调用Http11Processor的process(socket)方法,这个方法最终会调用CoyoteAdpater.service()方法,从而完成调用serlvet上的service方法。在这几个类中,用的最多的就是线程池和对象池。Tomcat中对于需要为每个线程创建的对象都会建立对象池来循环使用,这样可以节省创建对象的时间:

protected static class Http11ConnectionHandler implements Handler {

protected Http11Protocol proto;
protected AtomicLong registerCount = new AtomicLong(0);
protected RequestGroupInfo global = new RequestGroupInfo();

protected ConcurrentLinkedQueue recycledProcessors =
new ConcurrentLinkedQueue() {
protected AtomicInteger size = new AtomicInteger(0);
public boolean offer(Http11Processor processor) {
boolean offer = (proto.processorCache == -1) ? true : (size.get() < proto.processorCache);
//avoid over growing our cache or add after we have stopped
boolean result = false;
if ( offer ) {
result = super.offer(processor);
if ( result ) {
if (!result) unregister(processor);
return result;



Tomcat6开始支持NIO,在配置Tomcat6的Connector的protocol时又多了一个可选项org.apache.coyote.http11.Http11NioProtocol -非阻塞的java connector:
<connector protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000"redirectPort="8443" />

Http11NioProtocol使用java5中的NIO实现,使用selector和channel来创建处理server socket. 根据三种connector的比较, 使用NIO的connector,可以处理更多的connection,不受accecptCount和maxThreads的限制。

JBossESB4.5.GA 发布

JBossESB Team在2月12号发布了最新的JBossESB 4.5.GA. 最新版本的JBossESB包括了众多的bug fix ,以及新的特性. 详细信息列在了JBossESB 4.5.GA发布说明中. 新特性中包含了我contribute的Tomcat Gateway代码.在这一个版本中你可以使用http provider来配置一个http的gatway来实现多个ESB Service共用同一个端口.详细的配置说明清参考这篇wiki .


XPath and default name space

when you use xpath to select nodes from a xml document which contains default namepsace, you may need read this article. If the xpath expression is "//cd" , the xpath parser will treat it as the element which namespace is null and local name is "cd". Adding the prefix and default namespace to namespace context always can help you resolve this issue perfactly. I remembered I also wrote some code for jaxws cosomization parser for cxf wsdl2java tool. I just reviewed. It probably can not handle the xpath expression. I will take a look at it and fix it later...


How to write RHQ plugin

If you do not experience the RHQ, you can look at rhq-project.org to get more information. If you want to monitor and management your own software or your enterprise application , you may need to write your own rhq plugin . How to wirte a RHQ plugin ? Heiko will tell you about how in his series rhq plugin tutorial.


Install DB2 on Fedora8

If you are about to install DB2 on Fedora 8 or other linux platform , maybe this entry is worth reading.
When you use root user to install the DB2 database, you 'll find it does not take your much efforts to install it successfully. But if you intend to use the normal user to install DB2 in your home directory, there are somethings needed to be configured.
1. Enable DB2 Authentication using local operating system security and reserve the remote connection
When you installed DB2 in the home dir of normal user , you will find there is no security authentication . And the remote connection also does not work. To enable this , create a configuration file and execute db2rfe command.
Under /sqllib/instance directory , there is shell script named db2rfe. The comment for this command gives the clue it is to check system before installation. Do not know if it needs some update. At least I used it to set my db2 instance attribute.
Write the following configuration file for this db2ref script and save it as file db2ref.cfg:
** ============================================================================
** This is required keyword.
** ----------------------------------------------------------------------------
** Enable DB2 High Availability (HA) feature
** ----------------------------------------------------------------------------
** Valid value is NO and YES. Change to YES if you need to enable this feature.
** ------------------------------------------------------------------------------
** ENABLE DB2 Authentication on the server using local operating system security.
** ------------------------------------------------------------------------------
** Valid value is NO and YES. Change to YES if you need to enable this feature.
** --------------------------------------------
** Reserve DB2 remote connection service entry
** --------------------------------------------
** Valid value is NO and YES. Change to YES if you need to do the reservation.
** If SVCENAME and/or SVCEPORT are defined and valid, the DB2 database manager
** configuration will be updated accordingly.

After db2rfe is executed, you will find you can use "db2 connect sample using sampleuser" to connect your database.
The remote service port also takes effect , you can use a JDBC client to connect the database you created.

2. Change the service port
Use the normal user install DB2, you may find the service port is not common used 50000. Use this command to change it :
db2 update dbm cfg using SVCENAME 50000, restart db2 instance .

After follow this two steps, the db2 works fine to be connected with a remote java client .