ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Developing for Jakarta Avalon
Pages: 1, 2, 3

Developing an Application for Phoenix

This section briefly outlines the steps required to define, develop, package, and deploy an application in the Phoenix environment. The level of abstraction offered by Phoenix and the number of reusable blocks available in the Cornerstone repository provide a high-value proposition for developing server-side components using Avalon.



Step 1: Defining the Service

In Avalon, every component is associated with a role, since components are selected or retrieved by role. The role and the interface for our FxConversion service is defined below.

public interface FxConversion extends Component {
public String ROLE = “com.nuix.avalon.fx.FxConversion”;
public double convert(String in_ccy, String out_ccy, double amount)
throws FxConversionException;
}

Step 2: Implementing the Service

The MyFxConversion class implements the FxConversion interface, in addition to several of the lifecycle and threading interfaces defined by the Avalon Framework. Although not visible, the implementation uses the Scheduler and SocketManager components, which are part of the Cornerstone distribution.

public class MyFxConversion
extends AbstractLogEnabled
implements FxConversion, Configurable, Initializable, Composable {
}

Step 3: Deployment Descriptors

Once the MyFxConversion block has been completed, the deployment descriptors must be compiled. The Phoenix container relies on three deployment descriptors: assembly, config, and environment.

The Assembly File

The assembly file outlines the various components that the Foreign Exchange System requires. Each component specifies its dependencies, as shown below. The Phoenix container uses the information in the assembly file to build a dependency list of components and then to manage the lifecycle of these components.

There are several things worth pointing out; firstly, the provide child element of a block element always specifies the role of the component that it depends upon, not the actual class implementing the role. Secondly, the order that blocks are specified is unimportant for Phoenix to build its dependency list.

The Foreign Exchange application uses some of the blocks (i.e., DefaultThreadManager, DefaultSocketManager, and DefaultTimeScheduler) that are part of Cornerstone distribution.

<assembly>
<!-- The ThreadManager block -->
<block class="org.apache.avalon.cornerstone.blocks.threads.DefaultThreadManager" 
name="thread-manager" />
<!-- The Socket Manager block -->
<block class="org.apache.avalon.cornerstone.blocks.sockets.DefaultSocketManager" 
name="sockets" />
<!-- The TimeScheduler block -->
<block class="org.apache.avalon.cornerstone.blocks.scheduler.DefaultTimeScheduler" 
name="scheduler">
<provide name="thread-manager" 
role="org.apache.avalon.cornerstone.services.threads.ThreadManager" />
</block>
<block class="com.nuix.avalon.fx.MyFxConversion" name="fx-conversion" >
<provide name="sockets" 
role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
<provide name="scheduler" 
role="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"/>
</block> 
</assembly>

Pages: 1, 2, 3

Next Pagearrow