Java Bridge Use Cases
This section describes some of the common uses for the Java Bridge. The usage scenarios and examples discussed here provide a framework for the Java Bridge’s uses, rather than a complete picture. Real world experience indicates that companies are finding more and more applications for the Java Bridge, beyond what was initially anticipated.
Usage Scenarios
There are two usage scenarios that describe the most common applications for the PHP/Java Bridge:
- Integration with Existing Java Infrastructure - PHP is a fully featured scripting language engineered to cover virtually all of an enterprise’s requirements. At the same time, many enterprises have a long history of application development in Java. The Java Bridge enables enterprises to continue to use their Java infrastructure - applications, databases, business logic and various Java servers (WebLogic, JBoss, Oracle Application Server, etc.).
- Accessing Java Language and Architecture - Some enterprises require the full set of PHP capabilities, yet have a specific need for select Java based applications. SIP signaling in the communications industry or JDBC for creating connectivity to SQL databases are two examples of impressive, industry specific products. The Java Bridge enables enterprises to adopt a PHP standard and to use their preferred Java based applications.
Activities
This section describes two sample activities that indicate some of what you can do with the PHP/Java Bridge. In the sample activities, it is important to differentiate between Java and J2EE. The difference will impact on architecture and in turn, on the script code.
The important differences are:
- Java is a programming language. Java applications created in Java for the enterprise are not bound to a specific framework. Therefore, it is possible and perhaps preferable for an enterprise to relocate code libraries to the server that runs Zend Server.
- J2EE is a structured framework for application scripts developed for J2EE. It is preferable that J2EE servers be left intact.
Example 1: A Case Study in Java Bridge Performance (Java)
The Forever Times newspaper maintains a PHP-based website - let’s call it ForeverOnline.com. The newspaper has been searching for a real-time Stock Ticker application to add to their already successful and heavily visited website. The Forever Times Newspaper feels that real-time financial information is the one thing their website is lacking.
Forever Times believes they have found exactly the Stock Ticker application they need. The application provides up-to-date quotations from all the major markets, currency rates, and even links to some of the local exchanges. However, the application is written in Java and uses existing Java libraries.
Forever Times realizes that a PHP-based Web implementation that handles Java requests - a Java Bridge - is their best bet. At the same time, they are concerned that the performance of their Website remains optimal. To Forever Times’ horror, in testing the new application, they find that loading the site with user-requests for the Stock Ticker slows down the performance of the whole website.
The following code example illustrates how the Java Bridge applies to this business scenario and others like it:
|
Example: <? // create Java object $stock = new Java("com.ticker.JavaStock"); // call the object $news = $stock->get_news($_GET['ticker']); // display results foreach($news as $news_item) { print "$news_item<br>\n"; } ?> |
The example code can be understood as follows:
|
As opposed to a typical Java Bridge Implementation, the Zend Server Java Bridge implementation addresses performance issues through the Java Bridge architecture.
Implementing the Java Bridge is a way to address scalability issues by using the Java Bridge to handle all communication in a single JVM instance, instead of in several instances.
Example 2: A Case Study in Management Integration (J2EE)
A company called FlowerPwr.com sells flowers over the Internet. They are a successful East Coast-based firm that has an aggressive management profile. They are currently in the process of acquiring a West Coast competitor - let’s call it Yourflowers.com - that provides a similar service.
FlowerPwr.com has its own website: Its various enterprise applications are written in PHP. Yourflowers.com also has its own Website: However, all its applications are Java-based and were developed for J2EE. They have their own J2EE application server. FlowerPwr.com needs to begin operating as an integrated commercial entity as soon as possible, in a way that conceals the fact that the companies have merged.
Using the Java Bridge, FlowerPwr.com can create a common portal in PHP. The company can leave Java up and running and take full advantage of their acquisition’s existing Java services. FlowerPwr.com can do this over an existing portal using PHP.
The following code example illustrates how the Java Bridge can apply to this business scenario and others like it:
|
Example: <? // EJB configuration for JBoss. Other servers may need other settings. // Note that CLASSPATH should contain these classes $envt = array( "java.naming.factory.initial" => "org.jnp.interfaces.NamingContextFactory", "java.naming.factory.url.pkgs" => "org.jboss.naming:org.jnp.interfaces", "java.naming.provider.url" => " jnp://yourflowers.com:1099"); $ctx = new Java("javax.naming.InitialContext", $envt); // Try to find the object $obj = $ctx->lookup("YourflowersBean"); // here we find an object - no error handling in this example $rmi = new Java("javax.rmi.PortableRemoteObject"); $home = $rmi->narrow($obj, new Java("com.yourflowers.StoreHome")); $store = $home->create(); // add an order to the bean $store->place_order($_GET['client_id'], $_GET['item_id']); print "Order placed.<br>Current shopping cart: <br>"; // get shopping cart data from the bean $cart = $store->get_cart($_GET['client_id']); foreach($cart as $item) { print "$item['name']: $item['count'] at $item['price']<br>\n"; } // release the object $store->remove(); ?> |
The example code can be understood as follows:
|
After script execution, the referenced class may be disposed.