SyntaxHighlighter

Tuesday, September 29, 2009

Enabling sitevsion Portal for debugging

List of Modifications
Sitevision related
Path File name Changed Lines
${SITEVISION_HOME}/custom/conf/service debug.conf wrapper.java.additional.11=-Xrunjdwp:transport=dt_socket,server=y,
suspend=n,address=8001

This is java command line switch as explained below
-Xrunjdwp
This option loads the JPDA (Java Platform Debugger Architecture) reference implementation of JDWP (The Java Debug Wire Protocol (JDWP) is the protocol used for communication between a debugger and the Java virtual machine (VM) which it debugs (hereafter called the target VM). This library resides in the target VM and uses JVMDI and JNI to interact with it. It uses a transport and the JDWP protocol to communicate with a separate debugger application.
Operation
Format: -Xrunjdwp:[=],[=]...

Start sitevision in debug mode by running ${SITEVISION_HOME}/bin/debug.bat

Now, sitevision server is running in debug mode with socket for debugging available at 8001 port.

Eclipse settings

Create a debug configuration in eclipse

Create a remote java debugging configuration with values as


Name : MyPortal
Project : PortalProject
Connection Type : Standard (Socket Attach)
Host: localhost
Port : 8001 (same as that you specify in java command switch)

Happy debugging....

Saturday, July 25, 2009

Java Design Patterns - Quick Reference

1.Observer Pattern
Defines a one to many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.
Java's built in Observer pattern
Subject(Object under observation) needs to implement "Observable"
This subject can notify its dependent by calling following methods sequentially
1.setChanged()
2.NotifyObserver() / notifyObservers()
Observer's needs to implement "Observer" interface and register / unregister to the observable as
addObserver(Observable)
removeObserver(Observable)

2.Decorator Pattern
Attaches additional responsibilities to an object dynamically.
Decorator provides a flexible alternative to subclassing for extending functionality.

Diagrammatically it is represented as















3.Factory Method Pattern
Defines an interface for creating an object but lets subclasses decide which class to instantiate.
(Factory method lets class defer instantiation to subclass)

Diagrammatically this can be represented as












4. Abstract Factory Pattern
Provides an interface for creating families of related / dependent objects without specifying their concrete classes.

Can be thought as Factory of Factory...
One of example of abstract Factory is
javax.xml.validation.SchemaFactory it has static factory method newInstance( ) which Lookup an implementation of the SchemaFactory that supports the specified schema language and return it.

5. Command Pattern
Encapsulates a request as an object thereby letting you parameterize other objects with different requests / queue .
You can provide functionality of undo too.
Typical client for the command uses as follows
{
Command cmd = new ConcreteCommand();
cmd.execute();
}

Following diagram will make it more clearer with action receiver .














6. Adapter Pattern
Converts the interface of a class into another interface , the client expects.
Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.



7. Template Method Pattern
Defines the skeleton of an algorithm in a method, deferring some steps to sub classes.
Template method lets subclasses redefine certain steps of an algorithm without changing overall algorithm structure.
If you look @ Spring ,It has many templates defined
JMSTemplate, JDBCTemplate
JDBCTemplate simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow (get connection , cerate statement , set parameter , set connection, execute statement , extract results ), leaving application code to provide SQL and extract results.


8. Composite Pattern
Allows you to compose objects into tree structure to represent part-whole hierarchy.
Composite lets client treat individual objects and composition of objects uniformly.

Diagram :


9. State Pattern
Allows an object to alter its behavior when its internal state changes.
The object will appear to change its class .
Like a coffee vending machine changing state from working to bin full ,out of milk... states...

Diagrammatically it is represented as below


10. Proxy Pattern
Provide a surrogate / placeholder for another object to control access to it.
Use the proxy pattern to create a representative object that controls access to another object which may be remote / expensive to create / in need of securing
1. Remote Proxy
Controls access to remote object
2. Virtual Proxy
Controls access to resource which is expensive to create
3. Protection Proxy
Controls access to a resource based on access rights.


Saturday, November 29, 2008

FTP Operations In Enterprise applications

As far as my experience in enterprise application domain especially the application having integration kind of nature requires frequent FTP operation.
Recently me too had similar requirement,wherein I need to fetch a file from the remote server....
I was using Mule as integration bus for my application,though Mule provides in built support for FTP transport,It has 1 major drawback in case of FTP operations as listed below
1.Mule FTP Connector has polling nature and it deletes the file once its downloaded from FTP server.
Sometimes its allowed and perfectly acceptable to delete the downloaded file from remote FTP server but not always.
That lead me to apache commons NET project
This project consists of basic client side implementation of transport protocols such as SMTP,FTP,POP..
If you look at these API's these are one of the most simplest way to implement the FTPCleint
FTPClient ftpClient = new FTPClient();
ftpClient.connect("ftp.foo.com", "user01", "pass1234");
ftpClient.download("C:\\Temp\\", "README.txt");
// Eventually other operations here ...
ftpClient.disconnect();

Can you see ,how simple is this code...

Saturday, September 27, 2008

Spring-Quartz Transactions

Its been after a long time I got chance to sit back in summarize....Past 3 months were hectic in terms of work n there was always a race on ,against time.
Recently I came across a excellent feature of Spring framework,Just wanted to share with you all.
You must be aware of scheduling framework Quartz.
Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application.
I was working on a spring application ,all my business services are spring beans ,my transaction manager is "org.springframework.jdbc.datasource.DataSourceTransactionManager" which is local transaction manager,as my application is not in demand of JTA or any distributed transaction.
Now comes a trick ,when I come across following scenario
Suppose I have a business service which does following
  1. Insert a record in DB
  2. Schedules a job in Quartz
  3. Updates some record in DB
Now what I required is
  • If update in step 3 fails ,I want to rollback steps 1,2
  • If Step 2 fails ,I want step 1 to rollback
As mine datasource is a Local transaction manager,It cant work across multiple resources and manage.That was enforcing me to use JTA or similar transaction manager ,which is actually overkill for my application.
As expcted ,Solution to this problem is provided by none other than spring,Thanks to Juergen Hoeller.
Spring comes with
org.springframework.scheduling.quartz.LocalDataSourceJobStore which is extension to Quartz JobStoreCMT
Now you just need to cnfigure your job store as below
org.quartz.jobStore.class =
org.springframework.scheduling.quartz.LocalDataSourceJobStore
Now ,Operations performed by this JobStore will properly participate in any kind of Spring-managed transaction, as it uses Spring's DataSourceUtils connection handling methods that are aware of a current transaction.
How easily spring solves this problem shows ,springs capability to be an enterprise application framework......


Friday, June 20, 2008

My thoughts on developement frameworks...

I have been in the IT industry for past 2 years,which is really a short period.
But still some how I feel ,whatever I have gained so far,I can share...
So started writting....
I have been working on Java and related technlogies and frameworks,I worked on Spring,iBatis,bit of hibernate,struts along with some custom frameworks (Refres to frameworks developed by individual organizations to meet there technical requirement) n toolkits....
When we say its a framework ,its actually a collection of usage patterns combined to hide the complexity from animal called developer or the framework implementor or user.

Whenver these developers (me too still a developer :)) use these frameworks,
Usually framework are made for generic purpose ,so often we need write configuration file
either XML or properties file
The framework must be supported by IDE plugins (Such as Spring IDE for Eclipse for Spring) otherwise writting a XML configuraton according to framework expectation requires expertise and experience on that framework, a begineer will struggle like anything.
Second thing is the exceptions shown by frameworks ,are mostly misleading.... :( ,thats what my experience ,as in If you mis-spelled some attribute in some configuration file but it will show you all other things apart from it.. and now debugging a framework becomes a challenge....
In my career ,I worked on couple of custom framweorks too... the experience with them is also not that satisfactory..., as frameworks I used , which was simple ,but developers need to write more lines of code for developing a functionality which can be devloped in less number of lines without using that framework .
So, I feel a framework must developed keeping in mind that the implementor need to as less LOC possible .One truth is that as many LOC ,that many defects you will inject...
So My idea of good developement framework is..
1.Configurable via XML, with IDE plugin support
2.Good exception handlling,pin point the actual error .....
3.Minimal LOC for implementors or framework users
4.Ease of deugging or catching misconfiguration
5.Clear and comprehensive API documentation

Many of the industry proven developement frameworks do provide support for points 1,3 ,5 but points 2,4 are still very much required for good developement framework...
I have all this in mind from long period, finally was able to free up my mind..
Thats it....m summing up :)