Thursday, May 22, 2008
URL is dead, is it?
Tuesday, February 19, 2008
Solid State Drive (SSD) and Server Hardware
1. Very fast read access
2. Better write performance
Which will make
1. High Performance
2. High reliability
3. increased Throughput
So probably hardware vendor at least should give options to go for SSD for the above reasons.
Integrating Java EE 5(JEE5), JBPM, JBoss Seam, Netbeans and Glassfish V2
Integrating Java EE 5(JEE5), JBPM, JBoss Seam, Netbeans and Glassfish V2
I have ported jboss todo example application into Java EE 5 (Jee5) running on Glassfish v2 using Netbeans 6 IDE.
Create an enterprise application called todo with todo-war and todo-ejb applications modules.
Please download the jboss –seam at http://www.jboss.com/products/seam
before proceeding to next step. Also download and install netbeans from http://www.netbeans.org/downloads
Jboss seam required jboss-seam.jar as ejb application which should be added into application.xml. But Netbeans has deployment issue when we just add jboss-seam.jar as ejb application. In order to overcome this issue, we need to create separate module in Netbeans for seam. So create jboss-seam ejb module.
Creating jboss-seam ejb module:
Click “New Project”, Click “
You need to configure dependant jar files Library for jboss-seam ejb module.
To configure libraries, right click on the “jboss-seam” project click “properties” menu which opens the dialog box titled “Project Properties - jboss-seam”. Go to “Library”. In the right hand side click “Add Library” and Click “Manage Libraries”, then “New Library”. Give the name “Jboss-Seam-Lib”, click “Add Jar/Folder” button to add the jar files. Browse through {Seam Installation/unzipped Directory}/ lib
Add all the jar files except
§ jboss-seam.jar
Click “Ok” and choose “Jboss-Seam-Lib” in the “Add Library” dialog. Library “Jboss-Seam-Lib” will be listed under the “Compile” tab of the dialog box titled “Project Properties - jboss-seam”. Uncheck the check box, this will make sure that these jars will be used only for compilation. So whenever we use “jboss-seam” ejb module, these jars will not be copied. Next, we need to copy the source files from {Seam Installation/unzipped Directory}/src/main into Netbeans’ jboss-seam module under the “Source Packages” in Project view. Thus we got “jboss-seam.jar” equivalent module in netbeans.
JBPM Integration:
All the Jar files which is mentioned below will be available under the folder {Seam Installation/unzipped Directory}/ lib.
In order to run Jbpm, we need additional Jar files which I am going to explain below,
Required Jar for ear application (todo):
Right click on the EA project “todo”, click properties menu which opens the dialog box titled “Project Properties - todo”. Go to “Packaging” section under “Build”.
Create a library called “JBPMLib” (You can create a new library by clicking “Add Library” button in the right side pane and Click “Manage Libraries”, then “New Library”. Give the name “JBPMLib”, click “Add Jar/Folder” button to add the jar files )and add the following jar files.
§ jbpm-jpdl.jar
§ testng.jar
§ quartz.jar
JBPM requires Hibernate which is used as persistence framework. So create one more library for Hibernate (“Hibernate-Seam-Lib”) and add the bellow jar files
§ antlr.jar
§ cglib.jar
§ commons-beanutils.jar
§ commons-collections.jar
§ commons-digester.jar
§ commons-logging.jar
§ dom4j.jar
§ hibernate-annotations.jar
§ hibernate-commons-annotations.jar
§ hibernate-entitymanager.jar
§ hibernate-validator.jar
§ hibernate.jar
§ javassist.jar
§ log4j.jar
I also added the below jar files which is required for jboss-seam.
§ jboss-archive-browsing.jar
§ jboss-common-core.jar
§ jboss-el.jar
Once all the jars added, Click “Ok” and choose “JBPMLib” in the “Add Library” dialog. Library “JBPMLib” will be listed in “Packaging” section under “Build”. Double click on “Location in Archive” column of “JBPMLib” and edit it to “/lib”. Same way add the “Hibernate-Seam-Lib” and edit the “Location in Archive” to “/lib” and click somewhere outside to change the focus (otherwise edit will not be saved sometimes). Add “jboss-seam” ejb module by clicking “Add Project” button. Click “Ok”. This is how we added JBPM and its dependant jar files under lib location in the ear file. All other modules under the ear files will have access to the libraries (jar) under “ear/lib” folder.
Finally your Package dialog will have
- dist\todo-ejb.jar (by default it will be added) Location in Archive: “/”
- dist\todo-war.war (by default it will be added) Location in Archive: “/”
- dist\jboss-seam.jar (You added recently) Location in Archive: “/”
- JBPMLib (You added recently) Location in Archive: “/lib”
- Hibernate-Seam-Lib (You added recently) Location in Archive: “/lib”
Deployment Descriptor Changes:
Add jboss-seam.jar as ejb module in application.xml of “todo” ear module.
Required Jar for ejb application (todo-ejb):
Configure the todo-ejb libraries by going through Project Properties,
Add following Library files
- JBPMLib
- Hibernate-Seam-Lib
- Jboss-seam.jar
Note: Uncheck the “Package” Column for all the above libraries as it is added through EAR application (“todo”), otherwise it will add it into root location of ear file not under lib location.
Ejb App without Ejb: We can’t deploy ejb module without an ejb, so create a dummy stateless session bean.
Empty Seam.properties should be added to let seam knows this project is seam project.
Add the source copied from {Seam Installation/unzipped Directory}/examples/toto/src under “Source Packages”
Required Jar for WAR/web application (todo-war):
Go to the Packaging section of “Project Properties”.
Add following jar files
§ jboss-seam-debug.jar
§ jboss-seam-ui.jar
And edit “Path in ear” column and change it to “WEB-INF/ib”
Adding JBPM Config files:
We need to make following config files available to JBPM engine
- hibernate.cfg.xml
- jbpm.cfg.xml
- todo.jpdl.xml
Please place these files under “Source Packages” directly. So at the end you will be able to see these files under “
Add the source copied from {Seam Installation/unzipped Directory}/examples/toto/resources/WEB-INF to WEB-INF
And “{Seam Installation/unzipped Directory}/examples/toto/view” to “web” folder of Netbeans.
That’s all. Run the todo application. Enjoy Business Process…
Thursday, November 09, 2006
AJAX Submission Throttling
HTML Elements: Text field, Select box or any other control
Events: On key up /down
Technology used: AJAX and JSON response. (XML or text can also be used)
JSON: more information on http://www.json.org/
1. Naive Approach: The initial implementation of getting data for every key press was not a viable option to live with due to performance reasons. Since every request for individual letter typed in by the user causing delay in showing the desired data, the submission throttling method was adopted to address this issue.
2. Constant Time delay
The initial solution identified was to wait for the fixed delay (2 seconds, or similar), and submit the request there after.
For example: When user types the search criteria, irrespective of the speed in which user has typed the criteria, the request was submitted after the fixed delay.
Default Delay:
The delay mentioned in the above stated example is constant. The problem with the default delay was that the “fast typer” will have to wait minimum of the default delay introduced by the system. Hence the solution was to introduce a varying delay.
Differential delay (Based on typing speed)
Varying delay:
The system will responds based on the typing speed of the user. Following is the series of steps in which the submission throttling is implemented.
Breathe time (BT):
This is the default delay set by the system. App has the delay of 150 ms seconds to start with.
Actual Elapsed Time (AET):
This is the time duration between the typing of a character and the next event. Delay will be calculated based on the BT + time gap between typing last character and the current character.
Default Elapsed Time (DET):
The DET is set to constant value (3*BT), However, Introduced delay will not exceed the DET. This is because user may be knowing first few character and then after typing that he will wait for server to tell the matches for the string he typed.
Method to watch below
XHR.abort
scopeThis
calculateElapsedTime
callServerScript
var noOfReq =0;
var noOfAbort =0;
var noOfCancel =0;
var noOfServerCall =0;
var totalCall =0;
function XHR (advSuggest) {
this.req;
this.advSuggest = advSuggest;
this.isProgress= false;
this.isCompleted = false;
this.isAborted = false;
this.init= function (){
++noOfReq;
// // alert ("noOfReq=" + noOfReq);
try{
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
this.req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(oc){
this.req=null;
}
}
if(!this.req && typeof XMLHttpRequest!="undefined"){
this.req=new XMLHttpRequest();
}
};
this.setProgress= function (isProgress){
this.isProgress= isProgress;
};
this.setCompleted= function (isComplete){
this.isCompleted = isComplete;
this.setProgress(true);
};
this.resetReadyState= function() {
this.req.onreadystatechange = function () {};
};
this.abort= function() {
if(this.req.readyState>1 || this.req.readyState <4){
try{
this.resetReadyState();
}catch(e){
}
this.isAborted = true;
++noOfAbort;
this.req.abort();
}
};
this.makeRequest = function (inputText){
var url = "./fetchAdv.jsp?text="+escape(inputText);
if(this.req!=null){
this.isProgress = false;
//this.req.abort();
this.req.open("GET", url, true);
this.req.onreadystatechange = scopeThis (this, this.handle, inputText);
try{
this.isAborted = false;
this.req.send(null);
++noOfServerCall;
}catch(e){
alert ("Exception while aborting - " + e);
}
this.isProgress = true;
}
};
this.handle = function(inputText) {
if(this.isAborted === false && this.req.readyState === 4){
try{
if (!this.req.status || this.req.status === 200 ){
var advnames = eval("[" + this.req.responseText + "]");
this.isCompleted= true;
this.isProgress = false;
this.advSuggest.process (advnames, inputText);
return;
}
}catch(e){
alert("Exception " + e +"\n");
}
}
//return empty, is it required?
//this.advSuggest.process ("");
};
}
function AdvSuggest () {
this.req;
this.prevval = "";
this.inputtxt = "";
this.timerid="";
this.prevtime = 0;
this.suggestshown = 0;
this.focusout = 0;
this.searchdiv = document.getElementById('searching');
this.canSubmit = false;
var BREATH_TIME = 150;
var ELAPSED_TIME = BREATH_TIME *3;
var SELECTION_HTML = “";
var CACHE_RESULT = [];
this.printCache= function (){
return CACHE_RESULT;
};
// This function cleases string passed by de-specialising the "_" and "+" characters.
function cleanseString(str) {
var processedstr=str.replace("_","\\_");
processedstr=processedstr.replace("+","\\+");
return processedstr;
};
// This function calculates the time elapsed since the last key in by the user.
function calculateElapsedTime () {
var currentTime = new Date().getTime();
var currentTimeDiff = 0;
this.prevtime = this.prevtime ? this.prevtime : currentTime ;
currentTimeDiff = currentTime - this.prevtime + BREATH_TIME;
this.prevtime = currentTime;
return (currentTimeDiff === BREATH_TIME ) ? ELAPSED_TIME : (currentTimeDiff > ELAPSED_TIME) ? ELAPSED_TIME: currentTimeDiff ;
};
// This function initialises the XMLHttp objects for the Ajax call.
this.initialize= function (){
if(!this.req){
this.req = this.req || new XHR (this);
this.req.init();
}
};
// This function handles the keyup event on the advertiser search field appropriately.
this.callServerScript= function (searchstring, evt){
this.inputtxt= cleanseString(searchstring);
if(evt.keyCode == 40 && this.suggestshown){
this.showAdvertiserDetails('autocomplete');
document.search.autoselect.focus();
}
if(this.prevval == this.inputtxt){
return 0;
}
this.prevval = this.inputtxt ;
if(this.timerid != ""){
clearInterval(this.timerid);
++noOfCancel;
}
if(this.inputtxt == ""){
this.cancelRequest();
this.hideAdvertiserDetails('autocomplete');
return 0;
}
if(this.containsValue(this.inputtxt) ){
this.cancelRequest();
this.setContent(this.getValue(this.inputtxt)) ;
return 0;
}
this.cancelRequest();
var elpsTime = calculateElapsedTime();
this.timerid=setTimeout(scopeThis(this, this.getDetails), elpsTime);
++totalCall;
};
this. getDetails = function (){
this.timerid = "";
this.initialize();
if(this.req!=null){
this.req.makeRequest(this.inputtxt);
}
};
// this function checks if the keyed in text was already cached.
this.containsValue = function (key){
key = key.toUpperCase();
return CACHE_RESULT[key]? true: false;
};
// This function adds the keyed in value to the local cache if it is entered for the first time.
this.addValue = function (key, value){
key = key.toUpperCase();
CACHE_RESULT[key] = value;
};
// This function is used to get the keyed in value from the local cache.
this.getValue = function (key, value){
key = key.toUpperCase();
return CACHE_RESULT[key];
};
// This function is used to display or hide the returned data from the server side script.
this.process= function (advnames, searchText){
this.addValue(searchText, advnames);
this.setContent(advnames);
};
function toHtmlSelectString (data) {
var suggestctrl="";
var optionStr="";
if( data != ""){
suggestctrl = SELECTION_HTML;
for(var advname in data) {
// generate/form options html fragment
}
suggestctrl = //final select html;
}
return suggestctrl;
};
// This function is used to display the fetched data to the select box in the front end.
this.setContent = function (data){
var contentHtml = toHtmlSelectString (data);
// Push it to innerhtml
};
// This function is used to formulate the position of the suggestionbox on the search page.
this.findDisplayCoordinates= function (obj){
var curleft = 0;
var curtop = 0;
if (obj.offsetParent){
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent){
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
}
return [curleft,curtop];
};
//This function is used to handle the refreshing of the request object for firefox.
this.cancelRequest= function (){
if(this.req) {
try{
// Make it Async
setTimeout(scopeThis(this.req, this.req.abort), 0);
// this.req.abort();
}catch(e) {
alert ("Exception while aborting - " + e);
}
}
};
}
// This function assigns the properties to the passed object.
function scopeThis (obj, method) {
var startIndex = 2;
var args = [];
for(var x=2; x< arguments.length; ++x) {
args.push(arguments[x]);
}
return function () {method.apply(obj,args);};
};
Testing
// instantiate the AdvSuggest object in body onload
var advSuggest = new AdvSuggest ();
// Create input text and div element
then onkeydown make a call to
advSuggest.callServerScript(this.value,event)
Change the URL in the XHR object
I omitted most of the event handling like show/hide etc.