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.