Tuesday, June 12, 2007

Got my first Java Certification

I'm not a used-to blogger, so it has been a long time to insert a single thread.

As a Java newbie, I decided to have some sort of certification on it, to give myself a test and increase my competitive power.

Finally, got the SCJP certification on 8 of June, 2007 :)

Friday, February 9, 2007

Mongrel 1.0.1 + Rails 1.1.6 + Ruby 1.8.5

Try to deploy the application in FreeBSD with the combination mentioned, amazingly.... SLOW.... I don't know what's wrong with it, the Mongrel cluster making the system overhead when process only one single simple request, what's wrong with the latest version?? I switch back to Mongrel previous stable version, it performing very good.

Sunday, February 4, 2007

Spring IoC Learning Note 1 - Hello World

recently start to study springframework.org; The Spring Framework (or Spring for short) is an open source application framework for the Java platform (Definition from Wikipedia). It introduce the so-called 'lightweight framework' to Java world to be an alternative of the 'heavy-weight framework' like Enterprise JavaBean.

first step, write hello world.



//MessageProvider.java
package org.nixeon.ioctest;

public interface MessageProvider {
public String getMessage();
}



//MessageRenderer.java
package org.nixeon.ioctest;

public interface MessageRenderer {
public MessageProvider getMessageProvider();
public void setMessageProvider(MessageProvider mp);

public void render();
}



//HelloWorldProvider.java
package org.nixeon.ioctest;

public class HelloWorldProvider implements MessageProvider {

public String getMessage(){
return "Hello World!";
}
}



//HelloWorldRenderer.java
package org.nixeon.ioctest;

public class HelloWorldRenderer implements MessageRenderer {
private MessageProvider messageProvider;

public void setMessageProvider(MessageProvider mp){
messageProvider = mp;
}

public MessageProvider getMessageProvider(){
return messageProvider;
}

public void render(){
System.out.println(messageProvider.getMessage());
}
}


Use XML beans definition to inject the collaborator.

<!--messenger-meta.xml-->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="renderer" class="org.nixeon.ioctest.HelloWorldRenderer">
<property name="messageProvider">
<ref local="provider"/>
</property>
</bean>

<bean id="provider" class="org.nixeon.ioctest.HelloWorldProvider"/>
</beans>

So, lets get the Bean!!


//Messenger.java
package org.nixeon.ioctest;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

import org.nixeon.ioctest.MessageRenderer;

public class Messenger {
public static void main (String [] args) throws Exception {
BeanFactory factory = getBeanFactory();
MessageRenderer mr = (MessageRenderer) factory.getBean("renderer");
mr.render();
}

private static BeanFactory getBeanFactory() throws Exception {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"messenger-meta.xml"));
return factory;
}
}


Use ant to run the task

Buildfile: build.xml

run:
[java] Feb 4, 2007 5:01:38 PM org.springframework.core.CollectionFactory
[java] INFO: JDK 1.4+ collections available
[java] Feb 4, 2007 5:01:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[java] INFO: Loading XML bean definitions from file [D:\java_workspace\ioctest\messenger-meta.xml]
[java] Hello World!

BUILD SUCCESSFUL
Total time: 1 second


Done :-)

Monday, January 29, 2007

无神论 by 黄立行 Stanley Huang

i wanna believe in all the miracles too
i wanna believe in all the the fairy tales with you
i want the happy ever after really i do
but how can that be when i don't know if heavens true

but theses no eternity for an atheist like me

when i die is that the end no other way in
i'll never see your face again again again again babe
i want die happy ever after i want it with you
but how can that be when i don't know if heavens true

but theses no eternity for an atheist like me

when i die is that the end no other way in
i'll never see your face again again again again babe

and if you should go without me
just promise me that you will always be happy

我希望相信世界有
奇迹出现
我想要我们的童话
不只是瞬间
我希望今后都能快乐
永不分离
但我上不去天堂
我不能够陪你
不存在一种永恒
不相信世界有神
死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念
我真的希望我们快乐
永不分离
只有你能上天堂
我到不了那里
只要想念没改变
不管多远
我会在你心里面

死亡是不是终点
会停止想念
不能再亲吻你的脸
不管我有多怀念

Thursday, January 25, 2007

Prototype.js 1.5 API Doc

Ruby/Javascript lovers are happy to receive the gift from Prototype.js team. Finally, Prototype.js 1.5 is released to be the stable version and another surprise -- the API doc :-)

http://prototypejs.org/api

Monday, January 15, 2007

FreeBSD+Mongrel Cluster+Pound, Kickass Rails Environment

How easy to setup a Rails web server?? you may try this combination, FMcP(FreeBSD+Mongrel_Cluster+Pound). Note that pound is not a web server, it's just a reverse proxy and balancer that interact with mongrel clusters.

step 1: install mongrel & mongrel_cluster

$sudo gem install mongrel
$sudo gem install mongrel_cluster

step 2: install Pound reverse proxy

$pkg_add -r pound

[/usr/local/etc/pound.cfg]
ListenHTTP 0.0.0.0,80

UrlGroup ".*"
BackEnd 127.0.0.1,8000,1
BackEnd 127.0.0.1,8001,1
BackEnd 127.0.0.1,8002,3
EndGroup

UrlGroup ".*.(js|css|jpg|jpeg|bmp|gif|swf)"
BackEnd 127.0.0.1,8003,1
BackEnd 127.0.0.1,8004,1
EndGroup

[end]

$echo "pound_enable=\"YES\"" >> /etc/rc.conf

step 3: configure mongrel cluster

$cd railsapp
$mongrel_rails cluster::configure -a 127.0.0.1 -p 8000 -N 5 -e production
$mongrel_rails cluster::start
$tail log/mongrel.log <-- to see whether the service start successfully

step 4: start pound

$pound -f /usr/local/etc/pound.cfg

That's it!! Run ur rails app at http://127.0.0.1

more about Pound

Sunday, January 14, 2007

PEAR.... em.. what it is??

"I like PHP because it has alot of library, like pear,gd2....",
"oh? so what is pear??"
"pear is a extension for us to load more php library...."
"......... superb!... how is it works???"
"......"

Some windows PHP developer may not know they have a PHP package-manager in their PC. PEAR stands for "PHP Extension and Application Repository". The instruction shown below may "enable" the PEAR with your PHP in your windows box:

1.execute C:\PHP\go-pear.bat the cmd-line wizard will shown, just choose ur best option.
2. make sure the include_path=".;C:\PHP\pear;c:\php\includes" entry is set in ur php.ini
3. thats it, run the pear command by using the command php.exe c:\php\pear\pearcmd.php you'll see the usage of it

you can manage the PHP extended library by using pear, like install, remove, list and so on. just like yum, apt-get, pkg_add in linux and BSD.