Table of contents:
In the following pages we will give a step-by-step description on how to install and use the GoTech-framework. As the framework uses several third-party products there might be differences if other versions than the ones specified in this tutorial are used. The used operating system was Windows 2003 Server, however it should also run on all platforms supporting Java Version 1.4. The given example is just to demonstrate the capabilities of GoTech and does not represent any meaningful application.
The first step to set up the GoTech-framework is to install all necessary third-party products. The basis for all further steps is a freshly installed Windows 2003 Server. In the following table, all products and installation notes are listed. The products were installed in order as listed, however, the ordering should be of no importance.
Product Installation notes
Product | Product-specific installation notes |
Java 2 Standard Platform SDK 1.4.2 |
|
Apache Ant 1.5.3 |
|
AspectJ 1.1.0 |
|
XDoclet 1.2B3 |
|
JBoss Application Server 4.0.0 DR 2 |
|
The only larger requirement for configuration arises to enable NRMI for JBoss. To enable NRMI, open the file “standardjboss.xml” in “server/default/conf/” for editing (note: replace “default” with the name of your JBoss configuration if you do not use default). Now locate the section called “stateless-remoting-socket-invoker” and add the line “<interceptor>org.jboss.invocation.nrmi.ClientInterceptor</interceptor>” as shown below. Do the same in the section called “stateful-remoting-socket-invoker”.
<invoker-proxy-binding>
<name>stateless-remoting-socket-invoker</name>
...
<proxy-factory-config>
<client-interceptors>
<home>
...
</home>
<bean>
<interceptor>org.jboss.invocation.nrmi.ClientInterceptor</interceptor>
...
</bean>
</client-interceptors>
</proxy-factory-config>
</invoker-proxy-binding>
This sets up the client interceptors for NRMI. Now we need to set up the interceptors for the server side. Locate the section called “Standard Stateless SessionBean” and add the line “<interceptor>org.jboss.invocation.nrmi.ServerInterceptor</interceptor>” as shown below. Do the same for “Standard Stateful SessionBean”.
<container-configuration>
<container-name>Standard Stateless SessionBean</container-name>
...
<container-interceptors>
<interceptor>org.jboss.invocation.nrmi.ServerInterceptor</interceptor>
...
</container-interceptors>
...
</container-configuration>
Now all third-party software necessary should be installed correctly. The next step is to download and install the GoTech framework itself.
The GoTech framework can be downloaded from www.jorchestra.org. Installation is done quickly. Just unzip the archive. Now the configuration file of GoTech needs some work. Open “gotech.properties” located in “buildfile” in an editor. Adjust the paths corresponding to your installation. To test if all settings are correct, we now try to build and run the included example. First, change into the “buildfile” directory. By typing “ant” the build process is started. After successful completion of the build process, change into “build/bin” and execute “run-client.bat”. Then, change into the “build/client” directory and start the demo with “java –classpath %LCP% GuiPlate”. The application should now work, doing all the computations on the application server.
In this section, we will demonstrate the functionality of the GoTech framework by building a pretty standard application – a hello world example. The application in the original version will consist of two classes as shown below. The Main class calls the “functionality” of the demo application in demo.Changer. We have to introduce a package name for the future Bean class due to a limitation of XDoclet. XDoclet is unable to handle Beans without package name.
Main.java
import demo.Changer;
public class Main {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer("Hello ");
Changer change = new Changer();
change.change(buf);
System.out.println(buf);
}
}
demo/Changer.java
package demo;
public class Changer {
public void change(StringBuffer
s) {
s.append("GoTech!");
}
}
If we now compile and run the example it will hopefully print the result “Hello GoTech!”. Consider now that we want to change the example into a distributed application. To achieve that, the class Changer should be moved to an application server. Here, GoTech comes in. GoTech allows annotating Changer with just comments to distribute the application. Another noteworthy challenge is that the parameter s in regular Java is passed by reference. Standard policy for EJBs is call by copy, which would result in an erroneous program. GoTech however can use NRMI to maintain calling semantics using copy-restore. The fully annotated version of Change is shown below.
package demo;
/**
* Changer
* @ejb:bean name="ChangerBean"
* display-name="Changer Bean"
* type="Stateless"
* view-type="remote"
* jndi-name="ejb/test/CDemo"
*
**/
public class Changer {
/**
* @ejb:interface-method view-type="remote"
* @jboss:method-attributes copy-restore="true"
*/
public void change(StringBuffer s) {
s.append("GoTech!");
}
}
The @ejb:bean-tag tells GoTech the name of the bean, the bean type (stateless in this case as we do not need to maintain state), the view-type of the bean and the jndi-name. The @jboss:method-tag selects the calling semantics for the method - if non is specified, call by copy is used. To make it more interesting, let's add a method to Changer using call by copy semantics.
/**
* @ejb:interface-method view-type="remote"
*/
public void changeCBC(StringBuffer s) {
s.append("GoTech!");
}
The only (but important) difference is now that we did not specify copy-restore as calling semantics. To finish the example, we have to add the following line to the main program right after the change.change-call:
change.changeCBC(buf);
With the annotations included, the program can still be compiled and started with any normal java compiler. However, lets try the GoTech framework. Copy the client into the src/client directory and demo/Changer.java to src/share/demo/Changer.java. Note that the Changer class is shared code as the client accesses it. So do not copy your future EJBs to the server directory. Now start the JBoss application server, change into the buildfile-directory of GoTech and type "ant". The program should build successfully and the EJB should be automatically deployed to the application server.
To run the example, change into "build/bin" and type "run-client", then change to "build/client" and type "java -classpath %LCP% Main". The program should print "Hello GoTech!" on the screen (and not "Hello GoTech!GoTech!").
For questions, comments, and bug reports please contact Stephan Urbanski or Eli Tilevich.