Monday, December 28, 2009

Change Default Double Click Action On Folders In Windows

Few days back I found that the default behaviour of double click operation on folders in windows was changed to explore. I want default operation to be open again and I found that it is very simple in Windows XP.

To modify the default operation of double click on folder follow these steps:
  1. Click on My Computer.
  2. Select Folder Options... from Tools menu on the top.
  3. Click on File Types tab on the top.
  4. Select Folder from the list and click on Advanced button.
  5. Select the action from the list you want to make as default action for double click.
  6. Click Set Default and then click Ok and go back.
  7. Close all the windows and try if it works.

Thursday, October 8, 2009

Creating Asynchronous Task In JavaFX

Here is a example to create asynchronous task in JavaFX.
To create an asynchronous task in JavaFX you need to do following steps:


  1. Create an interface with your callback method.

  2. Create a Java class that implements javafx.async.RunnableFuture and implement its run method. Store reference of your interface in order to call declared callback method.

  3. Create a JavaFX class that extends javafx.async.JavaTaskBase and implement create method. This method returns the object of your javafx.async.RunnableFuture. You have to create object of the class which implements javafx.async.RunnableFuture and return it.

  4. Pass object reference which is of your interface type.

  5. Create Object of javafx.async.JavaTaskBase class and call start function.

Look at the following example.
Suppose there is a condition where I want my object to be nitified after given interval. I can achieve this by following code.
###################################################################
Write an Interface.
###################################################################
package timerdemo;
/**
*
* @author deepak_kalra
*/
public interface MyTimer {
public void timeUp();
}
###################################################################
Write a Thread class.
###################################################################
package timerdemo;
import com.sun.javafx.functions.Function0;
import javafx.async.RunnableFuture;
/**
*
* @author deepak_kalra
*/
public class MyTimerThread implements RunnableFuture {
private int sleepTime;; private MyTimer timer;
public MyTimerThread(MyTimer timer) {
this(timer, 1000);
}
public MyTimerThread(MyTimer timer, int sleepTime) {
this.timer = timer;
this.sleepTime = sleepTime;
}
@Override
public void run() {
try {
Thread.sleep(sleepTime);
javafx.lang.FX.deferAction(new Function0()
{
@Override
public Void invoke() {
timer.timeUp();
return null;
}
});
}
catch(InterruptedException ie) {
ie.printStackTrace();
}
}
}
###################################################################
Write a Task class.
###################################################################
package timerdemo;
import javafx.async.JavaTaskBase;
import javafx.async.RunnableFuture;import simplecalculator.MyTimerThread;
/**
* @author deepak_kalra
*/
public class MyJavaFXTask extends JavaTaskBase, MyTimer {
public override function create():RunnableFuture {
var t = new MyTimerThread(this, 1000);
return t;
}
public override function timeUp():Void {
println("Hey! Time is up buddy.");
}
}
################################################################### Write a Main class. ###################################################################
package timerdemo;
/**
* @author deepak_kalra
*/
function run(args : String[]) {
println("Before starting timer.");
var task = new MyJavaFXTask();
task.start();
println("After starting timer.")
}
################################################################### Output:
Before starting timer.
After starting timer.
Hey! Time is up buddy.

Wednesday, October 7, 2009

JavaFX New Beginning

Good user interface is an important factor for application success. User now a days want rich and interactive UI. Multimedia content is more preferred over static non interactive content. User want interactive content full of animation and special effects. With some jazzy features like audio running at the back, images and text moving around the screen etc.

Creating such rich user interface is not an easy task and is not achievable using normal programming language. Special software's, language's are coming in the market which can be used to create such interface.

You might have seen various website's having animated intro movie kind of stuff running on there website. It is a flash file which run in a flash player which is normally installed on every machine & browser now a day's.

JavaFX is a step from SUN in the same direction. It means it is used to create RIA (Rich Internet Applications). JavaFX is focused for content creators.

JavaFX runs on top of JVM. JavaFX is a scripting and declarative language.
Benefits:
Easy to learn.
Ready to deploy.
Inbuilt support for multimedia.
Cost Effective.
Data Binding.

What can you make:
Games, Animation Movies, Widgets, Web UI etc.

To start learning JavaFX I suggest you to download latest Netbeans IDE for JavaFX.

Also you can visit JavaFX official website for more information. http://www.javafx.com/

