Wednesday, May 31, 2006

Smells to refactorings cheat sheet

Smells to Refactorings Cheat Sheet is freely available -- see the top item on the industriallogic site.

Tuesday, May 23, 2006

WebLogic Server and Oracle RAC

Oracle Real Application Clusters (RAC) is a software component you can add to a high-availabitlity solution that enables users on multiple machines to access a single database with increased performance. RAC comprises of two or more Oracle databases instances running on tow or more clustered machines and accessing a shared storage device via cluster technology. Oracle RAC offers the following features to applications on WebLogic Server:
  • Scalability: A RAC appears lika a single Oracle database and is maintained using the same tools and practices. All nodes in the cluster execute transactions against the same database. RAC coordinates access to the shared data to ensure consistency, and integrity. Nodes can be added to the cluster without partitioning data (Horizontal scaling).
  • Availability: Depending on the configuration, when a RAC node fails, in-flight transactions are redirected to another node in the cluster either by WebLogic Server or Oracle Thin driver. The fail-over is not for failed connections. Fail-over is only for transactions, which will be driven to completion, based on the time of failure.
  • Load Balancing: BEA supports load balancing capability with Oracle RAC servers, through multi-data sources
  • Failover: BEA recommends using WebLogic JDBC multi data sources to handle failover. Transparent Application Failover is not supported with WebLogic Server due to the requirement of Oracle OCI driver which is not supported by BEA.
