April 23rd, 2008
I learned to use JavaCC these days. And I found that JavaCC is a great toolkit.
What is JavaCC?
JavaCC is short for Java Compiler Compiler. It is a parser or scanner generator for Java.
Java Compiler Compiler [tm] (JavaCC [tm]) is the most popular parser generator for use with Java [tm] applications. A parser generator is a tool that reads a grammar specification and converts it to a Java program that can recognize matches to the grammar. In addition to the parser generator itself, JavaCC provides other standard capabilities related to parser generation such as tree building (via a tool called JJTree included with JavaCC), actions, debugging, etc.
You can find a lot of language grammar and AST on its site too. I see that C++ and Java 1.5 grammar are there. JavaScript isn’t there. But I find out that Dojo toolkit’s JSLinker provides an ECMAScript 262 one. That is to say, you can create parser and parse C++, Java or JavaScript sources into your AST for any uses. Lots of great features can be imagined.
I spent about a week learning and using JavaCC. I completed a parser for an IDL language named CAR. I also built an Eclipse editor using the generated AST parser. Bang, all things seems working well: keyword hight-lighting, outline view, error probing, … Great toolkit!
Using JavaCC is quite simple, just download javacc-4.0.zip and unzip it, then following its examples tutorial. I sugguest you to start with JavaGrammars and VTransformer examples, as they are about Java grammar.
I think, later, given opportunity, I will try JavaCC out on other projects. Maybe my Java2Script compiler would be benefited from JavaCC.
P.S. Update:
There is a JavaCC Eclipse Plugin project, you can download the plugin to help you writing your syntax file.
Tags: Compiler, JavaCC
Posted in C++, Java, JavaScript | 2 Comments »
April 22nd, 2008
1. Moving server from IP to another IP may have a lot of problems. DNS may not be totally updated to all of visitor. So keep the old server running as possible.
2. Old content should not be removed immediately. Some visitors may visit your page directly and get cached *.html, which will try to visit old resources. Lots of 404 responses will occur.
3. Every page should be tested. Or bugs will fly all over.
4. All operations should be record so the next time, you can follow last time’s steps to save time.
Posted in Uncategorized | No Comments »
November 8th, 2007
Posted in Java | 2 Comments »
November 7th, 2007
After an incorrect shutdown, Eclipse can not start, freezing on splash window.
I opened file
workspace\.metadata\.log
there was a line saying:
The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes
After taking many tries, I found a solution for this bug. Just remove folder
workspace\.metadata\.plugins\org.eclipse.core.resources\.root\.indexes
and restart Eclipse. Everything will be fine again.
Posted in Bug Fix, Eclipse | 7 Comments »
October 31st, 2007
Mapping port 80 to inner port 8080:
/sbin/iptables -t nat -A PREROUTING -i eth+ -p tcp –dport 80 -j REDIRECT –to-port 8080
Well, I use this trick to avoid firewall blocking.
Posted in Tricks | 2 Comments »
September 18th, 2007
I struggled to find out why my server broke down frequently these days. And I think I found it.
My Apache HTTP server was configured with MaxClients at 50, the default AJP connector’s connections number was about 15, and the Tomcat’s maxThreads was 150. So the bottleneck would be AJP connector, especially all my connection-heavy Comet application was serving about 20 Gtalk/MSNLive simultaneous connections. It is obviously it will break down the servers. And after switching my Gtalk/MSNLive into query modes, it still broke down the server. The reason may be the bottleneck of Apache HTTP server’s 50 maximum connections.
I updated all the configuration to 256 for maximum simultaneous connections. Hope server won’t break down for Comet application from now on.
For more about extreme maximum simultaneous connections, please read articles:
http://jha.rajeev.googlepages.com/web2push
http://www.stdlib.net/~colmmacc/Apachecon-EU2005/scaling-apache-handout.pdf
http.conf
<IfModule prefork.c>
#StartServers 1
#MinSpareServers 1
#MaxSpareServers 5
StartServers 3
MinSpareServers 5
MaxSpareServers 10
#ServerLimit 50
ServerLimit 256
#MaxClients 50
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
server.xml
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009"
maxThreads="256" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" protocol="AJP/1.3" />
Posted in Comet, Tomcat, httpd | No Comments »
September 18th, 2007
Here is an example to replace string with a different delimiter in Windows’ *.bat file.
for /f "tokens=1-15 delims=/" %%i in ("%1") do (
set _X1_=%%i
set _X2_=%%j
set _X3_=%%k
set _X4_=%%l
set _X5_=%%m
set _X6_=%%n
set _X7_=%%o
set _X8_=%%p
set _X9_=%%q
set _XA_=%%r
set _XB_=%%s
set _XC_=%%t
set _XD_=%%u
set _XE_=%%v
set _XF_=%%w)
set _XPATH_=%_X1_%
if not "%_X2_%" == "" set _XPATH_=%_XPATH_%\%_X2_%
if not "%_X3_%" == "" set _XPATH_=%_XPATH_%\%_X3_%
if not "%_X4_%" == "" set _XPATH_=%_XPATH_%\%_X4_%
if not "%_X5_%" == "" set _XPATH_=%_XPATH_%\%_X5_%
if not "%_X6_%" == "" set _XPATH_=%_XPATH_%\%_X6_%
if not "%_X7_%" == "" set _XPATH_=%_XPATH_%\%_X7_%
if not "%_X8_%" == "" set _XPATH_=%_XPATH_%\%_X8_%
if not "%_X9_%" == "" set _XPATH_=%_XPATH_%\%_X9_%
if not "%_XA_%" == "" set _XPATH_=%_XPATH_%\%_XA_%
if not "%_XB_%" == "" set _XPATH_=%_XPATH_%\%_XB_%
if not "%_XC_%" == "" set _XPATH_=%_XPATH_%\%_XC_%
if not "%_XD_%" == "" set _XPATH_=%_XPATH_%\%_XD_%
if not "%_XE_%" == "" set _XPATH_=%_XPATH_%\%_XE_%
if not "%_XF_%" == "" set _XPATH_=%_XPATH_%\%_XF_%
For more information, please key in “for /?” in command line.
Posted in Tricks | 1 Comment »
September 5th, 2007
If you ever visit Eclipse homepage http://www.eclipse.org/, you may notice that Eclipse homepage embeds plugin updates news from Eclipse Plugin Central (http://www.eclipseplugincentral.org/). If you try to visit the news by the given link, you may find that the page loads very very very SLOW!
Why? Open the the page source, you will see that it generates all 900+ plugins in the source! And the *.html file size is up to 200+k. And worse thing is that every page in Eclipse Plugin Central is the same with 200+k HTML file! Every page!
Besides it was once hacked by someone and its functions were buggy, such 200+k HTML pages design in Eclipse Plugin Central must be listed as #1 of aweful designs that I have ever seen.
Posted in Uncategorized | No Comments »
September 1st, 2007
Recently, my Apache HTTP server was broken down twice. The scenario was when visiting a page, it was just waiting there, blank. And I checked the server through SSH and saw that there was a lot (about 50) of inner 8009 connections. After restarting Apache HTTP Server and Tomcat Server, these connections decreased to less than 10 connections.
Yes, I deployed Comet applications “Google Talk in JavaScript” and “MSN Live in JavaScript” on my server. Here is the connection routine:
Client <-Kept Connection-> Apache HTTP Server <-AJP Connector (8009 Connection)-> Tomcat
When a user is connected, an AJP Connector is setup for him/her. The connection will not be tore down until the user disconnects from Gtalk or MSNLive service. So if there are more than 50 users online, there are no doubts that the server crashes.
To solve this problem, one solution would be not using Apache HTTP Server in the middle of Tomcat server and browser client. So there is no limitation on AJP connections.
And another solution would be monitoring user connections on Tomcat server side, and if there are more than 50 connections, try to switch application’s Comet-mode into Query-mode smartly.
Providing Comet applications need to solve a lot of unknown problems.
Posted in Comet, Google Talk, Tomcat, httpd | 1 Comment »
August 21st, 2007
I am puzzled a lot when I got emails with winmail.dat attachment, which is unknown file type attachment in my Thunderbird. Here is the solution for this annoying winmail.dat:
Go to https://addons.mozilla.org/en-US/thunderbird/addon/4433, follow it instructions to download the “LookOut” add-on for Thunderbird, and attached files inside winmail.dat will be listed and be recognized and be opened with existed programs.
Posted in Uncategorized | No Comments »