Wednesday, July 8, 2009

Date Parsing And Date Formatting In JSP Using JSTL

Many times we come across a situation where we want to create java.util.Date object in JSP with the String date. JSTL provides you parseDate tag for parsing the date string and creating date object.

First you have to add formatting tag lib into your project.

put <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/formatting"%> on the top of your JSP.

Say you have date string in a variable dateStr. Then to make date object out of it you have to write following code.

<fmt:parseDate var="dateObj" value="${dateStr}" type="DATE" pattern="yyyy-MM-dd"/>

This will parse the given date string with the given pattern and create java.util.Date object. you can access the date object with the variable name you have provided in var attribute.

If you want to format the date object then you can use formatDate tag.

<fmt:formatDate value="${dateObj}" pattern="MMM dd, yyyy"/>

note: For pattern string please check java website.

tag will print the formatted date on the page. So no need to put this into tag.

You can also use var attribute to store formatted string into variable.





Saturday, July 4, 2009

jboss clustering using apache web server and mod_jk

JBoss application server provides inbuilt support for clustering 2 or more JBoss servers. You just need to do few settings in JBoss server configuration XML files.

First of all you need to get JBoss application server downloaded from JBoss website. Then you need apache web server to work as a front end server for all clustered nodes. You also need mod_jk as a connector between apache web server and JBoss.

Assuming that there are 2 JBoss nodes that has to be clustered. Node1 server name is node1.server and node2 server is named as node2.server. Following is the detail:

Node 1:
Server Name: ServerNode1
IP/Host Name: Machine1

Node 2:
Server Name: ServerNode2
IP/Host Name: Machine2

Now to make these 2 JBoss server as clustered you have to edit "%JBOSS_HOME%/deploy/jboss-web.deployer/server.xml"

You have to add jvmRoute=”ServerNode1” attribute in Engine tag.

<Engine name=”jboss.web” defaultHost=”localhost” jvmRoute=”ServerNode1”>

You have to do same changes in all clustered JBoss servers.

So in our case second server config file will have jvmRoute = "ServerNode2" value.

After this make sure that mod_jk is set to true in jboss-service.xml.

<attribute name="UseJK">true<attribute>

That is all about setting both nodes in cluster. Now lets see how to use apache web server as front server for these clustered nodes. For apache web server let's assume following configuration:

Apache Web Server:
IP/Host Name: ServerNodeManager (Remember it will just behave like node manager It is not same like other node managers available in market. e.g. Weblogic Server Node Manager.)

Now just install mod_jk in apache web server.

Put mod_jk module in apache web server modules folder.

Now modify configuration file (httpd.conf) of apache web server.

# This will load mod_jk module in apache web server
LoadModule jk_module modules/mod_jk.so

# This is to tell all information about clustered nodes. This file is used by mod_jk.
JkWorkersFile conf/workers.properties

# To set the log file
JkLogFile logs/mod_jk.log

# To set log level
JkLogLevel debug

# Mounting workers file with mod_jk
JkMountFile conf/workers.properties

# To redirect all requested URL's to JBoss servers.
JkMount /* jboss

Once you are done with these settings, create a new file with name workers.properties. Enter following entries into it. Save this file in conf folder on apache web server.

worker.list=jboss, jkstatus

# First Node
worker.ServerNode1.type=ajp13
worker.ServerNode1.host=Machine1
worker.ServerNode11.port=8009
worker.ServerNode1.lbfactor=1
worker.ServerNode1.disabled=false
worker.ServerNode1.socket_timeout=10
worker.ServerNode1.connect_timeout=20000

# Second Node
worker.ServerNode2.type=ajp13
worker.ServerNode2.host=Machine2
worker.ServerNode2.port=8009
worker.ServerNode2.lbfactor=1
worker.ServerNode2.disabled=false
worker.ServerNode2.socket_timeout=10
worker.ServerNode2.connect_timeout=20000

# Load balancer
worker.jboss.type=lb
worker.jboss.balance_workers=ServerNode1,ServerNode2
worker.jboss.sticky_session=true
worker.jboss.sticky_session_force=false
#worker.jboss.method=R
#worker.jboss.lock=P

worker.jkstatus.type=status

Now restart apache web server and all jboss nodes.

Treat this web server as you single point of contact. Mod_jk will internally take care of load balancing you request to each node.