Configuration Options
BEA supports several configuration options for using Oracle RAC with WebLogic Server:
  1. Multiple RAC instances with Global Transactions: BEA recommends the use of transaction-aware WebLogic JDBC multi data sources, which support failover and load balancing, to connect to RAC nodes.
  2. Multiple RAC instances without XA transactions: BEA recommends the use of (non-transaction-aware_ multi data sources to connect to the RAC nodes. Use the standard multi data source configuration, which supports failover and load balancing.
  3. Multiple RAC nodes when multi data sources are not an option: Use Oracle RAC with connect-time failover. Load balancing is not supported in this configuration.
LimitationsA detailed explanation of the following limitations can be found on WebLogic site
  1. Since Oracle requires that a Global Transaction must be initiated, prepared, and concluded in the same instance of the RAC cluster, and since Oracle Thin driver cannot guarantee that a transaction is initiated and concluded on the same RAC instance when when the driver is configured for load balancing, you cannot use connect-time load balancing wihen using XA with Oracle RAC.
  2. There is a potential for Inconsistent Transaction Completion
  3. Potential for Data Deadlocks in Some Failure scenarios
  4. Potential for Transactions Completed out of sequence.

Sunday, May 21, 2006

Java Petstore 2.0

The Java Pet Store 2.0 is the reference application for building AJAX web applications on Java EE 5. It contains blueprints for building AJAX-enabled JSF component libraries, using Java Persistence APIs, applying MVC and other design patterns in an AJAX web application, using Mashups such as Google Maps service for location specific searches using an RSS feed as a data source. You can download the Java Petstore Demo and try out the features from the petstore site.
Here are the features:
  1. Using AJAX for single-page interactive Web applications: The application is designed to be a single-page application where the user never leaves the page. Different sections of the page are dynamically loaded based on the user actions. These sections are loaded asynchronously to avoid any browser refreshes, and to give a richer interactive user-experience.
  2. Mash-ups with Google maps: The petstore uses a mashup with Google's Map service, alongwith Yahoo's Geo-coder service to allow users to see the available pets in a neighborhood.
  3. Community-created content: The application allows a user to add a pet for sale or adoption on the Website. The seller uploads
    1. Using Captchas to discourage spam in the community created content: Whenever a website allows its users to add content, it needs to build mechanisms to discourage placement of spurious content on its Website through automated mechanisms. We demonstrate how captchas can be used for this purpose.
    2. Community rated content: Each item in the petstore website can be rated by the users
    3. Payments through PayPal: The application provides a meeting ground for buyers and sellers of pets. The application uses the PayPal service to allow sellers to accept payments.
  4. Integration of an RSS feed: The website integrates an RSS feed of news items coming out the Java BluePrints website. The
  5. Integration of a search engine: The application integrates Apache Lucene search engine to handle all website searches.
  6. JavaServer Faces: Many of the AJAX features are implemented as reusable JavaServer Faces components.
  7. Java Persistence API: The application uses Java Persistence APIs to create an object/relational mapping layer.
  8. Dependency Injection: The application uses dependency injection instead of deployment descriptors.

Wednesday, May 10, 2006

Double dispatch in Java

Some programming languages provide the feature of dispatching a funtion call to different concrete functions depending on the runtime types of multiple objects involved in the call (including parameters). In Java dynamic method dispatch, the actual method call depends on the dynamic type of a single object (the object/interface on which the method is invoked), hence it is called single dispatch.

In the following piece of code (A java version of the original wikipedia example), you can see that, although an ExplodingAsteroid collidedWith a GiantSpaceShip, the output shows only a SpaceShip.

class SpaceShip {}
class GiantSpaceShip extends SpaceShip {}

class Asteroid {

public void collideWith(SpaceShip sp) {
System.out.println("Asteroid hit a SpaceShip");
}
public void collideWith(GiantSpaceShip gsp) {
System.out.println("Asteroid hit a GiantSpaceShip");
}
}

class ExplodingAsteroid extends Asteroid {

public void collideWith(SpaceShip sp) {
System.out.println("ExplodingAsteroid hit a SpaceShip");
}
public void collideWith(GiantSpaceShip gsp) {
System.out.println("ExplodingAsteroid hit a GiantSpaceShip");
}
}

public class DoubleDispatchTest { public static void main(String args[]) {
Asteroid ast = new Asteroid();
Asteroid ast1 = new ExplodingAsteroid();
SpaceShip sp = new SpaceShip();
SpaceShip sp1 = new GiantSpaceShip();
ast.collideWith(sp);
ast.collideWith(sp1);
ast1.collideWith(sp);
ast1.collideWith(sp1);
}
}

Output:
Asteroid hit a SpaceShip
Asteroid hit a SpaceShip
ExplodingAsteroid hit a SpaceShip
ExplodingAsteroid hit a SpaceShip
This is due to the fact that, though Java can recognize the runtime type of the Asteroid, it ignores the runtime type of the SpaceShip which is sent as an argument.
This problem can be solved by re-writing the above code as follows:

class SpaceShip {
public void collideWith(Asteroid inAsteroid) {
inAsteroid.collideWith(this);
}
}

class GiantSpaceShip extends SpaceShip {
public void collideWith(Asteroid inAsteroid) {
inAsteroid.collideWith(this);
}
}

class Asteroid {

public void collideWith(SpaceShip sp) {
System.out.println("Asteroid hit a SpaceShip");
}
public void collideWith(GiantSpaceShip gsp) {
System.out.println("Asteroid hit a GiantSpaceShip");
}
}

class ExplodingAsteroid extends Asteroid {

public void collideWith(SpaceShip sp) {
System.out.println("ExplodingAsteroid hit a SpaceShip");
}
public void collideWith(GiantSpaceShip gsp) {
System.out.println("ExplodingAsteroid hit a GiantSpaceShip");
}
}

public class DoubleDispatchJava {
public static void main(String args[]) {
Asteroid ast = new Asteroid();
Asteroid ast1 = new ExplodingAsteroid();
SpaceShip sp = new SpaceShip();
SpaceShip sp1 = new GiantSpaceShip();

sp.collideWith(ast);
sp.collideWith (ast1);

sp1.collideWith(ast);
sp1.collideWith(ast1);
}
}
Output:
Asteroid hit a SpaceShip
ExplodingAsteroid hit a SpaceShip
Asteroid hit a GiantSpaceShip
ExplodingAsteroid hit a GiantSpaceShip
In this case, we are still using the runtime type of just one object with each call, but we have an additional call embedded within the called method, which invokes another of the second object (Asteroid), thus achieving double dispatch. The same effect can be achieved by using a couple of if-else statements within the code, but the code starts to look ugly once more types of spaceships/asteroids are introduced.

Wednesday, May 03, 2006

Java Enterprise Edition 5

Java EE 5 specification passed yesterday. The specifications under JEE 5 include Java Authorization Contract for Containers (JACC), JSF 1.2, JSP 2.1, Servlet 2.5, EJB 3.0, JAX-WS 2.0. No implementations of the Java EE 5 specification have been announced yet (except for Glassfish). Here is a list of tutorials/articles for the new specifications. More information can be found at the Sun Java EE site.

Popular Posts