You are currently browsing the monthly archive for July 2007.
I try to collect all open-source softwares but still miss some. Fortunately there are lots of useful website do that for us.
Definition:
The intent of Facade pattern is to provide an interface that makes sub-system easy to use.
What is:
Facade pattern
Example:
1. AppLab’s Facade pattern
Using RunTime ShutdownHook
A shutdown hook is simply an instance of a subclass of the Thread class. Creating a shutdown hook is simple:
1. Write a class extending the Thread class.
2. Provide the implementation of your class’ run method. This method is the code that needs to be run when the application is shut down, either normally or abruptly.
3. In your application, instantiate your shutdown hook class.
4. Register the shutdown hook with the current runtime’s addShutdownHook method.
Ref:
USING SHUTDOWN HOOKS
Surviving Abrupt Shutdown
JBoss 4.0.2 org.jboss.system.Server.shutdown()
Tomcat 4.1.34 shutdown()
Using a daemon thread with ShutdownHook
For example, JBoss uses shutdownHook.setDaemon(true) or do this (Java Daemon).
I need to know if JBoss startup is ready, then I can do something else. But how can I detect it?
Fortunately JBoss JMX MBean can help us.
1. Use twiddle.bat to get server infomation
%JBOSS_HOME%\bin\twiddle.bat -H get
Get the values of one or more MBean attributes
usage: get [options] <name> [<attr>+]
If no attribute names are given all readable attributes are retrieved
options:
–noprefix Do not display attribute name prefixes
– Stop processing options
%JBOSS_HOME%\bin\twiddle.bat get jboss:service=invoker,type=jrmp
ServerAddress=0.0.0.0
RMIClientSocketFactoryBean=null
StateString=Started
State=3
RMIServerSocketFactoryBean=org.jboss.net.sockets.DefaultSocketFactory@ad093076
EnableClassCaching=false
SecurityDomain=null
RMIServerSocketFactory=null
Backlog=200
RMIObjectPort=4444
Name=JRMPInvoker
RMIClientSocketFactory=null
2. Example:
I write a batch script like this:
REM *********************************** REM startup JBoss and then do something REM *********************************** @echo off REM start JBoss server start "JBoss4C server" /Min %JBOSS_HOME%binrun.bat REM use jboss.server MBean to detect JBoss start up ready or not REM continue to ping JBoss for max times set jcount=0 set MAXLOOP=100 :loop call %JBOSS_HOME%bintwiddle.bat get --noprefix "jboss.system:type=Server" Started > $flg REM if flag is "true" means JBoss start up ready! find /i /n /off "true" $flg REM ERRORLEVEL=0 success,ERRORLEVEL=1 fail if ERRORLEVEL 1 goto :FAIL_STARTUP goto :SUCCESS_STARTUP_JBOSS :FAIL_STARTUP echo JBoss startup not ready! echo wait... %jcount% if %jcount% == %MAXLOOP% goto :EXIT set /A jcount=%jcount%+1 goto :loop :SUCCESS_STARTUP_JBOSS echo JBoss start up ready! goto :dosomething :dosomething REM continue your task :EXIT exit @echo on REM *********************** REM shutdown JBoss window REM *********************** @echo off :SHUTDOWN_JBOSS4C REM shutdown JBoss server call %JBOSS_HOME%binshutdown.bat -S :CLOSE_WINDOW call taskkill /f /fi "windowtitle eq JBoss4C server*" | @cls :EXIT exit @echo on
Definition:
The intent of Adapter pattern is to provide the interface that a client expects while using the services of a class with different interface.
Known as:
Class Adapter, Object Adapter
What is:
Adapter pattern
Example:
1. Bob Tarr’s adapter pattern
3. Design networked applications in RMI using the Adapter design pattern
Resource-Constrained scheduling is a NP-hard problem. Usually we have many different ways to find a near perfect solution. Matthew has an article about “A Genetic Algorithm for Resource-Constrained Scheduling” is a good introduction. But how do we implement it? Here is some guidelines.
Genetic Algorithms: Simulating Evolution on the Computer, part 1
Genetic Algorithms: Simulating Evolution on the Computer, part 2





